10 Replies Latest reply on Nov 22, 2012 5:07 AM by eryz

    Facelets Param for action method

    fmotlik

      Hi,


      we would like to template our textfields, which use ajax4jsf. The action should be provided by a param from facelets. The value and id tags of inputTextArea work great, but not the action. I googled it, but couldn't find any clean solution for it.



      <ui:include src="shared/inputTextArea.template.xhtml">
         <ui:param name="id" value="numberOfObjects"/>
         <ui:param name="input" value="#{selectedProject.projectBasis.numberOfObjects}"/>
         <ui:param name="action" value="#{selectedProject.projectBasis.touch}"/>
       </ui:include>



      <h:inputTextarea id="#{id}" 
          value="#{input}" required="true">
                     <a4j:support ajaxSingle="true" onsubmit="changed()"
                        event="onchange" action="$#{action}" />
        </h:inputTextarea>



      One thing we've thought about is using a using a Utility class that has an invokeAction method so we can use it like this


      <a4j:support action="#{utility.InvokeAction(#{action})}"



      I don't know if the action param gets passed to the invokeAction Method (will try it out after posting this thread), but if I get the String into the utility Method how do I call the action method, so that seam thinks it comes from the browser and handles it correctly.


      Maybe one of you has a solution for this problem. I don't think I'm the first person to have this problem with facelets. thx in advance

        • 1. Re: Facelets Param for action method

          study this article Advanced Facelets programming


          I hope this helps

          • 2. Re: Facelets Param for action method
            jpviragine.jpviragine.gmail.com

            Florian,


            Try this:


            <h:inputTextarea id="#{id}" 
                value="#{input}" required="true">
                           <a4j:support ajaxSingle="true" onsubmit="changed()"
                              event="onchange" action="#{actionBean[action]}"  />
            </h:inputTextarea>



            Usage:



            <ui:include src="shared/inputTextArea.template.xhtml">
               <ui:param name="id" value="numberOfObjects"/>
               <ui:param name="input" value="#{selectedProject.projectBasis.numberOfObjects}"/>
               <ui:param name="actionBean" value="#{selectedProject.projectBasis}"/>
               <ui:param name="action" value="touch}"/>
             </ui:include>




            Cheers,


            JP


            • 3. Re: Facelets Param for action method
              fmotlik

              thx for the incredibly fast help. Everything works absolutely perfect.

              • 4. Re: Facelets Param for action method
                fmotlik

                Hi


                I did implement it now the way you mentioned and it worked fine, but the problem is now, that we have to use a method like this
                action

                #{bean.anyMethod(node)}



                We use it for a clickable trinidad treetable so when you klick one of the Items the action gets called. It's easyiest to do by passing the node as a value, so we used that syntax. Now the problem is, that I would like to have that tree in a template, but it doesn't work in any way that I've tried so far.


                I set the action to someAction(node)
                action

                #{actionBean[action]}



                but that didn't work. I also tried


                action someAction
                action

                #{actionBean[action](node)}



                and this:
                action  someAction(node)
                action 

                #{actionBean[action(node)]}



                I know, that it would be possible to make my own EL function like described in the IBM article referenced above, but if possible I would like to use EL syntax without having to code some java.

                • 5. Re: Facelets Param for action method
                  fmotlik

                  No one got any clue how to achieve this?


                  Does anyone of you have an idea how to implement the clickable treeTable without having to pass the parameter? The table goes recursively over the data and actionBean.action(node) is used as the action for a commandLink.


                  The syntax is very easy to use and we do not have to circumvent the inability of Standard EL to pass parameters. But the problem with this is that the lookup with the

                  actionBean[action]


                  syntax doesn't work, because the parameter can't, as far as I've tried, be passed to the action.


                  Does anyone of you know another way how to do that, so we can put the tree into a template.

                  • 6. Re: Facelets Param for action method
                    barbacena

                    Use the h:inputText valueChangeListener to capture the value and the action from a4j:support to execute the code.


                    Unfortunately facelets doesn't help much on this.


                    []s

                    • 7. Re: Facelets Param for action method
                      jarda222

                      Joao Viragine wrote on Mar 17, 2008 17:28:


                      Florian,

                      Try this:

                      <h:inputTextarea id="#{id}" 
                          value="#{input}" required="true">
                                     <a4j:support ajaxSingle="true" onsubmit="changed()"
                                        event="onchange" action="#{actionBean[action]}"  />
                      </h:inputTextarea>
                      



                      Usage:


                      <ui:include src="shared/inputTextArea.template.xhtml">
                         <ui:param name="id" value="numberOfObjects"/>
                         <ui:param name="input" value="#{selectedProject.projectBasis.numberOfObjects}"/>
                         <ui:param name="actionBean" value="#{selectedProject.projectBasis}"/>
                         <ui:param name="action" value="touch}"/>
                       </ui:include>
                      




                      Cheers,

                      JP




                      Unfortunately this solution doesn't work for me.


                      I have page1.xhtml:


                      <ui:include src="search.xhtml">
                         <ui:param name="actionBean" value="#{bean1}"/>
                         <ui:param name="action" value="selected}"/>
                       </ui:include>
                      



                      than I have page2.xhtml:


                      <ui:include src="search.xhtml">
                         <ui:param name="actionBean" value="#{bean2}"/>
                         <ui:param name="action" value="selected}"/>
                       </ui:include>
                      



                      If I visit first page1.xhtml the bean1.selected is called. When I switch to page2.xhtml I would expect that bean2.selected is called, but unfortunately again bean1.selected is called.


                      When I restart server and visit page2.xhtml, first. The bean2.selected is called. If I visit page1.xhtml, again bean2.selected is called.


                      It seams that the action is somehow cached. But I don't know where and why.


                      Could you please help me?


                      Cheers,


                      Dusan

                      • 8. Re: Facelets Param for action method
                        jarda222

                        Hi,


                        I found that I had mistake in binding.


                        Dusan

                        • 9. Re: Facelets Param for action method
                          hhcofcmds

                          I had a similar problem some months ago. I created a method:



                               public void evaluateMethodBinding(String el) {
                                    ValueExpression ve = FacesContext.getCurrentInstance().getApplication().getExpressionFactory()
                                         .createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{" + el + "}", Object.class);
                                    ve.getValue(FacesContext.getCurrentInstance().getELContext());
                               }
                          




                          in a backing bean named 'ELEvaluator' and then I use



                              action="#{ELEvaluator.evaluateMethodBinding(action)}" 
                          



                          Where 'action' is a parameter of the facelets component. This supports parameters and everything, only you have to write the EL as a string:



                              <my:actionComponent [...] action="backing.method(params)"/>
                          



                          • 10. Re: Facelets Param for action method
                            eryz

                            #{actionBean[action(node)]}

                            Any simple solutions with syntax like this one to pass parameters too?

                            if not any standart hacks about it?