aspose file tools*
The moose likes JSF and the fly likes Display Different Sections while selecting different radio buttons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Display Different Sections while selecting different radio buttons" Watch "Display Different Sections while selecting different radio buttons" New topic
Author

Display Different Sections while selecting different radio buttons

Mahendra Chowdary
Greenhorn

Joined: Aug 26, 2010
Posts: 25
Hi ,

I am quite new to JSF. I have a query . I need to display two different panel when i select the different radio buttons . I am using the rich faces tags in my jsf page. I know how we can achieve this using javascript. But my interest is to achieve this functionality using Ajax. Is it possible . can somebody suggest.
Sumeet Singh Aryan
Ranch Hand

Joined: Jul 30, 2008
Posts: 43
please provide the sample code that you are trying.

I think you are not aware of reRender AJAX property. Do some google on it. this will surely help you.


The woods are lovely, dark and deep, But I have promises to keep; And miles to go before I sleep, And miles to go before I sleep. - Robert Frost
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16054
    
  21

It is very possible. Simply use the "rendered=" attribute on the two panels in question and use EL expressions such as "#{myBean.radioSelection == 1}"/"#{myBean.radioSelection == 2}"

Use of AJAX support such as RichFaces reRender can reduce the need for full-page refresh, but the end result is the same.


Customer surveys are for companies who didn't pay proper attention to begin with.
Mahendra Chowdary
Greenhorn

Joined: Aug 26, 2010
Posts: 25
Hi ,

Could sombody provide me some sample code so that i can render component on the basis of ajax request

Thanks
Mahi
Mahendra Chowdary
Greenhorn

Joined: Aug 26, 2010
Posts: 25
Please see my code ,

In the page i have,

<h:selectOneRadio id="Internalradioselect">
<f:selectItem id="InternalPerson" itemLabel="Person" itemValue="11">
<a:support event="onselect" reRender="panel1" action="#{addcontact.firstRadioChecked}" ></a:support>
</f:selectItem>
<f:selectItem id="InternalDistributionList" itemLabel="DistributionList" itemValue="22">
<a:support event="onselect" reRender="panel2" action="#{addcontact.secondRadioChecked}" ></a:support>
</f:selectItem>
</h:selectOneRadio>

<rich:panel id="panel1" rendered="#{addcontact.firstRadioChecked}">
Welcome to Panel 1
</rich:panel>

<rich:panel id="panel2" rendered="#{addcontact.secondRadioChecked}">
Welcome to Panel 2
</rich:panel>


In the java file i have

private Boolean firstRadioChecked = false;
private Boolean secondRadioChecked = false;

public Boolean getFirstRadioChecked() {
firstRadioChecked = true;
return firstRadioChecked;
}

public void setFirstRadioChecked(Boolean firstRadioChecked) {
this.firstRadioChecked = firstRadioChecked;
}

public Boolean getSecondRadioChecked() {
secondRadioChecked = true;
return secondRadioChecked;
}

public void setSecondRadioChecked(Boolean secondRadioChecked) {
this.secondRadioChecked = secondRadioChecked;
}





But while viewing on the page i am getting the following exception ..

javax.el.PropertyNotFoundException: /addcontact.xhtml @101,73 rendered="#{addcontact.firstRadioChecked}": Property 'firstRadioChecked' not found on type org.javassist.tmp.java.lang.Object_$$_javassist_1


Please suggest


Thanks
Baziaz
Mahendra Chowdary
Greenhorn

Joined: Aug 26, 2010
Posts: 25
When i try to run the page

the methods in the bean class are getting executed even before i perform an action like selecting a button on the page .

Can somebody please look into this .

Thanks
Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
I presume you solved your first problem since you now tell us that you have been able to view the page?

In you java code you do this
So you getter method always return true and always sets the property in question as selected. Why?!? What is the logic here? Shouldn't the getter only get the property and setter set it when needed?
Mahendra Chowdary
Greenhorn

Joined: Aug 26, 2010
Posts: 25
I will call this function only when i select a particular radio button

Now , i am having another problem ,,

All the methods in my bean are getting executed without performing an action
Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
Go Green wrote:I will call this function only when i select a particular radio button

Now , i am having another problem ,,

All the methods in my bean are getting executed without performing an action
I see. So your real problem is that you do not understand basic concepts of JSF framework. Your form is sending the values to the bean when the forms is sent BUT the initial values of the inputs in the form ALSO come from the backing bean. That is why all the getters of the properties present in the form are being executed when the form is viewed! So if you think that the getters are only being executed when you call them yourself you are wrong.

So, as a simplification, the getters are being called when the form is viewed and setters are being called when the form is sent to server. Of course AJAX calls can make other getter and setter calls but the general rule still applies.
Mahendra Chowdary
Greenhorn

Joined: Aug 26, 2010
Posts: 25
So ,

How should i modify my code so as to satisfy the following requirement.

I need to display different panels when i select different radio buttons in the page .
Mahendra Chowdary
Greenhorn

Joined: Aug 26, 2010
Posts: 25
Sorry ,

Double Post
Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
Well, first of all fix your java code so that the getters behave as they should be and only return the values.

And if you need to show one of the panels initially you can change the initialization for example to this
or do something similar.

But what comes to you ajax code I can not help you there. Sorry. I am not familiar with Rich Faces tags.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Display Different Sections while selecting different radio buttons