In a JSF component what is the best way to “refactor” common constants, e.g. names/paths in a <h:graphicImage> tag to a single local, temporary property?
<ui:composite>
<h:graphicImage library="mylib" name="/a/b/c/img1.png"/>
<h:graphicImage library="mylib" name="/a/b/c/img2.png"/>
<h:graphicImage library="mylib" name="/a/b/c/img3.png"/>
<!-- ... lots of repetitions -->
</ui:composite>
should be
<ui:composite>
<-- assign /a/b/c/ to path -->
<h:graphicImage library="mylib" name="#{path}img1.png"/>
<h:graphicImage library="mylib" name="#{path}img2.png"/>
<h:graphicImage library="mylib" name="#{path}img3.png"/>
<!-- ... lots of repetitions -->
</ui:composite>
Use
<c:set>on application scope. This basically stores the variable in the application map.Make sure that the
var="path"doesn’t conflict with existing managed bean names or implicit EL variables and such. You could if necessary use a convention to prefix it with_.