1) this is the only way i know of
2) As i was answered about a similar question i had months ago
"because application does much more than just instanciating the
component with default constructor. The application need to handle the
lifecycle of the component"

Also, am pretty sure you can also answer "because it's stated so in the
JSF specs" but am not 100% sure :)

Anyway, go with applicaion.createComponent and you are safe :)
Leyzerzon, Simeon a écrit :
> Could you please elaborate on why this is a preferred (or the only right) way 
> of creating a component dynamically?
> Simeon 
>
> -----Original Message-----
> From: David Delbecq [mailto:[EMAIL PROTECTED] 
> Sent: Monday, December 04, 2006 9:11 AM
> To: MyFaces Discussion
> Subject: Re: Newbie question: How to generate a jsf component dynamically
>
> Those calls (and other components you may create) are wrong:
>        HtmlPanelGrid grid = new HtmlPanelGrid ();
>        HtmlCommandLink link = new HtmlCommandLink ();
>
> To create component, use the 
> FacesContext.getApplication().createComponent(componentType) call.
>
> example:
>
> import javax.faces.context.FacesContext; import 
> javax.faces.component.html.HtmlCommandLink;
> ....
> HtmlCommandLink commandLink =
> (HtmlCommandLink)context.getApplication().createComponent(HtmlCommandLink.COMPONENT_TYPE);
>
> koshi a écrit :
>   
>> Hi, first of all, thanks for all your post and ideas, i'm grateful for 
>> your support.
>>
>> i decided to solve my problem this way
>>
>> in the view: 
>>   <h:panelGrid binding="#{managedBean.panelGrid}" />
>>
>> the managed bean:
>> public HtmlPanelGrid getPanelGrid ()
>> {
>>       HtmlPanelGrid grid = new HtmlPanelGrid ();
>>       ....
>>
>>       for (Actions action : actions) {
>>       
>>             if (action.getType () == ActionTypes.COMMAND_LINK) {
>>                     HtmlCommandLink link = new HtmlCommandLink ();
>>                     link.setId (action.getId ());
>>                     link.setTitle (action.getTitle ());
>>  
>>                     HtmlOutputText text = new HtmlOutputText ();
>>                     text.setValue (MessagesUtil.getMessage ("actions", 
>> action.getTitle (), null));
>>         
>>                     link.getChildren ().add (text);
>>         
>>                     MethodBinding method = 
>> FacesContext.getCurrentInstance ().getApplication ().
>>                                     createMethodBinding 
>> (action.getValue (), null);
>>                     link.setAction (method);
>>                     grid.getChildren ().add (link);
>>             }
>>       }
>>       return grid;
>> }
>>
>> but the commandLink doesn't work, and i have no idea of what is happening.
>>
>> if i put a commandLink into the panelGrid manually, then the 
>> commandLink works fine.
>>
>> <h:panelGrid id="id" binding="#{managedBean.panelGrid}">
>>        <h:commandLink id = "asd"  action="#{managedBean.action}">
>>             <h:outputText value="action name" />
>>        </h:commandLink>
>> </h:panelGrid>
>>
>> Thanks
>>   
>>     
>
>
> ==============================================================================
> Please access the attached hyperlink for an important electronic 
> communications disclaimer: 
>
> http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
> ==============================================================================
>
>
>   

Reply via email to