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):
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.
An IDE is no substitute for an Intelligent Developer.
Joined: Apr 28, 2013
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.
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.
Joined: Apr 28, 2013
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!