Michael Edgar
Michael Edgar

Reputation: 420

Is it possible to implement a dynamic tree of components in JSF?

I am attempting to construct a component tree in JSF 1.2 (Mojarra) where the tree consists of multiple types of junction and leaf nodes. Each leaf node needs to render in a unique way and needs to be posted-back with potential changes. The purpose is to allow the user to update processing logic where each leaf node represents an operation, such as "value equals" or "value not equal".

For example:

Root
|
+- InternalNode1 (type I_A)
|  |
|  +- LeafNode1 (type L_A)
|  |
|  +- LeafNode2 (type L_B)
|
+- InternalNode2 (type I_B)
   |
   +- LeafNode3 (type L_B)
   |
   +- LeafNode4 (type L_A)

Each type of leaf node needs to render differently, depending on the needs of that node type. Additionally, the tree will be modifiable and nodes can be added or removed with Javascript and updates posted back to the server, etc. For example, in the above tree, LeafNode4 could be removed, or its type changed to L_B.

Is this even possible with JSF components? Am I going about it the wrong way by attempting to use polymorphic UI components?

Upvotes: 4

Views: 2038

Answers (2)

McDowell
McDowell

Reputation: 108899

It is possible to build a component tree programmatically, but this would be the wrong approach for your use-case. It would generally be unsecure to allow the user-agent to manipulate such server-side code.

It would be better to use a model to manage your tree structure (which is essentially the approach Don Roby is suggesting.) The data that makes up this model can then be validated like any other user input to ensure attackers aren't trying to put server-side data into an invalid state.

JSF's declarative approach makes it challenging to do this out of the box (you can see a crude tree rendering example here.) If you don't want to drag in a 3rd party library (or write your own control) you may be better off handling all the tree UI in JavaScript and using a JSF hidden field to transport it to/from the server.

Upvotes: 1

Don Roby
Don Roby

Reputation: 41137

You might want to look at <rich:tree>.

Upvotes: 2

Related Questions