• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to navigate JSf form using value from h:selectOneRadio

 
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am right now exploring JSF for presentation layer. I am designing a form with <h:outputLabel..> and <h:inputText...> for the user to input his value. I also have a radio button as below.

And I have included the following piece of code in faces-config.xml as below.


Hence I get two option box as Pass and Fail.
I am also bit aware of navigation rules of JSF. Now I want the user to take to the step 2 if he chooses the option Pass and if the user chooses Fail, then I want to reset the values of the above form and display the same form. Please let me know how I can proceed from here.
[ January 13, 2008: Message edited by: Lilly bug ]
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Probably you cold write the following code:

<h:selectOneRadio value="#{list}" onchange="this.form.submit()"
valueChangeListener="#{backinbBean.valChngLsnr}"/>

In the backing bean we can write the follwing code
public void valChngLsnr(ValueChangeEvent vce){
if (vce.getNewValue()==Pass){
//goto step 2. Note: However,this would not be providing any navigation
// as you can see that the return type is void.

}
}

Now the issue of

reset the values of the above form and display the same form



would be resolved by itself provided that the scope of your managed bean representing the Page's backing bean remains request.

Tell me how it works.......
 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Dhushyant fro your reply. As I am a new bee to programming, I really don't understand properly. For reset property I have added one more button at the bottom as which resets the form. I have not yet done any java part in the application and I am only trying to show a mock form at this stage, hence playing around JSP pages and faces-config.xml and basically trying to do presentation layer. So I don't understand the java part which you had mentioned. As I said previously, If the user chooses option "Pass", then I am supposed to take him to the next page. Please explain me bit about the java part if you have time. Thanks.
 
Dushyant Agarwal
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
When we press a reset button on a page then whatever editable values that we might have entered on the page ,before the form gets submitted, get cleared.

Okay so, using a reset button would not serve the purpose.

Now when I asked you to place a value Change Listener I wanted you to write a simple method in a class which would act as the backing bean of the jsf/jsp page that you are creating.

The method might be as follows :-


Now in the faces-config.xml we register the class in which this method is created (FOr more on how to register a managed bean refer to JSF-The complete reference-Chris Schalk & Ed Burns)

Now when we write
it means we want to submit the form when someone tries to select any option from the radio Button.

On submitting the form a series of steps - known as the Request processing lifecycle - takes place.
It is a series of steps that automatiacally take place before your page gets submitted i.e. your request gets fired from the browser .

Now, During the fifth step the value change Listener function would be
called and the logic you implemented owuld get executed.

All this occurs between your selecting some option on the radio button and
and the rendering of the response .

Now I have tried to give a brief overview of what goes on behind scenes.
But for correct knowledge it is best taht you refer to the JSF complete reference.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Lilly bug",
Please check your private messages.
 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your response. I am jsut asked to use Javascript to show the demo now as a skeleton of functionalities. So at present I have to find the status of radiobutton using javascript and navigate accordingly.
I am posting my javascripts which is being invoked by a button. But this is not working.


I tried both the above scripts and are not working as well as confuse me.

But when I cick on the button, I am not getting any alert window.
Is it possible to check the status of a JSF component through javascript. Pease let me know.

I would like to check the status of this radiobutton and open windows accordingly. For example if the status is Fail, I will display the same page(Library.jsp) and will display (success.jsp) if the status is Pass
 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
javascript function is as follows:

I tried in the following ways and both didn't work.
Pretty much confused and want to know how to check the status of JSF radio button using Javascript. Please let me know.

<script language="JavaScript" type="text/javascript">
function function2() {
var m = document.all.statusList.status;
alert(m);
}
</script>


<script language="JavaScript" type="text/javascript">

function function2() {
for (var i=0; i < document.all.statusList.length; i++)
{
if (document.all.statusList[i].checked)
{
var rad_val = document.all.statusList[i].value;
}
}
alert(rad_val);
}
</script>
[ February 03, 2008: Message edited by: Lilly, Gopu ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic