首页 > 解决方案 > 在表单上提交表单数据为空 Jsf Primefaces

问题描述

我在提交表单时遇到问题,第一件事是没有 @this 我的 <p:commandButton> 没有调用我的 Managedbean。
当我添加 @this 时,它使用空表单数据调用我的托管 bean。
我无法弄清楚我在这里缺少什么。结构是
employee.xhtml:

   <ui:composition template="employee/employeeTemplate.xhtml"
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:p="http://primefaces.org/ui"> 
        <ui:define name="mainContent">
            <ui:include src="employee/employeeEditForm.xhtml"></ui:include>
        </ui:define>
    </ui:composition>

我的employeeTemplate.xhtml是:

   <ui:composition template="../../templates/sidebarLayout.xhtml"
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui" 
        xmlns:ui="http://java.sun.com/jsf/facelets">
        <ui:define name="sidebarContent">
            <p:panel styleClass="panelContainer">
                <p:panel styleClass="panelHeader"
                    header="#{o:translate('Employee List')}"></p:panel>
                <p:panel styleClass="panelSpacing">
                    <h:form id="employeeListForm">
                        <ui:include src="employeeList.xhtml">
                        </ui:include>
                        <ui:include src="addNewEmployee.xhtml">
                        </ui:include>
                    </h:form>
                </p:panel>
            </p:panel>
        </ui:define>
    </ui:composition>

我的对话框在addNewEmployee.xhtml

    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui"
        xmlns:fn="http://java.sun.com/jsp/jstl/functions"
        xmlns:ui="http://java.sun.com/jsf/facelets">
                <p:commandButton id="addEmployeeBtn" 
                             value="#{o:translate('Add New Employee')}"
                             styleClass="btnAction" 
                             style="float: right;" 
                             oncomplete="PF('dlgExample').show();">                 
                </p:commandButton>
        <p:dialog id="dlgExample"
                header="#{o:translate('Dlg Example')}"
                widgetVar="dlgExample" dynamic="true" width="750" height="600" appendTo="@(body)">
                <h:form id="dlgExampleForm">
                            <p:outputLabel for="val1"
                                value="#{o:translate('Employee Type')}:" />
                            <p:selectOneMenu value="#{myManagedBean.selectedEmp.type}" id="val1">
                                        <f:selectItems value="#{myManagedBean.employeeTypes}" />
                                    </p:selectOneMenu>
                            <p:commandButton id="cancelButton"
                                value="#{o:translate('Cancel')}" update=":mainContent,:msgs"
                                oncomplete="PF('dlgExample').hide();" />
                            <p:commandButton style="float: right;"
                                styleClass="pull_right btnAction"
                                actionListener="#{myManagedBean.saveEmployee}"
                                value="#{o:translate('Save')}" process="@this"
                                update=":mainPage,:msgs" >
                                <p:confirm header="Confirmation" message="Are you sure you want to Save?" 
                                icon="ui-icon-alert" /> 
                                </p:commandButton>
                </h:form>
            </p:dialog>
</ui:composition>

任何帮助将不胜感激。

标签: jsfprimefaces

解决方案


推荐阅读