Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Dynamic Forms  RSS feed

 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using straight jsf can you dynamicaly add aditional components to a form as the user inputs information? Such as they click button foo and button bar is rendered? Without the page reloading? With the page reloading?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are different methods for handling this. You can create the component and set it's rendered property to false. Then in the backing bean when some event occurs you can change it's rendered property to true. This would all be done on the server side. There is no way of doing it without a page reload with JSF only.

You can also create components in your backing bean and then add them to the component tree when some event occurs. However, this is more complicated. I'd just go with the first option.
 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would this generate ugly white space? Is there a way of using placeholders or somthing?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Daniel Prene:
Would this generate ugly white space? Is there a way of using placeholders or somthing?


Ugly white space? No. When the HTML makes it to the browser the component isn't there at all. Well, no whitespace assuming your aren't absolutly placing html components on the page.

The best to way to figure out what you want to do is try a couple of different approaches and use the one that works best for your given situation. Got to dig in and get your hands dirty at some point.
 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help! You're right, it's time a boot up Eclipse and get busy. One last question though... we need to controll front-end layout and such, hence my question about placeholders. We need to know and controll exactly where somthing goes. I was just wondering if there was somthing for components like there is for validation errors. Thanks again!
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you just have a misunderstanding of how it works. Let me explain. And this won't be accurate code, but just an example.



Ok, so that page gets requested as is. Here is the output



Now if we change the rendered property to true we get



So there is a placeholder. The placeholder exists where the component is defined in the JSP. It will show up where it should go as long as the rendered proeprty is set to true. It won't show up if set to false.

Side note: Obviously you'd want to use value binding for the rendered property rather than a static "true" or "false".
[ July 18, 2005: Message edited by: Gregg Bolinger ]
 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, alright. Awesome, that's exactly what I'm looking for. Now I just need to learn how to combine this and event listeners.. Once again, thank you!
 
Thurston Windiberger
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent info, but let me ask one additional question. How can I reload the page (to render or remove components) without triggering the required value validators?

Thanks!
 
Garann Means
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From what I understand (not a whole lot yet), that's what the immediate="true" attribute does. There may be some extra code you need in the method that removes your components to get it to skip right to the redraw step without validating.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!