• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Framework evaluation: Does JSF support dynamic form?

 
Yk Ng
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Thileepa Asokan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic