Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ajax with JSF

 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I am using JSF for frontend, I have a siutuation as below and I think Ajax would solve the situation even though I have not used ajax before. Please give some suggestions.

I have a jsf form with two option button "yes" or "no". If the user selects "yes" option button, the I need to show a drop down menu for the user to select. And if the user selects "no", then no action is needed. Kidly suggest me whether Ajax would be a better option.

Thanks.
 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can it be done though event handling of JSF components without AJAX? I am looking for the possibility. Thanks.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18156
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gopu Akraju:
Can it be done though event handling of JSF components without AJAX? I am looking for the possibility. Thanks.


Yes, although it requires a page refresh. In that case, use the "render=" attribute on the drop down menu and make it refer to a backing bean variable that gets set by the "yes" option button.

AJAX-enabled JSF tags, such as RichFaces can also handle this using a partial page request.
 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim.

I have a set of radio buttons, YES and NO. I want to add the value change listener for selectonemenu item and then calling a method (render.javaMethod) on valuechangelistener.

I could understand up to this step. If the user selects YES, I have to display a list of numbers from 1 till 9 as a drop down menu and then depending upon the user's selection from the number, I have to use a backing bean to write to a database.

Can anyone please explain how to do this? I really don't understand on "refresh" part too. B'cos I need to see the change before I submit my form. Thanks.
 
Joe Matthew
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the benefits of using AJAX is that the page does not refresh. Much better UI to the user.

But if you want to use JSF only, on clicking the radio button, the page will be refreshed with your drop down displayed.
 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Thanks. refresh is working now. And I am able to catch the value change as below with some system.out.printlns. I still have some abouts about how to display a list of numbers if the radio button value is "yes".



My method is also getting triggered when there is change in the selection of radio button as below:



Now my doubt is how to pass or display to list the set of numbers(ie "{#testLaneList}") if the radio button value is "yes"

<h:selectOneMenu id= "lanes" attribute? I don't know this part value="#{controlLaneList}"> </h:selectOneMenu>

Can any one tell how to achieve this? I know that I am just few steps to reach my goal. As I don't find any suitable example, I am kind of stuck here.
 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I managed to like below:

Setting the boolean value in java method.


from jsp page:



Thanks and it works.
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the user point of view, I would definitely recommend to skip any AJAX magic. I would display a disabled dropdown, which gets enabledif yes is clicked, and stays untouched otherwise.

The key point is that in this scenario the user has an idea of what is going to happen if he clicks on the radio button, and no fields will appear automagically.

From the techie point of view - use AJAX. it's cool.

:-)

jan
 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jan,

Actually I am not using ajax now and tru=ying to use valuechangelistener as explained here

But I have some difficulities in binding the component value, if possible please go through that thread and give me your feedback. Dying to figure out for the past 2 days

Thanks and Regards
Gopu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic