4

I would like to add PrimeFaces components like inputText, calendar etc dynamically from bean. I have tried in several possible ways, but I couldn't add PrimeFaces components dynamically from bean.

View:

<pe:dynaForm id="dynaForm" value="#{formGeneratorBean.model}" var="data">
    <pe:dynaFormControl type="input" for="txt">
        <p:inputText id="txt" value="#{data.value}" required="#{data.required}" />
        In place of p:inputText
    </pe:dynaFormControl>
</pe:dynaForm>

Model:

public FormGeneratorBean() {
    model = new DynaFormModel();
    DynaFormRow row = model.createRegularRow();
    DynaFormLabel label11 = row.addLabel("Author", 1, 1);
    DynaFormControl control12 = row.addControl(new BookProperty("Author",
    true), "input", 1, 1);
    label11.setForControl(control12);
}
asif md
  • 41
  • 3

1 Answers1

0

Add the type calendar to your View

<pe:dynaFormControl type="calendar" for="cal" styleClass="calendar">  
         <p:calendar id="cal" value="#{data.value}" showOn="button"/>  
</pe:dynaFormControl>

And your addControl method should set the type calendar, for example:

DynaFormControl control12 = row.addControl(new Field("Birth Date",
true), "calendar", 1, 1);

You can put pe:dynaFormControls for all the types you want, and they will only be shown if you add controls related to them.

cassiafn
  • 1
  • 3