How to compare 2 lines using <c: if>?
I am trying to display <h:outputText> or <h:commandLink> , respectively, the String property returned by the swap bean. I'm having trouble comparing strings. Here is an illustration:
<c:if test='#{column.header ne "Details"}'> <h:outputText value="#{recordTable[column.property]}"/><br/> </c:if> <c:if test='#{column.header eq "Details"}'> <h:commandLink value="#{column.header}" action="#{searchBean.goToWarehouse}"/><br/> </c:if> However, comparisons do not work. Is this the right way to do this? Is it possible to do this without <jsp:useBean....> as done in: JSP sample
Thanks for any help
It seems you are using this in <h:dataTable> . JSTL tags are only evaluated when creating view time, and not during view rendering. This boils down to the following: JSTL runs from top to bottom, and then passes the result to JSF to restart from top to bottom. At the moment, JSTL tags are evaluated inside JSF data, then a repeating iterative element (the one in the var attribute) is not available for JSTL. Therefore, the test result is always false .
Just use the attribute of the rendered JSF component.
<h:outputText value="#{recordTable[column.property]}" rendered="#{column.header ne 'Details'}"/> <h:commandLink value="#{column.header}" rendered="#{column.header eq 'Details'}" action="#{searchBean.goToWarehouse}"/> <br/> Here are some more examples of using the rendered attribute:
<h:someComponent rendered="#{bean.booleanValue}" /> <h:someComponent rendered="#{bean.intValue gt 10}" /> <h:someComponent rendered="#{bean.objectValue == null}" /> <h:someComponent rendered="#{bean.stringValue != 'someValue'}" /> <h:someComponent rendered="#{!empty bean.collectionValue}" /> <h:someComponent rendered="#{!bean.booleanValue and bean.intValue != 0}" /> <h:someComponent rendered="#{bean.enumValue == 'ONE' or bean.enumValue == 'TWO'}" /> Unrelated to a specific problem, Roseindia is not the best JSF training resource. I would recommend going to other resources.