在primefaces中使用默认值设置表单中的值

时间:2015-08-03 10:09:08

标签: primefaces

我正在使用Primefaces 5.1,我有一个表格中有值为#{circuitController.newCircuit.project}的列。

对于本专栏,我想设置#{projectController.selectedProject}的默认值,而不要求用户写文本。

我该怎么做?

<h:form id="newUserForm">
				
  <p:panelGrid id="displayNewUser" columns="2" cellpadding="4"
	style="margin:0 auto;">
	<f:facet name="header">
     selected project : #{projectController.selectedProject.designation}
    </f:facet>
	<h:outputText value="Designation :" styleClass="title-text" />
	<p:inputText id="newCircuitDesignation"
	  value="#{circuitController.newCircuit.designation}" required="true" />
						
	<h:outputText value="Description :" styleClass="title-text" />
	<p:inputText id="newCircuitDescription"
	  value="#{circuitController.newCircuit.description}" required="true" />
						
					
	<h:outputText value="Start date :"
	  styleClass="title-text" />
	<p:calendar id="newCircuitend"
	  value="#{circuitController.newCircuit.date_deb}"
		enableManualInput="true" />

	<h:outputText value="End Date:" styleClass="title-text" />
	<p:calendar id="newCircuitstart"
	  value="#{circuitController.newCircuit.date_fin}"
	  enableManualInput="true" />
		
	<h:outputText value="Circuit designer:" />
	<p:selectOneMenu  id="user" required="true" effect="fold"
	  editable="true" value="#{circuitController.newCircuit.user}"  var="user"
	  itemValue="#{user}" 
   		  converter="project.management.converter.UserConverter">
	  <f:attribute name="collectionType" value="java.util.ArrayList" />
	  <f:selectItems value="#{designersSelectItems.values}" />

 	  <p:column>
	    <h:outputText value="#{user.identity}" rendered="true"
          styleClass="data-text" />
	  </p:column>
	</p:selectOneMenu>
						
	<h:outputText value="project :" />
	<p:inputText id="newCircuitpro"
	  value="#{circuitController.newCircuit.project}" var="project" converter="project.management.converter.ProjectConverter"/>

	<f:facet name="footer">
	<p:commandButton value="Submit" update=":form1:circuit1, :growl"
	  oncomplete=" handleSubmitRequest(xhr, status, args, 'newUserDlg','newUserForm');"
	  actionListener="#{circuitController.addCircuit()}" icon="ui-save" />
	  <p:commandButton type="reset" value="Reset" icon="ui-reset">
      </p:commandButton>
	  </f:facet>
	</p:panelGrid>
</h:form>

1 个答案:

答案 0 :(得分:0)

您可以使用@PostConstruct方法在渲染视图之前设置值。

public class CircuitController {
    @ManagedProperty(value="#{projectController}")
    private ProjectController projectController;

    /* Getter and setter for projectController */
    /* And other properties of CircuitController */

    @PostConstruct
    public void init() {
        newCircuit.setProject(projectController.getSelectedProject());
    }

}