2 Replies Latest reply on Mar 11, 2009 12:34 PM by bobgee

    Don't repeat your code - how to?

      In my view pages I have very similar code which differs only in one string an one session bean name. Currently it's about the page navigation html for a resultset - yet I'm interested in a common approach.
      I ask myself how I could evacuate that xhtml code in an include file and passing the differing parts as parameters.


      Current code within a PrinterList.xhtml:


          <div class="tableControl">
      
              <s:link view="/PrinterList.xhtml"
                  rendered="#{printerList.previousExists}"
                        id="firstPage">
                  <h:graphicImage value="#{messages.imgPageFirst}"/>
                <f:param name="firstResult" value="0"/>
              </s:link>
      
              <s:link view="/PrinterList.xhtml"
                  rendered="#{printerList.previousExists}"
                        id="previousPage">
                  <h:graphicImage value="#{messages.imgPagePrevious}"/>
                  <f:param name="firstResult"
                          value="#{printerList.previousFirstResult}"/>
              </s:link>
      
              <s:link view="/PrinterList.xhtml"
                  rendered="#{printerList.nextExists}"
                        id="nextPage">
                  <h:graphicImage value="#{messages.imgPageNext}"/>
                  <f:param name="firstResult"
                          value="#{printerList.nextFirstResult}"/>
              </s:link>
      
              <s:link view="/PrinterList.xhtml"
                  rendered="#{printerList.nextExists}"
                        id="lastPage">
                  <h:graphicImage value="#{messages.imgPageLast}"/>
                  <f:param name="firstResult"
                          value="#{printerList.lastFirstResult}"/>
              </s:link>
      
          </div>



      Basic idea is to move that into an include file and pass the name of the view page (here: PrinterList) and the name of the list bean (here: printerList):


      <ui:include src="/layout/tablePaging.xhtml">
           <ui:param name="view" value="PrinterList" />
           <ui:param name="listBean" value="#{printerList}" />
      </ui:include>
      



      The main questions:
      How do I pass the listBean and how do I specify the EL expression for the listBean in the includeded file?
      (listBean.nextExists, listBean.nextFirstResult etc. - how to convert from name to entity?)
      - and: is there a more elegant way (maybe putting variable into page scope)?


      Everything well to understand?


      Thanks!
      Robert

        • 1. Re: Don't repeat your code - how to?
          niox.nikospara.yahoo.com

          Hello,


          I think you are on the right track. What I have done:


          In first.xhtml:


          <ui:include src="/WEB-INF/include/prok/controls_form.xhtml">
               <ui:param name="x" value="#{controlsHelper.tmp}" />
          </ui:include>
          



          In controls_form.xhtml (notice #{x.espa} is substituted for #{controlsHelper.tmp.espa}):


          <s:decorate id="espaDeco" template="/layout/edit.xhtml">
               <ui:param name="fldcode" value="502" />
               <h:selectBooleanCheckbox id="espa" value="#{x.espa}" disabled="false" />
          </s:decorate>
          



          It is just as you propose. The case for your other param, view, should be similar (but I havent checked if @view accepts EL expression):


          <s:link view="/#{view}.xhtml" ... />
          



          I do not understand what do you mean convert from name to entity. The substitute variable is as good as the substituted, if that's what you ask.


          In my opinion the Facelets way you are thinking of is elegant.

          • 2. Re: Don't repeat your code - how to?

            Thanks, Nikos, for your reply, was helpful to know that I'm on the right way.



            I do not understand what do you mean 'convert from name to entity'. The substitute variable is as good as the substituted, if that's what you ask.

            Seems, I did a mistake, thought the passed bean isn't know as bean in the included page, but it is.
            Works fine now.


            The problems left is to show the current page number (there is no function in EntityQuery for that) and how to set maxResults from the view side, not from the list bean.


            Greets, Robert