6.13. PortletFaces and PortletPreferences

Simiar to the JSR 301/329 portletPreferences EL variable, PortletFaces introduces an EL variable named portletPreference (singlular, not plural). Although the EL usage is similar in syntax, the implementation is different so that it is compatible with ICEfaces paritalSubmit (Ajax). One drawback of JSR 301/329 portletPreferences EL variable is that when used with ICEfaces partialSubmit, user preference selections from the EDIT mode view will be directly set inside the underlying PortletPreferences object. Even though the user might not click a "Save Preferences" button to store the preferences permanently, the preference values might be active for the remainder of the PortletSession. The PortletFaces portletPreference EL variable does not store submitted values directly inside of the underlying PortletPreferences object. Instead, the submitted values are stored in a temporary copy, which solves the problem related to ICEfaces partialSubmit. Additionally, PortletFaces provides a convenience backing managed-bean named PortletPreferencesForm that has an action-listener named PortletPreferencesForm.submit() that will permanently store the portlet preferences.

Example 6.57. EDIT Mode with PortletFaces and ICEfaces Partial Submit

<!--
This is a file named edit.xhtml that can be used for portlet EDIT mode.
It utilizes the PortletFaces portletPreference EL variable for gaining
read/write access to javax.portlet.PortletPreferences. Unlike the
JSR 301/329 approach, there is no need to write a backing managed-bean
because PortletFaces already provides one named portletPreferencesForm.
-->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<f:view xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ice="http://www.icesoft.com/icefaces/component">

	<ice:messages globalOnly="true" />
	<ice:form partialSubmit="true">
		<ice:outputLabel for="datePattern" />
		<ice:inputText id="datePattern" required="true" value="#{portletPreference['datePattern']}" />
		<ice:message for="datePattern" />
		<ice:commandButton actionListener="#{portletPreferencesForm.submit}" partialSubmit="false" value="Save Preferences" />
	</ice:form>
</f:view>