0

I want to render a panelgroup only if the value of my selectOneMenu is not null. I have this:

<h:selectOneMenu value="#{bean.myString}">
    <f:selectItem itemValue=#{null} itemLabel="None" />
    <f:selectItem itemValue="first" itemLabel="First" />
    <f:selectItem itemValue="second" itemLabel="Second" />
    <f:ajax render="panelWrap" />
</h:selectOneMenu>

<h:panelGroup id="panelWrap">
    <h:panelGroup rendered="#{bean.myString == null ? false : true}">
        // My content
    </h:panelGroup>
</h:panelGroup>

I did this a lot with objects but here I am stuck on a simple string value. Can anybody help? Thanks

user1983983
  • 4,793
  • 2
  • 15
  • 24
Loric
  • 1,678
  • 8
  • 28
  • 48
  • 1
    Apart from the XML syntax error and the clumsy double boolean condition, I don't see any problems. What exactly is it, the problem you're having with it? What exactly do you mean with "a simple string value"? Do you want to check if `"first"` is selected or so? If so, why did you ask that you want to check for `null`? – BalusC Jul 24 '13 at 13:52
  • 1
    You forgot the double quotes `"` at `#{null}`. – user1983983 Jul 24 '13 at 14:08
  • I mean that the condition in the 'renderer' doesn't work properly. The panel group is always hidden even when I select 'First' or 'Second'. I would like to make it hidden only when I select 'None'. – Loric Jul 24 '13 at 14:16
  • Also, what BalusC meant by the double boolean condition is you don't need to explicitly check if you condition evaluates to true or not. Example: `rendered = "#{bean.myCondtion == true}"` not necessary, you can simply do `rendered = "#{bean.myCondtion}"` – Andy Jul 24 '13 at 14:34

1 Answers1

2

On your first <f:selectItem> change itemValue=#{null} to itemValue="#{null}". In your second panelGroup change the rendered condition to "#{not empty bean.myString}". You might find this link helpful.

Evaluate empty or null JSTL c tags

Community
  • 1
  • 1
Andy
  • 5,900
  • 2
  • 20
  • 29