wood burning stoves 2.0*
The moose likes JSF and the fly likes Bean value not getting updated Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Bean value not getting updated" Watch "Bean value not getting updated" New topic
Author

Bean value not getting updated

Marissah Miller
Greenhorn

Joined: Apr 28, 2013
Posts: 5
Hi, I'm new to JSF so please forgive my lack of knowledge! I have been stuck on the same issue for a few weeks and have gotten so frustrated with it that I just can't seem to figure it out. I've tried searching, tried looking at examples, but what I'm doing is a tad odd and I can't seem to figure out what's wrong. Long story short, I have a tree whose children are "pages" and the pages each have "questions" as children. I am making something a bit similar to SurveyMonkey or FluidSurveys so the main content pane will have options for configuring a question (text, multiple choice, numeric, etc). When you click the tree nodes for the "questions" I want it to save the values (in the database or session, doesn't matter, I haven't gotten that far yet) the user has selected and then load the previously saved configuration for the question node they have just clicked. So the event that will trigger the need for reading the values the user has input is my OnNodeSelect. However, when I check the "question" values, they are still the same as they were initialized to. The bean is session scoped and is working for the tree aspects (I can add and remove nodes) but I can never get the values for the question. I have a feeling that I'm making a really obvious mistake, but I just can't figure it out. Also, I apologize in advance for my code if it's not very good.

The way I'm testing (as a preliminary step before coding to do something useful) is when I select a node, I attempt to print out what the question text is. It's always null even though I have typed in the text area. I also have a println in the set method for questionText but that never gets printed out.

Here is the xhtml:



There's a bunch more code after that, but it's irrelevant.


Here's the bean (with irrelevant portions removed):

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Welcome to the JavaRanch, Marissa!

Once an example gets too big to fit on the screen, the odds that people will spend time trying to make sense of it go way down. So wherever possible, try and strip out as much of the non-essentials as you can.

I cannot tell for sure (forest/trees, see above), but it looks like you are expecting a stock html <input type="checkbox"> to do the work of a JSF <h:selectOneRadiobutton> control. That won't work. JSF won't transfer View Control data to/from the backing bean unless the control is a JSF control.


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

Joined: Apr 28, 2013
Posts: 5
Thanks for the advice Tim. I removed most of the code I had posted (I wouldn't want to look at that much either, I just know I've seen forums where the first response is something like "you have to post all of your code so we can help you" so I thought I'd just start with that).

Okay, so when a node of the tree gets selected OnNodeSelect() DOES get called in the backing bean. However, questionText is always "" even if I have typed something there. So my backing bean is working for the tree (ajax listeners are working) but I don't understand why questionText doesn't get updated. Do I have to submit the form for that to happen? If so, how can I simulate this from the OnNodeSelect() method because that's when I need to get the value. The setQuestionText() method never gets called.

Thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

AJAX does submit a form. That's not a problem. AJAX can also be fine-tuned to submit only part of a form, but it will always submit its data as a form.

However, a Submit operation submits ONLY the form that contains the control that triggers the submit. So any data you enter in any other form will not be submitted. That's a basic HTML constraint, not just a JSF one.
Marissah Miller
Greenhorn

Joined: Apr 28, 2013
Posts: 5
Sorry about the delayed response..I'm a full-time student and I also work full-time and I had a huge project demo on Thursday so I was too busy to check out what you said. When I removed the "treeForm" h:form and just had the whole page on the same form, I was then able to accomplish what I wanted. Thank you so much for your help!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bean value not getting updated