aspose file tools
The moose likes JSF and the fly likes Dynamic Forms Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Dynamic Forms" Watch "Dynamic Forms" New topic
Author

Dynamic Forms

Daniel Prene
Ranch Hand

Joined: Jul 15, 2005
Posts: 241
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

Joined: Jul 11, 2001
Posts: 15230

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

Joined: Jul 15, 2005
Posts: 241
Would this generate ugly white space? Is there a way of using placeholders or somthing?
Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

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

Joined: Jul 15, 2005
Posts: 241
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

Joined: Jul 11, 2001
Posts: 15230

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

Joined: Jul 15, 2005
Posts: 241
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

Joined: Aug 05, 2005
Posts: 1
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

Joined: Jan 28, 2002
Posts: 214
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamic Forms
 
Similar Threads
Hidden Field in JSP
Tomcat shutdown
Using JavaScript to communicate with Applets
Need help for AJAX with struts2.0
Hidden Field in JSP