Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ui:include with parameters?

Have JSF 1.2 two pages(one.xhtml and other.xhtml),
that are included to the current page by following rule:

...     <c:if test="#{flowScope.Bean.param1}">         <ui:include src="one.xhtml"/>     </c:if>       <c:if test="#{!flowScope.Bean.param1}">         <ui:include src="other.xhtml"/>     </c:if>  ... 

As far one.xhtml differs from other.xhtml only by action parameters:

one.xhtml:<h:commandLink action="actionOne">
other.xhtml:<h:commandLink action="actionTwo">

Is it possible to use some general xhtml?
Instead of one.xhtml and other.xhtml,something like this:

...     <c:if test="#{flowScope.Bean.param1}">         <ui:include src="general.xhtml" param="actionOne"/>     </c:if>       <c:if test="#{!flowScope.Bean.param1}">         <ui:include src="general.xhtml" param="actionTwo"/>     </c:if>  ... 

thank you for help.

like image 760
sergionni Avatar asked Mar 13 '11 17:03

sergionni


People also ask

How do I use ui include?

Use ui:insert and ui:include tag to include header/footer and content file in template file. Name each section in ui:insert tag. name attribute of ui:insert tag will be used to replace the contents of the corresponding section.

What is ui Param JSF?

Use ui:param tag to define a parameter containing a value to be passed to Header section. <ui:insert name = "header" > <ui:include src = "/templates/header.xhtml" > <ui:param name = "defaultHeader" value = "Default Header" /> </ui:include> </ui:insert>


2 Answers

You need to nest <ui:param> inside <ui:include> to pass parameters to the included file.

<ui:include src="general.xhtml">     <ui:param name="action" value="actionOne" /> </ui:include> 

and in the include:

<h:commandButton action="#{action}" /> 

Note that this only supports strings, not action methods. For the latter you would need to upgrade to JSF 2.0 and use composite components.

like image 155
BalusC Avatar answered Sep 24 '22 12:09

BalusC


In addition to BalusC's answer:

Note that this only supports strings, not action methods. For the latter you would need to upgrade to JSF 2.0 and use composite components.

There is a way to do this with JSF 1.2, though it's somewhat ugly:

<ui:include src="general.xhtml">     <ui:param name="actionBean" value="#{myBackingBean}" />     <ui:param name="actionMethod" value="edit" /> </ui:include> 

and

<h:commandButton action="#{actionBean[actionMethod]}" /> 
like image 44
meriton Avatar answered Sep 21 '22 12:09

meriton