wood burning stoves 2.0*
The moose likes JSF and the fly likes Framework evaluation: Does JSF support dynamic form? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Framework evaluation: Does JSF support dynamic form?" Watch "Framework evaluation: Does JSF support dynamic form?" New topic
Author

Framework evaluation: Does JSF support dynamic form?

Yk Ng
Greenhorn

Joined: Sep 24, 2010
Posts: 1
Hi,

I am evaluating Java-based frameworks for my new project, and one key project requirement is to support dynamic form. By that I mean at runtime the user will be able to create a form and define the fields on it (e.g. create a form with 3 textboxes and one dropdown menu), and the system will save the settings and generate the form dynamically.

In JSF, how can I implement something like that?

Thanks,
- YP
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15959
    
  19

Welcome to the JavaRanch, Yk!

Yes, you can dynamically create a View in JSF. I've done it in 2 different ways - one for a dynamic tree display and one for an entire form like what you're talking about.

The dynamic form app is a database editor webapp that I hope to make open-source someday. It constructs a page where you can view and update each field of a table row, after first selecting which table you want to edit.

What I did was build an anchor view with the static part of the page in it, then make a binding for the dynamic parts. On the other side (Managed Bean) of that binding I placed the code that constructed the dynamic elements and attached them to the binding point.

All of the standard JSF elements are instantiable classes with default no-argument constructors, so it's very easy to construct one, set its properties, then attach it to the proper point in the UI View tree.


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

Joined: Jun 08, 2011
Posts: 6
Hi,

Can someone explain how exactly we will be able to attach the elements to the proper point in the UIView tree?

How can we get the reference to the UIView?

Thanks very much.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15959
    
  19

We generally recommend not re-opening old topics (we don't charge extra for you to create a message thread of your own! ), but, since it's open now, here's your answer:

Use the "binding" attribute on a container element. Backing bean code can also just get the UIViewRoot from the FacesContext and run down it manually, but it's usually simpler to provide a more direct link to the part of the view you want to customize.
Thileepa Asokan
Greenhorn

Joined: Jun 08, 2011
Posts: 6
Thanks, Tim. I will remember to create a new thread next time.

I have another question.

When I get the UIViewRoot from the FacesContext and run down it manually, will I also be able to add new UIComponents so that the view rendered next time has new UIComponents?

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15959
    
  19

Thileepa Asokan wrote:
When I get the UIViewRoot from the FacesContext and run down it manually, will I also be able to add new UIComponents so that the view rendered next time has new UIComponents?



Yup. I have an app that does that. It's rather specialized. Mostly I use static View definitions, though. Less trouble, more maintainable and I can (theoretically) dump the UI work off onto a non-programmer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Framework evaluation: Does JSF support dynamic form?
 
Similar Threads
Required Java Server Faces 2 Tutorials with SpringSourceToolSuite 2.7
JSF and Javascript why id elements have a strange names
setting up different modules in the RAD
Question: Which of both JSF or JSP is betterfor to build my own CMS?
proper faces plugin