| Author |
Radio buttons, ajax and rendering.
|
Vladislav Simovic
Ranch Hand
Joined: Feb 03, 2011
Posts: 37
|
|
So basically what i am trying to achieve is when i select certain radio button some things get rendered and some not. Ofcorse, i dont need to render the hole page again, just some things. I have written something like this, but this is not working:
How to do this properly?
|
 |
karan khosla
Greenhorn
Joined: Apr 27, 2009
Posts: 22
|
|
Hi,
I believe you have to do few things to make it work.
Firstly,
<f:ajax event="change" render="area" listener="#{beanName.methodWithYourLogic}" />
Here, "methodWithYourLogic" is the method name can be anything that you define in your bean class with the logic on what basis you want to display the component or the other way around. In this method by the end make that variable true so it will show the component.
Secondly,
<h:inputTextarea id="area" render=#{beanName.someboolVar} style="margin-left: 50px"/>
Hope! This Helps.
|
Karan Check me out on http://pythonicway.blogspot.com/
|
 |
Vladislav Simovic
Ranch Hand
Joined: Feb 03, 2011
Posts: 37
|
|
<f:ajax> Unable to attach <f:ajax> to non-ClientBehaviorHolder parent
is the error i get. it seems you cant put <f:ajax> into <f:selectItem>. Without this i cant do ajax request when certain radio button is selected. Is there any other way to do this?
|
 |
karan khosla
Greenhorn
Joined: Apr 27, 2009
Posts: 22
|
|
Yes! You have to put in <f:ajax> inside a component. For Example:
Here,
variableInBean, most likely has to be string. In bean you have to fetch this variable to know what user has selected.
listInBean, has to be a container. for example, ArrayList.
This is a dynamic way of doing it.
OR,
Static way where radio buttons has fixed labels.
Hope! This Helps.
|
 |
deva kumar
Greenhorn
Joined: Apr 11, 2013
Posts: 2
|
|
Hi
<h:selectOneRadio id="selectRadioId" style="padding-left: 10px; padding-right: 10px;" rendered="true" >
<f:selectItem value="one" rendered="true" />
<f:selectItem value="two" rendered="true" />
<f:ajax event="change" render="roleData" listener="#{testClass.getRolesList()}"/>
</h:selectOneRadio>
<h:dataTable id="roleData" rows="3" value="#{testClass.allRoles}" var="role" rendered="true" border="2">
<h:column>
<f:facet name="header">name</f:facet>
#{role.role}
</h:column>
<h:column>
<f:facet name="header">id</f:facet>
${role.id}
</h:column>
</h:dataTable>
While trying above code i'm getting error
"java.lang.String cannot be cast to javax.faces.model.SelectItem"
also the datatable is not rendered.
help to resolve this.
thanks
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14561
|
|
Welcome to the JavaRanch, Deva!
You can make your sample code and XML easier to read by using the "Code" button in our message editor. Also, we would prefer that you didn't "piggyback" onto an existing topic if you have a question of your own. Start your own topic. It makes it easier for people to follow.
Your exception comes from the fact that the SelectOneRadiobutton control does not take string labels, it takes SelectItem model objects. A SelectItem is a label/value pair where the itemlabel is the text displayed next to the button and the itemvalue is what the radioButton's value will be set to when the button is clicked.
In essence, the SelectOneRadiobutton has mechanics that work exactly like a selectOneMenu control, except that instead of rendering as a dropdown list, you get buttons.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
deva kumar
Greenhorn
Joined: Apr 11, 2013
Posts: 2
|
|
Thanks.
|
 |
 |
|
|
subject: Radio buttons, ajax and rendering.
|
|
|