0

When the user chooses the expert radio button, I would like to render an additional outputText with "expert" as value. I tried ajax, with event,listener and render attributes but nothing works.

This is my form:

<h:form>
    <h:selectOneRadio id="rb" value="#{account.dtype}">
        <f:selectItem itemId="user" itemValue="user" itemLabel="User" />
        <f:selectItem itemId="admin" itemValue="admin" itemLabel="Admin" />
        <f:selectItem itemId="expert" itemValue="expert" itemLabel="Expert" />
        <f:ajax execute="@this" render="choice"/>
    </h:selectOneRadio>
    <br />
    <h:outputLabel id="choice" value="#{account.dtype}" rendered="#{account.dtype}=='expert'" />
</h:form>
user3129002
  • 1
  • 1
  • 3
  • With JSF 2.x, the attribute itemId is not defined in the component selectItem: your page won't work. Please add the relevant missing information – perissf Dec 23 '13 at 09:26
  • @perissf, it could actually work as non existing attributes are by default ignored. If `Account#Dtype` is an `String` with the necessary getter and setter methods, it should. Anyway, the question is lacked of resources as the managed bean being used. – Aritz Dec 23 '13 at 11:50
  • Have you found the answer useful? In case it helped, mark it as answered, otherwise leave a comment so that I can improve it. – perissf Dec 27 '13 at 13:44

2 Answers2

0

The code you posted contains several errors.

First, you have an error in the EL formula that checks account.dtype: everything that's out of the curly brackets is evaluated as a pure text string, therefore your formula evaluates to the string expert=='expert' and not to a boolean value. You have to use:

<h:outputLabel id="choice" value="#{account.dtype}" rendered="#{account.dtype == 'expert'}" />

(or use eq instead of == operator)

Second, the component to be updated must exist in the DOM tree, otherwise its rendered status cannot be updated. So, wrap it in a component which is always rendered and ajax-update it instead. For example, you can update the whole form:

<f:ajax execute="@this" render="@form"/>

Finally, although this doesn't have any effect, note that the attribute itemId is not defined in the component selectItem, and will be ignored by JSF. Your IDE should have warned you about this.

See also:

Community
  • 1
  • 1
perissf
  • 15,979
  • 14
  • 80
  • 117
-1

Thank you, I found the problem.

The problem was that I had the xhtml page containing the form where the body was instead of , same thing for instead of

I also used the click ajax event instead of "execute".

Your rectifications helped me also, thank you :)

user3129002
  • 1
  • 1
  • 3