簡體   English   中英

JSF通過commandButton重定向

[英]JSF redirect via commandButton

如果代碼是這樣的話,我無法重定向到另一個頁面:

<h:commandButton type="button" value="Enter" action="index?faces-redirect=true" >

但是,如果代碼是:

<h:commandButton type="button" value="Enter" action="index?faces-redirect=true" >
    <f:ajax />
</h:commandButton>

有人能解釋一下嗎? 謝謝!

- - - - - - - - - - - -編輯 - - - - - - - - - - - -

整個xhtml代碼供您參考:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
<h:head>

</h:head>

<h:body>
<h:form id="form">
    <h:commandButton id="enterModelButton" type="button" value="Enter" action="index?faces-redirect=true" >
        <f:ajax />
    </h:commandButton>
</h:form>
</h:body>
</html>

<h:commandButton type="button">不生成提交按鈕。 它只是生成一個沒有任何效果的“死”按鈕,純粹用於自定義onclick="..."腳本等。 這有點像黑暗的JSF 1.0 / 1.1時代的遺留問題,因為在JSF中使用普通的vanilla HTML這種事情是不可能的。

<f:ajax>通過JSF生成的onclick執行ajax powers提交。 它不關心按鈕的type

基本上,刪除type="button"並依賴其默認type="submit"應該可以解決您的問題。

<h:commandButton value="Enter" action="index?faces-redirect=true" />

但是,總而言之,如果這是真正的代碼並且您實際上並不打算調用bean操作,那么您將完全朝着錯誤的方向前進,以實現通過按鈕導航到不同頁面的功能要求。 你應該使用<h:button>代替。

<h:button value="Enter" outcome="index" />

也可以看看:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM