Related to my JSF application, I noticed there’s a problem with the Mojarra JSF 2.1.16 library. I have a ViewScoped bean which loads a user from a login got as ViewParam. After that loaded user data can be managed and saved. Below is the view code, where I have skiped the main form fields as I have tested there’s no problem with them.
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui"
template="/templates/general_template.xhtml">
<ui:define name="metadata">
<f:metadata>
<f:viewParam id="user" name="user"
value="#{manager._ParamUser}" />
<f:event type="preRenderView"
listener="#{manager.initialize}" />
</f:metadata>
</ui:define>
<ui:define name="general_content">
<p:outputPanel autoUpdate="false" id="loggedData" name="loggedData"
layout="block">
<h:form id="SystemUserForm">
<h:panelGrid columns="4" cellspacing="10px" style="border-color:red;">
<h:outputText value="#{msg.LOGIN}:" />
<h:outputText value="#{manager._UserBean._login}" />
</h:panelGrid>
<p:commandButton value="#{msg.UPDATE}" action="#{manager.actionSave}"
ajax="false" />
<p:commandButton value="#{msg.CANCEL}"
action="#{manager.actionCancelSave}" ajax="false" />
</h:form>
</p:outputPanel>
</ui:define>
At the beginning bean is created and User itself is loaded from data base using received param. Problem comes when I call the action method to save it, because the ViewScoped bean called manager is being constructed again. So there’s no param and I have a null pointer Exception. That’s working properly with Mojarra 2.1.14 and 2.1.15.
Backing bean code:
@ManagedBean
@ViewScoped
public class Manager extends UserData {
public static final String PARAM_USER = "ParamUser";
private String _ParamUser;
public String get_ParamUser() {
return this._ParamUser;
}
public void set_ParamUser(String _ParamUser) {
this._ParamUser = _ParamUser;
}
public Manager() {
super();
}
@Override
public void initialize(ComponentSystemEvent event) {
if (!FacesContext.getCurrentInstance().isPostback()) {
loadUserBean(this._ParamUser);
if (this._UserBean == null) {
redirectTo404();
}
}
}
@Override
public String actionSave() {
super.actionSave();
return NavigationResults.USER_LIST;
}
UserData is, of course, an abstract class. When actionSave() is called bean is constructed again and there is no _ParamUser attribute, because this is get by viewParam. That constructor recall is only happening with Mojarra 2.1.6.
This issue has been solved in Mojarra JSF 2.1.17, tried and tested. Could be a problem with Mojarra JSF 2.1.16 and Tomcat 6. However, I haven’t found any known issues for that version.