Add PrimeFaces components to pe: dynaform from bean

I would like to add PrimeFaces components such as inputText, calendaretc. dynamically from a bean. I tried in several ways, but I could not dynamically add PrimeFaces components from the 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);
}
+4
source share
1 answer

Add type calendar to view

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

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 appear if you add the controls associated with them.

0
source

Source: https://habr.com/ru/post/1616546/


All Articles