I am updating the JSF portlet we had in Liferay 6.2 to Liferay 7.
The portlet displays a list of and icons selectOneListboxused to control the display of these icons.
<h:selectOneListbox id="listModeSelector" value="#{user.listMode}" size="1">
<f:selectItems value="#{user.listModes}" var="mode"
itemLabel="#{mode.label}" itemValue="#{mode.value}" />
<f:ajax event="change" execute="@this" render=":metricsPanel" />
</h:selectOneListbox>
When user.setListModecalled after the change selectOneListbox, the portlet will save the new option in the portlet settings with the call to the bean functions PortletPreferences' setValueand store:
@ManagedBean
@SessionScoped
public class User {
private static final String LIST_MODE_KEY = "listMode";
private ListMode listMode;
private PortletPreferences preferences;
public User() {
PortletRequest request = ((PortletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest());
preferences = request.getPreferences();
listMode = ListMode.fromValue( preferences.getValue( LIST_MODE_KEY, ListMode.Normal.getValue() ) );
}
public String getListMode() {
return listMode.getValue();
}
public ListMode[] getListModes() {
return ListMode.values();
}
public void setListMode( String listModeValue ) {
this.listMode = ListMode.fromValue( listModeValue );
try {
preferences.setValue( LIST_MODE_KEY, listModeValue );
preferences.store();
}
catch ( ...Exception e ) {
log.error( "unable to persist listMode: " + e.getMessage(), e );
}
}
}
When they change this parameter, we want it to remain changed for them, for any future sessions. But, switching to Liferay 7, this leads to IllegalStateExceptiona message Preferences cannot be stored inside a render call.
, : Liferay 7 JSF PortletPreferences selectOneListbox ? , ?