• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to check condition in xhtml?  RSS feed

 
Raghu Sha
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to display button based on the condition in xhtml page.
using JSF2 & richface 4.0

<c:forEach items="#{empList}" var="emp">

How to check condition like empList.size > 0 in xhtml?

if list is having value, need to show buttons.
 
Tim Holloway
Bartender
Posts: 18715
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSTL should not be used in JSF, and I don't care that Oracle's docs say otherwise. It doesn't work a lot of the time, and there are native JSF constructs that do the job better and cleaner.

To conditionally render an element in JSF, use its "rendered=" attribute. To conditionally render a set of elements, put them in a container and make the container conditionally rendered.

For example:


I recommend NOT coding complex expressions in EL, because A) the're polluting the MVC Separation of Concerns by putting logic in the View Template (which should be data), and because B) EL is a royal pain to debug. Easier to code the logic in the backing bean where a debugger can set breakpoints. However, for simple display control logic I will accept rendered="#{not empty myBean.elements}".

I VERY strongly discourage using loop-style constructs to render 2-dimensional (tabular) data. That's what the JSF dataTable tag is for.>
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!