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

    Don't repeat your code - how to?

    Robert Grampp Newbie

      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"
                  <h:graphicImage value="#{messages.imgPageFirst}"/>
                <f:param name="firstResult" value="0"/>
              <s:link view="/PrinterList.xhtml"
                  <h:graphicImage value="#{messages.imgPagePrevious}"/>
                  <f:param name="firstResult"
              <s:link view="/PrinterList.xhtml"
                  <h:graphicImage value="#{messages.imgPageNext}"/>
                  <f:param name="firstResult"
              <s:link view="/PrinterList.xhtml"
                  <h:graphicImage value="#{messages.imgPageLast}"/>
                  <f:param name="firstResult"

      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}" />

      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?


        • 1. Re: Don't repeat your code - how to?
          Nikos Paraskevopoulos Novice


          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}" />

          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" />

          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?
            Robert Grampp Newbie

            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