2012-01-23 28 views
3

我有一個CommandButton(PrimeFaces 3.0.1),它不在Form-Tag中。有沒有一種方法可以通過它的Id或某些內容來引用表單,以便Button可以發佈表單,即使它不是該表單的子元素? 我did'nt發現在規格任何apropriate ...CommandButton在表單之外:是否可以通過ID發佈表單?

的巴頓目前看起來是這樣的:

<p:commandButton value="#{messages['000.label.ok']}" 
     oncomplete="w00001.hide()" type="submit" 
       action="cancel" 
     ajax="false" immediate="true" /> 

按下按鈕JSF轉發到另一個頁面後,由按鍵映射「取消」。

謝謝!

+0

可能重複的[從命令按鈕調用另一個窗體](http://stackoverflow.com/questions/11766255/call-another-form-from- (命令按鈕) – Kukeltje

回答

1

edit1 所以你想要做的是提交一個表單,然後重定向。如前所述,commandButton必須位於表單的內部,如果您想用它來提交,但它不一定是相同的表單。你可以圍繞commandButton包裝第二個表單,並且仍然使用它來提交第一個表單的值。

 <h:form id="form_test"> 
      <!-- values of this form will be submitted --> 
     </h:form> 
     <h:form> 
      <p:commandButton value="cancel" action="#{yourBean.cancelFlow}" 
       process="form_test @this" ajax="false" /> 
     </h:form> 

YourBean.java方法看起來是這樣的(假設你的cancelpage.xhtml在包your.package

public String cancelFlow() { 
    // do something with form data 

    return "/your/package/cancelpage?faces-redirect=true"; 
} 

你也可以重定向程序,使用FacesContext.getCurrentInstance().getExternalContext().redirect

+0

不幸的是,我認爲,這不是我需要的原因...我需要一個提交 – treeno

+0

這確實提交了第一個表單(輸入類型的commandButton默認爲「submit」)。也許我誤解了你想要的東西,你能發佈你的源代碼嗎? –

+0

我編輯了問題描述。我需要一種方法將這個「取消」--token發送到服務器,以便JSF可以將我重定向到另一個頁面 – treeno

相關問題