0 Replies Latest reply: Jul 25, 2013 11:01 AM by Landal RSS

    Component binding return null value

    Landal

      I'm migrating a JSF 1.2 application to JSF 2.1, specificly I'm currently using mojorra 2.1.24.
      The application consists of request scoped beans, and in order to pass data between requests, it embeds the data inside UI components.
      The following behaviour works well with JSF 1.2, but not with JSF 2.1.

      The application has the following configuration:

      <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
      </context-param>
      
      
      
      

       

      The page contains the following snippet:

      <h:form prependId="false">
           <h:inputHidden binding="#{bean.inputHidden}" />
           ...
           <h:panelGroup rendered="#{bean.rendered}">
             ...
            <h:commandLink value="onAction" action="#{bean.onAction}" />
           </h:panelGroup>
      </h:form>
      
      
      


      The bean is the following:

      @ManagedBean
      @RequestScoped
      public class Bean {
        private UIInput inputHidden;
        private AItem item;
      
      
        public setInputHidden(UIInput inputHidden){
          this.inputHidden = inputHidden;
          if(item != null){ this.inputHidden.setValue(item); }
        }
      
      
        public AItem getItem(){
          return (AItem) getInputHidden().getValue();
         }
      
        // other getter/setter 
      
      
        public String onNavToPage(AItem item){ this.item = item; return "page"; }
      
      
        public String onAction(){ //... do something return ""; }
      
      
      
      
        public boolean isRendered(){ return getProcessItem() != null; }
      
      
      }
      
      
      

       

      The steps are the following:

      1. to navigate to page page the method bean.onNavToPage is invoked from within another page;
      2. upon page rendering the bean.item is set as bean.inputHidden value;
      3. after the page is diplayed, the command link is pressed.

      At this point no command link is invoked, because the bean.inputHidden.getValue() returns null, and the command link is not processed.

      I noticed that the inputHidden parameter passed to the setInputHidden method during restore view phase has, inputHidden.getValue() == null, no value has been saved previously in the view.

      I would guess that something has changed in the component state management, but debugging the JSF code I didn't find what.

      Debugging JSF code I found that the component state has been masked before the state has been saved in the view, so the ComponentStateHelper.saveState saves the deltaMap and not the defaultMap, where all the state has been put.

      public Object saveState(FacesContext context) {
              if (context == null) {
                  throw new NullPointerException();
              }
              if(component.initialStateMarked()) {
                  return saveMap(context, deltaMap);
              }
              else {
                  return saveMap(context, defaultMap);
              }
          }
      
      
      
      

       

      is this a bug?

      If not, how can I restore JSF 1.2 behaviuor and save the defaultMap?

       

      Thanks in advance for the help.