File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes JSF 2.0 - Ajaxification of listboxes and menus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF 2.0 - Ajaxification of listboxes and menus" Watch "JSF 2.0 - Ajaxification of listboxes and menus" New topic

JSF 2.0 - Ajaxification of listboxes and menus

Christopher Sharp
Ranch Hand

Joined: Dec 12, 2007
Posts: 155
OK, so far so good, I've made quite a lot of progress with JSF 2.0, but now I'm getting to a particularly important part involving Ajax, which I'm having trouble understanding.

The code without using Ajax works, but it causes irritating page "flips" and messes up the display, and I wish to use Ajax to get rid of that.

The relevant part of the xhtml file is as follows:

where I specify a menu where you can select one out of several options. Once you have decided which option you want, you click <h:commandButton> "Select Set", which fires
an action listener that then downloads from an external file the data you want, which is then used to set up a second menu. The reason why I have chosen to use a command
button once you have selected an option is because a file is downloaded, and I don't want a file to be downloaded every time you change the selection, only when you
specifically want it. <h:commandButton> comment A controls the values given by comments a, but I would like this to be done by Ajax.

Once you have downloaded data, it appears in a second menu in <h:selectOneListbox>, and you can make changes to selected values by inputting text in <h:inputText>, then
<h:commandButton> "Update Abundance" will copy the value in <h:inputText> to the selected place in <h:selectOneListbox>, i.e. <h:commandButton> comment C controls comments c.
Again I would like this to use Ajax.

Finally <h:button> "Readme", comment B, displays a popup using JavaScript, and does not have any associated code in a bean, but also causes an irritatiing page flip.

The code in my bean is as follows, where "a", "A", "c" and "C" correspond to the code in the xhtml file:

The basic question is how to "Ajaxify" the code in a suitable way. Any ideas and suggestions would be most appreciated.
Volodymyr Lysenko
Ranch Hand

Joined: Mar 29, 2012
Posts: 511

Hello Christopher!

I don't think it is good to put so long code and many questions in one post. Better understandable is to put simple question or a few easy to answer questions.
Because the long time should be spent to realize something and I stiil don't understand all your post

As I see you want to do similar to what I did a few weeks ago. As abundanceSet0 is selected corresponding list for abundances0 is constructed.
Together with Tim Holloway I did:

In backing bean I have:

When value of first selectonemenu 'countryGroup' changes this is working
<f:ajax execute="@this" event="change" render="registerForm:regionGroup" />
And this causes to work this
After registerBacking.showRegions f:ajax renders registerForm:regionGroup which causes method getRegionSelectItems to look in database for new regions based on new country
Follow this approach. Probably it is what you need!

True person is moral, false is right!
Christopher Sharp
Ranch Hand

Joined: Dec 12, 2007
Posts: 155
Hello Volodymyr,

Many thanks indeed for your detailed reply, and I'm sure it will be very helpful, particularly as you gave me an example which is similar to my problem. I agree with you that I put in too much information at once, which may have caused some confusion, and should have asked a question about one specific problem at a time.

Basically, I wanted to get the application working without Ajax in the first instance, then put in Ajax to make it work much better. The original version of my code can be found by going first to:

then clicking "MODEL SPECTRA", then clicking "Continue" on the lower left. Most of this was originally written using JavaScript before I knew what server-side code to use, then later decided to use JSF 1.2. Because I already had a lot of JavaScript, I just "bolted in" JSF 1.2 using some additional buttons and hidden fields. Now I am completely rewriting this using JSF 2.0 and want to use as little JavaScript as possible.

I am also seriously thinking of using PrimeFaces, and have played around with some simple tests, but first I need to get some experience with Ajax.
I agree. Here's the link:
subject: JSF 2.0 - Ajaxification of listboxes and menus
It's not a secret anymore!