Don't repeat your code - how to?
bobgee Mar 9, 2009 4:06 PMIn 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
 
    