• Settings
    • Locale
    • Change the locale of the datepicker, schedule and client side validation messages.

      Language
      English
      English
      English
      French
      German
      German
      German
      Italian
      Korean
      Spanish
      Catalan
      Dutch
      Portuguese
      Portuguese
      Arabic
      Arabic
      Bulgarian
      Bangla
      Bosnian
      Czech
      Greek
      Estonian
      Persian
      Finnish
      Danish
      Hindi
      Indonesian
      Icelandic
      Croatian
      Japanese
      Hungarian
      Hebrew
      Georgian
      Central Kurdish
      Khmer
      Kyrgyz
      Kazakh
      Lithuanian
      Latvian
      Malay
      Norwegian
      Polish
      Romanian
      Russian
      Slovak
      Slovenian
      Serbian
      Serbian
      Swedish
      Thai
      Turkish
      Ukrainian
      Uzbek
      Vietnamese
      Chinese
      Chinese
  • Resources

DynaForm Basic

DynaForm builds a dynamic form with labels, inputs, selects and any other elements from a model, for forms that are described at runtime (for example in a database or an XML file). It adds an expandable extended view area, open / close state saving, an autoSubmit feature, a client-side widget API and various facets.

DynaForm Tag Documentation

DynaForm is a dynamic form component that renders based on a DynaFormModel.

NameTypeRequiredDefaultDescription
id String false generated Unique identifier of the component in a namingContainer.
rendered boolean false true Boolean value to specify the rendering of the component, when set to false component will not be rendered.
binding UIComponent false generated An EL expression referring to a server side UIComponent instance in a backing bean.
widgetVar String false generated ('widget_' + componentClientId) Name of the client side widget.
autoSubmit boolean false false When true, form is submitted automatically on change.
buttonBarPosition String false bottom Position of the button bar: 'top', 'bottom', or 'both'.
columnClasses String false Comma-separated CSS classes for label and control columns.
openExtended boolean false false When true, extended rows are shown by default.
style String false Inline style of the component.
styleClass String false Style class of the component.
value Object true The dynamic data model (e.g. DynaFormModel).
var String false Name of the request-scoped variable that exposes the current row/control data.
varContainerId String false Name of the request-scoped variable that exposes the current container client id.

DynaFormControl Tag Documentation

Defines a control template for a DynaFormControl type; used as a child of DynaForm.

NameTypeRequiredDefaultDescription
id String false generated Unique identifier of the component in a namingContainer.
rendered boolean false true Boolean value to specify the rendering of the component, when set to false component will not be rendered.
binding UIComponent false generated An EL expression referring to a server side UIComponent instance in a backing bean.
for String false Search expression for the input component this control wraps (for label 'for' and validation).
style String false Inline style of the component.
styleClass String false Style class of the component.
type String false default Control type identifier; must match a DynaFormControl type in the model.
Tag Documentation Widget Source Basic Features Controls
Basic usage

Build a simple dynamic form: create a DynaFormModel, add rows with createRegularRow(), add labels with addLabel(...) and controls with addControl(data, type, ...), and link them with label.setForControl(control). The child tag pe:dynaFormControl matches the Java controls by its type attribute (usually one to many). Labels are rendered automatically, no p:outputLabel is needed.

Utilization of nested model

A nested model is like a table contained in a cell, which is useful when a control is a combination of several pe:dynaFormControl. The XHTML stays the same, only the Java model changes: create a second DynaFormModel, fill it as usual and add it with nestedRow.addModel(data, type, ...).

Search area

Background

Normally a form can be built straightforwardly with h:panelGrid or p:panelGrid if the count of rows / columns and the positions of elements are known. That is not possible if a form is described dynamically at runtime. DynaForm builds such a form from a Java model without limitations.

Supported facets: headerRegular, footerRegular, headerExtended, footerExtended and buttonBar.

Usage


<style>
    .dynaform-basic .pe-dynaform-cell input,
    .dynaform-basic .pe-dynaform-cell textarea,
    .dynaform-basic .pe-dynaform-cell[colspan="1"] input,
    .dynaform-basic .pe-dynaform-cell[colspan="1"] textarea {
        width: 150px;
    }

    .dynaform-basic .pe-dynaform-cell.calendar input,
    .dynaform-basic .pe-dynaform-cell[colspan="1"].calendar input {
        width: 120px;
    }

    .dynaform-basic .pe-dynaform-cell .p-selectonemenu {
        width: 134px;
    }

    .dynaform-basic .label-container {
        font-weight: bold;
    }

    .dynaform-basic .field-container input {
        text-transform: uppercase;
    }

    .dynaform-nested .pe-dynaform-cell .p-datepicker input {
        width: 100px;
    }

    .dynaform-nested .pe-dynaform-headerfacet div {
        border: 1px dotted #808080;
        padding: 10px;
        text-align: center;
    }

    .dynaform-nested .pe-dynaform-label {
        text-align: left;
        padding: 2px 20px 0 0;
    }
</style>

