9

index.xhtml から registerFirstTime.xhtml にリダイレクトしようとしています。

ページ index.xhtml のコードは次のとおりです。

<h:form id="content" style="margin-top: 1em;">
    <p:panel id="panel" header="LOGIN">
        <p:messages id="msgs" globalOnly="true"/>
        <h:panelGrid columns="3">
            <h:outputLabel value="e-mail" />
            <p:inputText id="name" required="true" value="#{UserBean.email}"
                requiredMessage="Required: e-mail" display="icon">
            </p:inputText>
            <p:message id="msgName" for="name"/>
            <h:outputLabel value="Password" />
            <p:password id="password" required="true" value="#{UserBean.password}"
                requiredMessage="Required: Password" display="icon" feedback="false">
            </p:password>
            <p:message id="msgPassword" for="password"/>
        </h:panelGrid>
        <h:panelGrid columns="2">
            <p:commandButton value="Login" actionListener="#{UserBean.validate}" update="msgNombre, msgPassword, msgs"/>
            <h:commandButton value="Register for the first time" action="register"/>
        </h:panelGrid>
    </p:panel>
</h:form>

一方、faces-config.xml のリダイレクトの内容は次のとおりです。

<navigation-rule>
    <from-view-id>index.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>register</from-outcome>
        <to-view-id>registerFirstTime.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

入力した名前とパスワードが入力されるまで、リダイレクトを行うことはできません。必須フィールドを考慮せずにレコードのリダイレクトを行うにはどうすればよいですか? ありがとう!=)

4

2 に答える 2

30

属性immediate="true"を持たないすべての入力フィールドの処理をスキップするコマンド ボタンに追加します。immediate="true"

<h:commandButton value="Register for the first time" action="register" immediate="true" />

具体的な問題とは関係ありませんが、技術的にはここでリダイレクトを送信していないことに注意してください。これは基本的に転送を送信します。つまり、ブラウザのアドレス バーの URL はログイン ページの URL のままです。<redirect/>に追加する必要があり<navigation-case>ます。また、ナビゲーション ケースは JSF 1.x の残り物であることに注意してください。JSF 2.x 以降では、ビュー ID を結果として指定するだけで「暗黙のナビゲーション」を実行できます。

<h:commandButton value="Register for the first time" action="registerFirstTime?faces-redirect=true" immediate="true" />

このようにして、ナビゲーション ケースを完全に取り除くことができます。

于 2012-06-28T12:35:04.507 に答える
7

@BalusC ソリューションは、いつものようにうまくいくはずです。しかし、Primefaces を使用しているように見えるので、いくつか指摘したいと思います。どちらも質問とは関係ありませんが、ある時点で役立つかもしれません。

まず、暗黙的なナビゲーション (JSF2 で導入) を使用できます。そうすれば、faces-config.xml ファイルですべてのナビゲーション ルールを定義する必要がなくなります (私は古い JSF 1.2 プロジェクトに取り組んでおり、すべてのナビゲーション ロールを定義する必要はありません)。方法は次のとおりです。

<h:commandButton value="Register for the first time" action="registerFirstTime.xhtml?faces-redirect=true"/>

faces-redirect パラメーターは、必要な場合に備えて、転送ではなくリダイレ​​クトを強制します。

また、すべてではなく一部の値を適切に処理したいとします。その場合、p:commandButton または p:ajaxのプロセス属性を使用できます。例えば

<h:commandButton value="Register for the first time" action="registerFirstTime.xhtml?faces-redirect=true" process="@this, name"/>

これにより、JSF はボタン (@this) と id="name" (電子メール フィールド) を持つコンポーネントのみを処理します。繰り返しますが、おそらくこの質問には当てはまりませんが、私がよく使うものです。

于 2012-06-28T14:22:23.063 に答える