0

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.

Aritz
  • 30,971
  • 16
  • 136
  • 217
  • Can't reproduce your problem. Please provide an SSCCE. – BalusC Jan 08 '13 at 13:29
  • Edited. I try to be as clear as possible. – Aritz Jan 08 '13 at 13:53
  • Provided that `/templates/general_template.xhtml` contains no bean references, I still don't see the problem. Note that the `#{manager}` isn't constructed at all while requesting the page because it's nowhere referenced by some output component or event. So it's only constructed when submitting the form. Perhaps this has confused you? – BalusC Jan 08 '13 at 13:54
  • Wait, your `Manager` class has a `NavigableUserData` constructor? Did you post the real code? Or at least copypasted tested code? – BalusC Jan 08 '13 at 14:06
  • Sorry, I changed some names for better understanding.. – Aritz Jan 08 '13 at 14:08
  • And the first point you've said, in fact `#{manager}` is called before, but I have skipped form field code because it was too long. I put you a short example about that. – Aritz Jan 08 '13 at 14:15
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/22400/discussion-between-xtreme-biker-and-balusc) – Aritz Jan 08 '13 at 14:24

1 Answers1

0

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.

Aritz
  • 30,971
  • 16
  • 136
  • 217