5 Replies Latest reply on Dec 8, 2009 8:36 AM by Ilya Shaikovsky

    <a4j:aroundInvoke ? or something else ?

    nimo stephan Master

      I have the following scenario:

      I have a xhtml-fragment called "fileUpload.xhtml.

      <ui:composition>
      <a4j:outputPanel>
      <h:form>
      <rich:fileUpload id="uploadTracks" styleClass="#{styleUploadFiles}" .. />
      <!-- the 'action-method' depends on the site, in which fileUpload.xhtml is embeeded, so I tried to use a variable (which does not work) -->
      <a4j:support event="onuploadcomplete" action="#{uploadFiles}"/>
      </rich:fileUpload>
      </h:form>
      </a4j:outputPanel>
      </ui:composition>


      Now, I want to use this fragment within another page:

      <a4j:outputPanel>
      <!--this works, it is a property-->
      <ui:param name="styleUploadFiles" value="style1.css" />
      <!--this works not, as it is a action -->
      <ui:param name="uploadFiles" value="#{myBean.uploadGif}" />
      <ui:include src="uploadFiles.xhtml"/>
      </a4j:outputPanel>



      myBean.uploadGif is a action which I want to bind to uploadFiles - but, trivial, this does not work, as with ui:param, only param-binding is allowed and and not actions.

      I have three pages which uses the same composition in "fileUpload.xhtml" but I want to inject different methods (depending on the site).

      I need something like the ejb-annotation @AroundInvoke (in which a variable method is called within a bunch of same code) - but only for JSF-TreeBuilding. However, I guess, I could build a extra component via facelets - but then I have to do a tag-library and register it - I do not want that.

      Now my question: Is there another simpler solution - maybe via a rf-components?

      I could imagine a new component such as 'a4j:aroundInvoke':

      <a4j:aroundInvoke bind="fileUpload.xhtml" action="#{
      myBean.uploadGif}" var="uploadFiles">
      </a4j:aroundInvoke>


      You see, with the new component, I would inject the composition "fileUpload", bind it to action 'myBean.uploadGif' via the variable 'uploadFiles'. Would this makes sense?

      Or is it senseless, as jsf2/rf4 has something like that?



        • 1. Re: <a4j:aroundInvoke ? or something else ?
          nimo stephan Master

          The component

          <a4j:aroundInvoke bind="fileUpload.xhtml" action="#{
          myBean.uploadGif}" var="uploadFiles">
          </a4j:aroundInvoke>

          would then produce this jsf-tree

          ...
          <a4j:outputPanel>
          <h:form>
          <rich:fileUpload .. />
          <!-- the 'action-method' depends on the site, in which fileUpload.xhtml is embeeded, so the var 'uploadFiles' of 'a4j:aroundInvoke' injects the right method-->
          <a4j:support event="onuploadcomplete" action="#{myBean.uploadGif}"/>
          </rich:fileUpload>
          </h:form>
          </a4j:outputPanel>
          ..


          Is this idea sensefull? Or exists another simpler way?

          • 2. Re: <a4j:aroundInvoke ? or something else ?
            Ilya Shaikovsky Master

            try please

            <ui:composition>
            <a4j:outputPanel>
            <h:form>
            <rich:fileUpload id="uploadTracks" styleClass="#{styleUploadFiles}" .. />
            <a4j:support event="onuploadcomplete" action="#{uploadFilesBean.uploadFiles}"/>
            </rich:fileUpload>
            </h:form>
            </a4j:outputPanel>
            </ui:composition>
            


            and

            <a4j:outputPanel>
             <ui:include src="uploadFiles.xhtml">
             <ui:param name="uploadFilesBean" value="#{myBean}" />
             </ui:include>
            </a4j:outputPanel>


            so you passing object reference which should implement upload method.

            • 3. Re: <a4j:aroundInvoke ? or something else ?
              Nick Belaevski Master

              Hi,

              JSF2 is capable of passing method expressions into composite components, so it's not necessary. We've implemented solution for the problem in photoalbum application, you can check it.

              • 4. Re: <a4j:aroundInvoke ? or something else ?
                nimo stephan Master

                hello ilya,

                thank you, this works:

                <ui:composition>
                <a4j:outputPanel>
                <h:form>
                <rich:fileUpload id="uploadTracks" styleClass="#{styleUploadFiles}" .. />
                <a4j:support event="onuploadcomplete" action="#{uploadFilesBean.uploadFiles}"/>
                </rich:fileUpload>
                </h:form>
                </a4j:outputPanel>
                </ui:composition>
                
                
                <ui:include src="components/uploadTracks.xhtml">
                 <ui:param name="uploadFilesBean" value="#{mySessionBean}" />
                </ui:include>


                however, I have to create two objects which I want to avoid - but nice to know this!

                hey nick,

                JSF2 is capable of passing method expressions into composite components


                this is exactly what I need - I will check the "photoalbum application" (however, I guess, I have to wait till jsf2 and rf4 is out, so I cannot use it yet, am I right?).


                • 5. Re: <a4j:aroundInvoke ? or something else ?
                  Ilya Shaikovsky Master

                  I have been able to google some solutions in facelets related blogs some time ago.. but not stored the links.. :( Try search more for it.. just search the facelets related solutions and not RF related.