JSF-Primefaces两种形式的干扰

时间:2014-05-02 15:46:11

标签: jsf jsf-2 primefaces

我知道嵌套是表单标签的问题。但是,我的页面没有嵌套表单。我有一个表单(id =" menuForm")来包含p:菜单。接下来,我在页面下方有一个表单(id =" locationForm")。我已经检查了输出的html源代码,并且没有发生嵌套。

我有一个p:commandButton,我想用它来提交表单。它偶尔会起作用,但不是所有的时间。有时,该方法会触发,有时则不会触发。任何人都可以说出我做错了什么吗?

此外 - 如果我完全注释掉菜单表单,它将按预期工作。

感谢。

行动方法:

    public String insertLocationAction(){
    System.out.println("******* Method Fired.");
    DatabaseManager.insertLocation(newLocation);
    return "locations";
    }

XHTML页面:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://xmlns.jcp.org/jsf/html"
  xmlns:p="http://primefaces.org/ui"
  xmlns:f="http://xmlns.jcp.org/jsf/core"
  xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<f:view>
    <ui:debug rendered="#{facesContext.application.projectStage eq 'Development'}"/>
    <h:head />
    <p:messages />
    <p:layout fullPage="true">
        <p:layoutUnit position="west" size="260" header="Menu" resizable="false" closable="false">
        <h:form id="menuForm">
            <p:menu style="width: 240px;" >
                <p:submenu label="Locations" style="width: 240px;">
                    <p:menuitem value="All Locations" outcome="/pages/locations.xhtml" style="width: 240px;" />
                    <p:menuitem value="Create New" action="#{locationBackingBean.addLocationAction}" style="width: 240px;"  />
                </p:submenu>
                <p:submenu label="Queries" style="width: 240px;">
                    <p:menuitem value="Product Group Sales" outcome="/pages/productGroupSales.xhtml" style="width: 240px;" />
                    <p:menuitem value="Product Line Sales" outcome="/pages/productLineSales.xhtml" style="width: 240px;" />
                </p:submenu>
            </p:menu>
        </h:form>
    </p:layoutUnit>
    <p:layoutUnit position="center">
         <h:form id="locationform" enctype="multipart/form-data">
            <p:growl id="growl" showDetail="true" />
            <p:panelGrid columns="2">
                <f:facet name="header">Enter New Location Details</f:facet>
                        <h:outputLabel for="locationName" value="Location Name:" />           <p:inputText id="locationName" value="#{locationBackingBean.newLocation.locationName}" size="100" />
                        <h:outputLabel for="street1" value="Street Address1:" />    <p:inputText id="street1" value="#{locationBackingBean.newLocation.street1}" size="100"/>
                        <h:outputLabel for="street2" value="Street Address2:" /><p:inputText id="street2" value="#{locationBackingBean.newLocation.street2}" size="100"/>
                        <h:outputLabel for="city" value="City:" /><p:inputText id="city" value="#{locationBackingBean.newLocation.city}" size="40" />
                        <h:outputLabel for="state" value="State:" /><p:inputText id="state" value="#{locationBackingBean.newLocation.state}" size="2" />
                        <h:outputLabel for="country" value="Country:" /><p:inputText id="country" value="#{locationBackingBean.newLocation.country}" size="20" />
                        <h:outputLabel for="phone" value="Phone:" /><p:inputText id="phone" value="#{locationBackingBean.newLocation.phone}" size="15" />
                        <h:outputLabel for="locationType" value="Type:" /><p:inputText id="locationType" value="#{locationBackingBean.newLocation.locationType}" />
                </p:panelGrid>
                <p:commandButton action="#{locationBackingBean.insertLocationAction}"  ajax="false" value="Save" />
            </h:form>
        </p:layoutUnit>
    </p:layout>
</f:view>
</html>

1 个答案:

答案 0 :(得分:0)

请参阅:http://www.primefaces.org/docs/vdl/4.0/primefaces-p/commandButton.html

默认情况下,p:commandButton处理整个视图&#39;。

添加流程=&#34;:locationform&#34;对于commandButton可能只需要&#34; locationform&#34; (取决于您的选择器工作和嵌套的jsf组件等。