0

I have 2 <h:panelGroup for conditional text display. When I run with id empty than this condition is executed fine #{empty personBean.person.id} and I see text in it. If I put <h2>#{buttonText}</h2> in panels than I see buttonText properly displayed in h2 tag.

Now Problem:

In below code if I put <h2>#{buttonText}</h2> at the end like below than I always get value Update member due to this I can not use value of buttonText anywhere in the page below. Someone tell me what to do?

 <h:panelGroup rendered="#{empty personBean.person.id}">
                        <h1>Add Information</h1>
                        <i>Use the form below to add your information.</i>
                        <ui:param name="buttonText" value="Add member" />
                    </h:panelGroup>
                    <h:panelGroup rendered="#{not empty personBean.person.id}">
                        <h1>Update Information</h1>
                        <i>Use the form below to edit your information.</i>
                        <ui:param name="buttonText" value="Update member" />
                    </h:panelGroup>
                    <h2>#{buttonText}</h2>

I am unable to use <ui:param like I use <c:set var="buttonText" value="Add member" /> JSTL set variable.

Pirzada
  • 4,685
  • 18
  • 60
  • 113

1 Answers1

2

The <ui:param> is not evaluated during view render time (ask yourself; does it necessarily generate any HTML?), but during view build time. So the rendered attribute isn't been taken into account at all and you effectively end up with both being interpreted and the latter one would always override the former one.

Technically, you'd need to "render" ("build" is a better term, but it reads a bit strange) it conditionally using a view build time tag such as <c:if>. However, in your particular construct it's better is to just check the very same condition in <ui:param>'s value and have only one of it instead of two:

<ui:param name="buttonText" value="#{empty personBean.person.id ? 'Add' : 'Update'} member" />

or just evaluate it directly there where you need it

<h2>#{empty personBean.person.id ? 'Add' : 'Update'} member</h2>

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Just wanted to know if you could tell me. What IDE do you use for your development? Eclipse, IntelliJ, NetBeans or any othere. I am new and using IntelliJ and was thinking about using Eclipse as most companies use that? – Pirzada Dec 01 '12 at 03:09