2014-05-02 64 views
0

我知道嵌套是表單標籤的問題。但是,我的頁面沒有嵌套窗體。我有一個窗體(id =「menuForm」)來包圍p:菜單。接下來,我在頁面中放置一個表單(id =「locationForm」)。我檢查了輸出的html源代碼,並且沒有發生嵌套。JSF-Primefaces兩種形式干擾

我有一個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> 
+0

如果您註釋掉'',你的意思是我 – Mindwin

+0

?已經嘗試了刪除表單id = menuForm的不同組合,同時離開菜單 - 導致JSF關於缺少表單的錯誤。如果我將整個菜單和菜單一起刪除,那麼沒有問題。 – user3596751

回答