7 Replies Latest reply on Jun 5, 2009 1:00 PM by Vesa Hiltunen

    Dynamic Action Name

    Rajib Jana Newbie

      Hi All,


      I am building an enterprise application using SEam 2.1.1 and richfaces. The application has a menu/sub menu and a common toolbar. The toolbar has buttons like add, edit, save, view etc. Once user clicks a node in menu/submenu, then a screen is appeared which has a backing bean with add, edit, save, view functions. The application will have 40-50 screens ( forms, tabular etc) and the toolbar buttons will work on the most recently opened screen.


      WE are using richfaces toolbar and commandbutton. To support the above features, the action name needs to be dynamic as the backing bean will be different for different screens. As I understand from richfaces doc, I can only give the static bean method name in action parameter in commandbutton tag.


      Is there any way to pass the action name ( i.e. action name can be decided at runtime) to action parameter?  Can it be done using seam tags like s:link and  s:button?


      I am new to SEAM and richfaces and any help will be gr8.


      Regards


      Rajib


        • 2. Re: Dynamic Action Name
          Darrell Wu Newbie

          Hi,


          I can get this going for commandButtons with the syntax as below


          <h:commandButton action="#{actionBean[action]}" .../>
          
          



          But i can't get it going for slink.


           <s:link action="#{actionBean[editMethod]}" ... />





          I get the following error on the seam debug page



          Exception during request processing:
          Caused by javax.el.PropertyNotFoundException with message: "Target Unreachable, identifier 'actionBean' resolved to null" 
          



          Has anyone got it going for slinks?

          • 3. Re: Dynamic Action Name
            Rajib Jana Newbie
            Hi,

            I am still not able to solve my problem.

            I tried to implement custom tag as described in the link( suggested by Stephen), but could not able to get it working.

            pls. let me know how you get <h:commandButton action="#{actionBean[action]}" .../>
            working?

            Template:

            1. template.xhtml

            <f:view contentType="text/html"
                    xmlns="http://www.w3.org/1999/xhtml"
                    xmlns:ui="http://java.sun.com/jsf/facelets"
                    xmlns:h="http://java.sun.com/jsf/html"
                    xmlns:f="http://java.sun.com/jsf/core"
                    xmlns:a="http://richfaces.org/a4j"
                    xmlns:s="http://jboss.com/products/seam/taglib">
            <html>
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                <title>#{messages['app.title']}</title>
                <link rel="shortcut icon" href="#{request.contextPath}/favicon.ico"/>
                <a:loadStyle src="resource:///stylesheet/theme.xcss"/>
                <a:loadStyle src="/stylesheet/theme.css"/>
            </head>

            <body>
                    <div id="header">
                            <ui:insert name="header">
                            <ui:include src="menu.xhtml">
                                        <ui:param name="projectName" value="#{messages['app.title']}"/>
                            </ui:include>
                    </ui:insert>     
                    </div>


               <div id="center">
                            <h:messages id="messages" globalOnly="true" styleClass="message"
                    errorClass="errormsg" infoClass="infomsg" warnClass="warnmsg"
                    rendered="#{showGlobalMessages != 'false'}"/>
                    <ui:insert name="body">
                                   
                    </ui:insert>
               </div>


            </body>
            </html>
            </f:view>

            2. menu.xtml
            <a4j:form
                    xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:s="http://jboss.com/products/seam/taglib"
                xmlns:rich="http://richfaces.org/rich"
                xmlns:a4j="http://richfaces.org/a4j"
                xmlns:r="http://www.customfacelet.com/jsf"
                id="menu">
                   
                <rich:toolBar>
                    <rich:toolBarGroup>
                         <h:commandLink action="#{actionBean}" value="Add">
                          </h:commandLink>
                     </rich:toolBarGroup>
                </rich:toolBar>
            </a4j:form>

            Xhtml: UIControl_FWD.xhtml

            <ui:include xmlns="http://www.w3.org/1999/xhtml"
                xmlns:s="http://jboss.com/products/seam/taglib"
                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:rich="http://richfaces.org/rich"
                xmlns:a="http://richfaces.org/a4j"
                template="layout/template.xhtml"
                src="/UIControl.xhtml">
               
                <ui:param name="actionBean" value="#{dropDownBean.add}"/>
                </ui:include>

            Xhtml: UIControl.xhtml

            <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:s="http://jboss.com/products/seam/taglib"
                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:rich="http://richfaces.org/rich"
                xmlns:a="http://richfaces.org/a4j"
                template="layout/template.xhtml">

            <ui:define name="body">

                <rich:panel>
                    <f:facet name="header">UIControl</f:facet>

                    <h:form id="dropDownBeanForm">

                       
                    </h:form>

                </rich:panel>

            </ui:define>

            </ui:composition>


            I have dropDownBean session bean (stateful) with getadd method. When the app is executed, it shows the error "Property 'add' not found on type org.javassist.tmp.java.lang.Object_$$_javassist_2"


            I am stuck with this problem and need help.




            • 4. Re: Dynamic Action Name
              Darrell Wu Newbie

              OK,


              Here an example of how i did it,
              I;ve got a file called leadDetail.xhtml as shown below


              <ui:composition xmlns="http://www.w3.org/1999/xhtml" 
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html" 
                xmlns:f="http://java.sun.com/jsf/core" 
                xmlns:c="http://java.sun.com/jstl/core"
                xmlns:s="http://jboss.com/products/seam/taglib"
                xmlns:rich="http://richfaces.org/rich"
                xmlns:a4j="http://richfaces.org/a4j">
              <h:form>
              ... removed code...
                             
              <div class="buttons clearfix">
              <h:commandButton action="#{actionBean[action]}" value="Save" styleClass="btn alignright btn_green"/>
              </div>                     
              </h:form>
              </ui:composition>




              then in my xhtml file i had the following


              <ui:include src="/WEB-INF/incl/leadDetail.xhtml" >
                 <:param name="actionBean" value="#{backingBean}"/>
                <:param name="action" value="save"/>
              </ui:include>




              where backingBean is my backing bean
              action is the name of the method to call



              Hopes this helps,
              Let me know if you get it going for slinks

              • 5. Re: Dynamic Action Name
                Rajib Jana Newbie
                Thanks Darrell, its now working.

                But action="#{actionBean[action]}" does not work if "action" has arguments.

                But , action="#{actionBean.action(arg)}" works when used normally(i.e bean name is not passed by ui:param).

                I tried with action="#{actionBean[action(actionParm)]}" where actionParam is passed by ui:param, but it does not work. I have to use f:param/f:setPropertyActionListener.

                slink is not working for me also.

                • 6. Re: Dynamic Action Name
                  Marc Schmucki Newbie

                  Have you found any solution for this problem?? I'd like to do the same thing...


                  Thank you in advance!

                  • 7. Re: Dynamic Action Name
                    Vesa Hiltunen Newbie

                    h:commandLink instead of s:link seems to work:


                    <h:form>
                        <h:commandLink value="label" action="#{actionBean[action]}" />
                    </h:form>