1

I'm creating a page to build forms and I'm using PrimeFaces component's dashboard to store and order the fields of the form. The problem is: When I try to add a new form field, by sending two input values to the Bean, the get method of dashboard is called before the set method os inputs, so I can't add the input values to dashboard.

Form.xhtml:

<h:form id="dashboardForm">
  <h:panelGrid columns="4" cellpadding="5">
    <p:outputLabel for="formName" value="Form Name"></p:outputLabel>
    <p:inputText id="formName" placeholder="Exemple Form"></p:inputText>
  </h:panelGrid>        
  <hr></hr>
  <p:layout>
    <p:layoutUnit position="west" minSize="150">
      <p:panel header="Add Field">
        <h:panelGrid columns="2" cellpadding="5" id="newField">
          <p:outputLabel for="newFieldName" value="Question"></p:outputLabel>
          <p:inputTextarea  id="newFieldName" value="#{monitoringFormDashboard.newFieldName}"></p:inputTextarea>

          <p:outputLabel for="newFieldType" value="Type"></p:outputLabel>
          <p:selectOneMenu immediate="true" id="newFieldType" value="#{monitoringFormDashboard.newFieldType}">
          <f:selectItem itemLabel="Text" itemValue="0"></f:selectItem>
          <f:selectItem itemLabel="Dropdown" itemValue="1"></f:selectItem>
          <f:selectItem itemLabel="Boolean" itemValue="2"></f:selectItem>
          </p:selectOneMenu>

        </h:panelGrid>
        <p:commandButton id="addNewField" value="Add" actionListener="#{monitoringFormDashboard.addField}" update="dashboard" image="ui-icon ui-icon-carat-1-e" />
      </p:panel>
    </p:layoutUnit>
    <p:layoutUnit position="center">
      <p:dashboard id="dashboard" binding="#{monitoringFormDashboard.dashboard}">        
      </p:dashboard>
    </p:layoutUnit>
  </p:layout>        
</h:form>

When I press the Add commandButton, the method execution order on bean is:

  1. getDashboard
  2. setDashboard
  3. getNewFieldName
  4. getNewFieldType
  5. setNewFieldName
  6. setNewFieldType
  7. addField

So this is exactly the inverse order of what I need. I need first the newFieldName and newFieldName and later call addField and at least getDashboard...

Here is the bean class if needed: http://pastebin.com/fcCnAYNZ

What is it that I'm missing?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Afonso Lage
  • 281
  • 5
  • 18

1 Answers1

0

I've found the problem. It's related to the binding, as I read from another great @BalusC answer:

How biding attribute in jsf works

After removing binding and using another approach, it worked like a charm.

Community
  • 1
  • 1
Afonso Lage
  • 281
  • 5
  • 18