• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating component in backinbean

 
Kumar Gaurav
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Can anyone please provide input on how to create a component, say an inputtext from backingbean.

Please help me out and if possible provide some code also.
 
Tim Holloway
Bartender
Posts: 18417
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kito Mann has an example or 2 in his "JSF in Action" book.

The easiest way to do this is to bind the component's parent to a backing bean property, then use that property in a setParent operation for the component that you constructed.

For Input text, just invoke the no-argument bean constructor for an HtmlInputText object, then set the properties of the constructed component the same way you would for XML template declarations. EL items (such as the "value" attribute) are a little more complicated, but there are examples floating around on the web that were good enough for me.

CAUTION #1: You can't do the "setParent" operation in the backing bean's constructor, since the property set methods haven't yet been invoked to do the parent component's binding to the backing bean. A PostConstruct method can be used to do this, however.

CAUTION #2: Don't go overboard on this. When a GUI (web or otherwise) gets too dynamic, it confuses the users. So it's often better to simply enable/disable controls than to make them appear and disappear. That, in fact is a major gripe I have with MS Word 2003 - the "Print" menu would vanish on me.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!