0

ドロップダウン リストの値に基づいてページを動的に表示しようとしています。関連付けられているすべてのコンポーネントが適切にレンダリングされています。Bean がビュー スコープにある場合、検証はトリガーされませんが、セッション スコープでは同じことが正常に機能しています。問題?

Main.xhtml の私のコードは次のとおりです。このページには、ページを動的に含むドロップダウン値に基づいて、ドロップダウンリストが含まれています。

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition template="#{templates.standard}">
<ui:define name="contentArea">
<c:choose>
<c:when test="#{testBean.value == '1'}">
<h:panelGroup>
<ui:include src="Page1.xhtml" />
</h:panelGroup>
</c:when>
<c:when test="#{testBean.value == '2'}">
<h:panelGroup>
<ui:include src="Page2.xhtml" />
</h:panelGroup>
</c:when>
</c:choose>
</ui:define>
</ui:composition>
</html>

The below Page1.xhtml will be included dynamically in Main.xhtml 

<?xml version="1.0" encoding="UTF-8"?>
<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">
<h:panelGroup>
<h:inputText value="#{testBean1.date}"
id="date" 
required="true" requiredMessage="Enter Valid date">
<f:validator validatorId="test.TestDateValidator" />        
</h:inputText>  
</h:panelGroup>
<h:panelGroup>
<h:message for="date"/>
</h:panelGroup>
4

1 に答える 1

4

ビュー スコープ Bean は JSF ビューに格納されます。JSF ビューは、ビルドされている場合にのみ使用できます。JSTL のようなタグハンドラは<c:xxx>、ビューのビルド時に実行されます。したがって、これらは JSF ビューが使用可能になる前に実行されます。したがって、ビュー スコープ Bean のプロパティを JSTL タグ属性にバインドすると、JSF ビューでビュー スコープ Bean インスタンスを参照するのではなく、すべてのプロパティがデフォルトに設定された、新しく作成されたものを参照します。

So, basically, you end up with two different instances of a view scoped bean on a per-request basis. One which is used during restoring the view (the one which is freshly recreated on every form submit) and another one which is used during processing the form submit (the one which was actually stored in the view scope).

This chicken-egg issue is already reported as JSF issue 1492 and fixed for the upcoming JSF 2.2.

それまでは、別のリクエスト スコープ Bean を作成し、インクルード条件を によって注入されるリクエスト パラメータに依存させる@ManagedPropertyか、部分的な状態の保存をオフにすることをお勧めします (ただし、メモリ/パフォーマンスに影響する可能性があります)。<ui:include>はビューのビルド時にも実行されるため、rendered属性を使用して JSF コンポーネントにラップしても、ビューのレンダリング時に評価されるため、何の役にも立たないことに注意してください。

以下も参照してください。

于 2012-12-17T11:58:15.150 に答える