2011-06-09 52 views
7

我嘗試在一個頁面中使用JSF 2.0的多個表單。我使用PrimeFaces 3.0M1並嘗試使用製表符和每個製表符的一種形式構建應用程序。如何在JSF 2.0的一個頁面中使用多個表單?

我有一個頁面類似如下:

<html 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:fn="http://java.sun.com/jsp/jstl/functions" 
xmlns:p="http://primefaces.prime.com.tr/ui"> 

<div> 
<p:tabView> 
<p:tab title="Form1"> 
<h:form id="form1"> 
    <p:inputText id="txtInput" value="#{bean1.inputText}" /> 
    <p:commandButton title="Submit" value="Submit" actionListener="#{controller1.submitValues}"> 
</h:form> 
</p:tab> 
<p:tab title="Form2"> 
<h:form id="form2"> 
    <p:inputText id="txtInput2" value="#{bean2.inputText}" /> 
    <p:commandButton title="Submit" value="Submit" actionListener="#{controller2.submitValues}"> 
</h:form> 
</p:tab> 
</p:tabView> 
</div> 
</html> 

如果我點擊提交按鈕選項卡1,一切就像excpected。 但是,如果我點擊第二個選項卡上的按鈕,該命令將不會在控制器2中執行。

這裏有什麼問題?如果我將button2的執行命令綁定到button1,controller2中的命令就會正確執行,所以我可以排除後備bean中存在問題。

我該如何解決這個問題?

回答

1

Primefaces嚮導和tabview組件必須包含在一個表單中。

沒有理由不能在這樣的tabview或嚮導中有多個Submit按鈕。您對此的困惑很可能是因爲您擔心您的託管bean的其他屬性未顯示在當前查看選項卡中。

+0

如果我只有對整個嚮導一種形式,哪能每個單獨的形式在客戶端驗證所提交?例如,如果我要求字段,它將不會允許我繼續到下一個選項卡,因爲它全部在同一個表格中 – Erick 2015-09-08 21:09:43

1

我覺得你可以去指定的按鈕

試試這個的「過程」屬性。 更改<h:form>標籤,並與<h:panelGrid>替換它,並給予相應的ID爲Form1中窗口2和和改變這樣

<p:commandButton title="Submit" value="Submit" actionListener="#controller1.submitValues}" process="@this,form1"> 

<p:commandButton title="Submit" value="Submit" actionListener="#controller2.submitValues}" process="@this,form2"> 

這將工作中的2個按鈕。 :) 用你的結果更新我

+0

我在對話框中添加了dynamic =「true」,並保存在Dialog內部,它解析了問題。 – tom 2015-07-01 21:09:43

0

你可以創建一個項目列表,並用你想要在你的支持bean中瀏覽的值來填充它。把<h:form>標籤中<ui:repeat>標籤是這樣的:

<ui:repeat var="item" value="#{backingBean.items}"> 
    <h:form> 
    Put here the content of your form 
    </h:form> 
</ui:repeat> 
<p:commandButton value="Submit" action="desired action"/> 
相關問題