9 Replies Latest reply on Nov 24, 2008 8:58 AM by iisrail

    Request Parameters in init

      I have app that includes two pages first navigation div, second the content div. Where the content of content div should be changed after click on some link of navigation panel. Therefore I've defined the managed bean beyond the content page in request scope. Except to display the current content beyond the managed bean, I should let to users to do update action on the page and thereby while Restore View phase I do the following in my code:

      SessionBean ses = FacesUtils.getSessionBean();
      paramNodeId = FacesUtils.getRequestParameter(PARAM_NODE_ID);
      // retrieve params after update
      if (paramNodeId == null) {
       paramNodeId = (String) ses.get(PARAM_NODE_ID);
      }else{
       ses.put(PARAM_NODE_ID, paramNodeId);
      }
      

      My question is whether there is more convenient way to handle old params while Restore View phase?

        • 1. Re: Request Parameters in init
          ilya_shaikovsky

          not sure that understand you right.
          you have some action components which fires requests and passes some new parameters.. why you just can't process your old params in also action methods and then overwrite them with new ones?

          • 2. Re: Request Parameters in init

            Ilya,

            what do you mean? I don't have to use request scope, but when I have used session scope my old param was not overwrited, and click on other link on navigation panel brought me to the same content.

            • 3. Re: Request Parameters in init
              ilya_shaikovsky

              please show your current code. Maybe your new params not setted because of some validation/conversion failures?

              • 4. Re: Request Parameters in init

                you mean I should use session scope?

                • 5. Re: Request Parameters in init
                  ilya_shaikovsky

                  seems I misunderstand you.. let start again from your current code (more full) and more detailed problem definition. ;)

                  • 6. Re: Request Parameters in init

                    I have app that includes two pages first navigation div, second the content div. Where the content of content div should be changed after click on some link of navigation panel. Therefore I've defined the managed bean beyond the content page in request scope. Except to display the current content beyond the managed bean, I should let to users to do update action on the page. But while update the init function on the managed bean is invoked and while doing the following such as:

                    paramNodeId = FacesUtils.getRequestParameter(PARAM_NODE_ID);
                    

                    The paramNodeId get null and as result null pointer in some point therfore I need save a value of param in session bean and while activation update action retrieve it from session bean in the following way:
                    if (paramNodeId == null) {
                     paramNodeId = (String) ses.get(PARAM_NODE_ID);
                    }else{
                     ses.put(PARAM_NODE_ID, paramNodeId);
                    }
                    


                    The whole code:

                    public class EditNodeBean extends BaseBean {
                     static final String PARAM_NODE_ID = "nodeID";
                     static final String PARAM_OBJECT_ID = "objectID";
                     static final String PARAM_ITEM_ID = "itemID";
                     static final String PARAM_IS_NEW = "isNew";
                     protected CMSNode cmsNode;
                     protected CMSTree daoTree;
                    
                     protected String paramNodeId ;
                     protected String paramObjectId ;
                     protected String paramItemId ;
                     protected String paramIsNew ;
                    
                     protected void init() {
                     this.logger.info("init is invoked");
                     SessionBean ses = FacesUtils.getSessionBean();
                     paramNodeId = FacesUtils.getRequestParameter(PARAM_NODE_ID);
                     paramObjectId = FacesUtils.getRequestParameter(PARAM_OBJECT_ID);
                    
                     // retrieve params after update
                     if (paramNodeId == null) {
                     paramNodeId = (String) ses.get(PARAM_NODE_ID);
                     }else{
                     ses.put(PARAM_NODE_ID, paramNodeId);
                     }
                    
                     if (paramObjectId == null) {
                     paramObjectId = (String) ses.get(PARAM_OBJECT_ID);
                     }else{
                     ses.put(PARAM_OBJECT_ID, paramObjectId);
                     }
                    
                     daoTree = this.serviceLocator.getCmsTree();
                     cmsNode = daoTree.getNode(nodeId);
                     }
                    
                     public String update() {
                     this.logger.info("update is invoked");
                     Integer selectedObject = (Integer) FacesUtils.getElValue("#{editNode.cmsNode.objectId}");
                     daoTree.updateNode(cmsNode);
                     return null;
                     }
                    
                    


                    my faces-config.xml
                     <managed-bean>
                     <managed-bean-name>editNode</managed-bean-name>
                     <managed-bean-class>
                     com.igl.web.bean.EditNodeBean
                     </managed-bean-class>
                     <managed-bean-scope>request</managed-bean-scope>
                     <managed-property>
                     <property-name>serviceLocator</property-name>
                     <value>#{serviceLocatorBean}</value>
                     </managed-property>
                     </managed-bean>
                    



                    • 7. Re: Request Parameters in init
                      ilya_shaikovsky

                      using the same scenario in our rf-demo we've used

                       <h:outputLink style="display:block;height:20px" value="#{component.contextRelativeDemoLocation}">
                       <span style="display:block;padding-top:3px;text-decoration : none; color : #000000;">
                       #{component.name}
                       </span>
                       <f:param value="#{component.id}" name="c"/>
                       <f:param value="#{component.activeTab}" name="tab"/>
                       </h:outputLink>
                      


                      to add parameters of the current view to the URL after navigation click and make it bookmarkable.

                      check richfaces-demo navigation menu code.

                      • 8. Re: Request Parameters in init

                        No, I don't have problems with my current code it works OK, but I want to know whether there is a more good way? My question is how not in via my current code see my init function to distingvish between what activate init function update function or some nvaigation function?

                        • 9. Re: Request Parameters in init

                          That is when I activate update function, the init function of a bean is activated and therefore I shouldn't retrieve request params. So how I can know that init was invoked via update function?