In my application I am using JSF 1.2. I dont want to use facelets taglib so I have included a JSP using jsp:include attribute. I want to pass a variable to subpage which will decide the style class value. Below is the code for parent.jsp
<f:view>
...
<f:subview id="navigation">
<jsp:include page="/subpage/child.jsp">
<jsp:param value="page9" name="pageName"/>
</jsp:include>
</f:subview>
...
</f:view>
Child jsp is
<f:subview id="navigation">
...
<t:commandLink id="page9" value="mylink" action="#{manageBean.someAction}"
styleClass="#{param.pageName == 'page9'?'stepLinkActive':'stepLink'}" />
...
</f:subview>
In above code stepActiveLink class is not getting applied to myLink. Infact #{param.pageName} value is blank.
I found this link on SO which works if I use surrounding the command link like below
<c:if test='${param.pagename eq "page9"}'>
<t:commandLink id="page9"
value="#{msgs['DICT.ISSUE_CONTROL.SPECIAL_INFO']} "
action="#{bondIssueBean.gotoModifyPage9}" styleClass="stepLinkActive" />
</c:if>
<c:if test='${param.pagename ne "page9"}'>
<t:commandLink id="page9"
value="#{msgs['DICT.ISSUE_CONTROL.SPECIAL_INFO']} "
action="#{bondIssueBean.gotoModifyPage9}" styleClass="stepLink" />
</c:if>
I have lot of commandLinks which will need to duplicate commandlink definition just to change style class. I wonder, going forward if any other param is passed then it may increase duplicate codes. My questions are
- Why JSF EL can not identify param value – ${param.paramName}? I also tried accessing param variable using #{param[‘pageName’]} but no luck.
- How I can replace above if..else so that I can have single commandlink definition?
It fails “by design”. For a technical background story see also JSF issue 629, which summarizes as follows:
There’s however a possible workaround with help of
<c:set>which copies it into the request scope so that it’s available in JSF EL#{}as well.