<div class="card dynaform-basic">
    <h5>Basic usage</h5>
    <p>Build a simple dynamic form: create a <code>DynaFormModel</code>, add rows with <code>createRegularRow()</code>, add labels with <code>addLabel(...)</code> and controls with <code>addControl(data, type, ...)</code>, and link them with <code>label.setForControl(control)</code>.
        The child tag <code>pe:dynaFormControl</code> matches the Java controls by its <code>type</code> attribute (usually one to many). Labels are rendered automatically, no <code>p:outputLabel</code> is needed.</p>
    <h:form id="formBasicUsage">
        <h:panelGroup id="dynaFormGroup">
            <p:messages id="messages" showSummary="true"/>

            <pe:dynaForm id="dynaForm" value="#{dynaFormController.model}" var="data" columnClasses="label-container, field-container">
                <pe:dynaFormControl type="input" for="txt">
                    <p:inputText id="txt" value="#{data.value}" required="#{data.required}"/>
                </pe:dynaFormControl>
                <pe:dynaFormControl type="calendar" for="cal" styleClass="calendar">
                    <p:datePicker id="cal" value="#{data.value}" required="#{data.required}" showIcon="true"/>
                </pe:dynaFormControl>
                <pe:dynaFormControl type="select" for="sel">
                    <p:selectOneMenu id="sel" value="#{data.value}" required="#{data.required}">
                        <f:selectItems value="#{dynaFormController.languages}"/>
                    </p:selectOneMenu>
                </pe:dynaFormControl>
                <pe:dynaFormControl type="textarea" for="tarea">
                    <p:inputTextarea id="tarea" value="#{data.value}" required="#{data.required}" autoResize="false"/>
                </pe:dynaFormControl>
                <pe:dynaFormControl type="rating" for="rat">
                    <p:rating id="rat" value="#{data.value}" required="#{data.required}"/>
                </pe:dynaFormControl>

                <f:facet name="buttonBar">
                    <p:commandButton value="Submit" action="#{dynaFormController.submitForm}"
                                     process="dynaForm" update=":formBasicUsage:dynaFormGroup :formBasicUsage:inputValues"
                                     oncomplete="handleCompleteBasicUsage(xhr, status, args)"/>
                    <p:commandButton type="reset" value="Reset" style="margin-left: 5px;"/>
                </f:facet>
            </pe:dynaForm>
        </h:panelGroup>

        <p:dialog header="Input values" widgetVar="inputValuesBasicUsage">
            <p:dataList id="inputValues" value="#{dynaFormController.bookProperties}" var="bookProperty"
                        style="margin:10px;">
                <h:outputText value="#{bookProperty.name}: #{bookProperty.formattedValue}"
                              style="margin-right: 10px;"/>
            </p:dataList>
        </p:dialog>
    </h:form>

    <script>
        /* <![CDATA[ */
        function handleCompleteBasicUsage(xhr, status, args) {
            if (args && args.isValid) {
                PF('inputValuesBasicUsage').show();
            } else {
                PF('inputValuesBasicUsage').hide();
            }
        }
        /* ]]> */
    </script>
</div>

<div class="card dynaform-nested">
    <h5>Utilization of nested model</h5>
    <p>A nested model is like a table contained in a cell, which is useful when a control is a combination of several <code>pe:dynaFormControl</code>. The XHTML stays the same, only the Java model changes: create a second <code>DynaFormModel</code>, fill it as usual and add it with <code>nestedRow.addModel(data, type, ...)</code>.</p>
    <h:form id="formNestedModel">
        <h:panelGroup id="dynaFormGroup">
            <p:messages id="messages" showSummary="true"/>

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

                <pe:dynaFormControl type="date" for="cal" styleClass="calendar">
                    <p:datePicker id="cal" value="#{data.value}" required="#{data.required}" showIcon="true"/>
                </pe:dynaFormControl>

                <f:facet name="headerRegular">
                    <div><h:outputText value="Search area"/></div>
                </f:facet>

                <f:facet name="buttonBar">
                    <p:commandButton value="Submit" action="#{nestedDynaFormController.submitForm}"
                                     process="dynaForm" update=":formNestedModel:dynaFormGroup :formNestedModel:inputValues"
                                     oncomplete="handleCompleteNestedModel(xhr, status, args)"/>
                    <p:commandButton type="reset" value="Reset" style="margin-left: 5px;"/>
                </f:facet>
            </pe:dynaForm>
        </h:panelGroup>

        <p:dialog header="Input values" widgetVar="inputValuesNestedModel">
            <p:dataList id="inputValues" value="#{nestedDynaFormController.bookProperties}" var="bookProperty"
                        style="margin:10px;">
                <h:outputText value="#{bookProperty.name}: #{bookProperty.formattedValue}"
                              style="margin-right: 10px;"/>
            </p:dataList>
        </p:dialog>
    </h:form>

    <script>
        /* <![CDATA[ */
        function handleCompleteNestedModel(xhr, status, args) {
            if (args && args.isValid) {
                PF('inputValuesNestedModel').show();
            } else {
                PF('inputValuesNestedModel').hide();
            }
        }
        /* ]]> */
    </script>
</div>