You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Michael Heinen <mh...@recommind.com> on 2007/07/03 10:48:45 UTC

how to render various components dynamically for a generic editor ?

Hi,

 

I have to create a generic editor with various fields based on a
configuration(file, database ...). Each field can be rendered as a
different input type, e.g. selectOneCheckbox, selectManyCheckbox,
selectOneRadio, selectOneMenu, selectManyMenu or even inside a tree2
structure. Moreover I have to add validators and converters to the
components, e.g. for numeric input, dates etc.

 

I am currently no sure what's the best approach for this and I would be
happy about some feedback.

I am sure that some of you have to implement these type of requirements
and therefore I look forward to your recommendations and experiences.

 

I see the following alternatives:

a) loop over the fields in the jsp (with a datalist) and define all the
possible types of components.

   Then the rendered attribute could be used to show/hide them based on
the configuration.

   --> seems not very performant

   --> no idea how to add converters and validators because they don't
offer a rendered attribute

   

b) create the UIComponents and the component tree on serverside and use
component bindings

  --> complicates the maintenance from my point of view. because
styleclasses, js-eventhandlers etc must be set in java.

 

c) use some kind of dynamic includes ?

  --> ??

 

d) ???

 

Michael


Re: how to render various components dynamically for a generic editor ?

Posted by David Delbecq <de...@oma.be>.
Hi,

I had a similar requirement for a form here.
I had an List of object to visually edit. The objects were carrying
their description, value and type. I created, for each type, a wrapper
bean that provided a method UIComponent createEditor(some environment
stuff); I then created a custom component (let's name
<custom:genericEditor value="<wrapped object to edit>"),  that has
responsability to
1) setup, for it's children, an accessible request scoped variable that
refered to objet to edit
2) create a tomahawk subform (some very complex editors needed to do
partial submit)
3) act as NamingContainer
4) dynamically populate the subform's children list upon first need
using the createEditor()

En l'instant précis du 03/07/07 10:48, Michael Heinen s'exprimait en ces
termes:
>
> Hi,
>
>  
>
> I have to create a generic editor with various fields based on a
> configuration(file, database …). Each field can be rendered as a
> different input type, e.g. selectOneCheckbox, selectManyCheckbox,
> selectOneRadio, selectOneMenu, selectManyMenu or even inside a tree2
> structure. Moreover I have to add validators and converters to the
> components, e.g. for numeric input, dates etc.
>
>  
>
> I am currently no sure what's the best approach for this and I would
> be happy about some feedback.
>
> I am sure that some of you have to implement these type of
> requirements and therefore I look forward to your recommendations and
> experiences.
>
>  
>
> I see the following alternatives:
>
> a) loop over the fields in the jsp (with a datalist) and define all
> the possible types of components.
>
>    Then the rendered attribute could be used to show/hide them based
> on the configuration.
>
>    --> seems not very performant
>
>    --> no idea how to add converters and validators because they don't
> offer a rendered attribute
>
>   
>
> b) create the UIComponents and the component tree on serverside and
> use component bindings
>
>   --> complicates the maintenance from my point of view. because
> styleclasses, js-eventhandlers etc must be set in java.
>
>  
>
> c) use some kind of dynamic includes ?
>
>   --> ??
>
>  
>
> d) ???
>
>  
>
> Michael
>


Re: how to render various components dynamically for a generic editor ?

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi!
>
> I have to create a generic editor with various fields based on a
> configuration(file, database …). Each field can be rendered as a
> different input type, e.g. selectOneCheckbox, selectManyCheckbox,
> selectOneRadio, selectOneMenu, selectManyMenu or even inside a tree2
> structure. Moreover I have to add validators and converters to the
> components, e.g. for numeric input, dates etc.
>
You can have a look at the dynaForm component in MyFaces Orchestra which
already do something like that based on a JPA annotated bean.
You can easily create a new "extractor" based on e.g. the metadata of
your database.

It's not very well documented, but a very simple example can be found in
the MyFaces Orchestra Examples package.

Ciao,
Mario