This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Render form components with Ajax

 
George Schrader
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a form dynamically based on questions from a database. Some of the questions need only be displayed based on a yes of one of the previous radio button questions (yes or no). In other words, if one of the answers are selected with yes, then how do I dynamically render other questions or not render them if it is selected as no. Since the ids are created dynmically, how can this be done?

 
Tim Holloway
Saloon Keeper
Pie
Posts: 17616
38
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's some really nasty EL in there. Wow.

Your example didn't attempt any AJAX. I never tried out the new AJAX tag for JSF2, but I can tell you how the RichFaces AJAX would handle that.

First of all, however, I'd recommend using a dataTable and not a ui:repeat. You're basically attempting to program on what is properly supposed to be a page template. Or in other words, you're breaking the MVC paradigm. The code should be in the Model, not in the View (most Controllers in JSF are vendor-supplied, not user-written).

Secondly, along the same lines, you're writing code in EL. EL should be kept simple, not only so that people don't have to treasure-hunt between the Model and View for functionalities, but because EL can be a real bugger to debug.

Having said that, here's a simple RichFaces sample of how to make something like what you described, adhering to the about guidelines. It looks like you're using IceFaces, and it has similar capabilities.


I've made a few implied changes to the table dataModel to keep the EL simple and to keep the model a unit instead of a collection of loosely-associated data from different places. That is, after all, what models are for.

More importantly for your purposes, note that I've directed the UI to re-render the 2 response controls when the radio buttons are changed. I've also removed the "required" stuff, since the model is expected to have initialized the value, and thereafter the UI should ensure that one of the buttons is selected. Properly speaking, for a yes/no input a checkbox should be employed, but that's another matter.
 
George Schrader
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for the response. Guess I should have stated that I am using Primefaces. I will see if there is a comparable tag and try this out...
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic