composite:insertChildren タグを使用しているため、@ViewScoped マネージド Bean が @RequestScoped マネージド Bean のように動作するという問題があります。この件に関する他の投稿を読み、@ViewScoped managedBeans の制限を認識していますが、明示的なバインディングはなく、複合コンポーネントで JSTL を使用していません。
insertChildren タグが managedBean にバインドされていると想定していますが、誰かが私を悲惨な状況から解放し、回避策を示してくれることを望んでいます-@SessionScoped Bean の使用を開始したくありません。:)
これが私の簡単な例です。シンプルなマネージド Bean:
@ManagedBean(name = "simpleMB")
@ViewScoped
public class SimpleManagedBean implements Serializable {
private static final long serialVersionUID = -1;
@NotNull
@Email
private String email;
public SimpleManagedBean() {
System.out.println("SimpleManagedBean");
}
@PostConstruct
public void postConstruct() {
System.out.println("Post construct");
}
public String submit() {
return null;
}
... setter and getter
}
上記の SimpleManagedBean を以下のフォームおよび複合コンポーネント (insertChildren なし) とともに使用すると、すべてが期待どおりに機能します。テキストを入力して送信を押すと、入力したテキストとともにエラーが表示されます。この時点で、私は幸せです。
<h:form>
<foo:simpleNoChildren />
<h:commandButton id="submit"
value="Submit"
action="#{simpleMB.submit}" />
</h:form>
... and the composite component ....
<composite:interface />
<composite:implementation>
<h:panelGrid columns="3">
<h:outputText value="Email" />
<h:inputText id="email"
value="#{simpleMB.email}"
required="true" />
<h:message for="email" />
</h:panelGrid>
</composite:implementation>
ここで、以下に示すように、panelGrid とそのコンポーネントを複合コンポーネントの外に移動し、composite:insertChildren タグに置き換えると、テキストを入力して送信を押すと、適切なエラー メッセージが表示されますが、@PostConstruct メソッド再び呼び出されると、入力したテキストが表示されなくなりました。:(
<h:form>
<foo:simple>
<h:panelGrid columns="3">
<h:outputText value="Email" />
<h:inputText id="email" value="#{simpleMB.email}" required="true" />
<h:message for="email" />
</h:panelGrid>
</foo:simple>
<h:commandButton id="submit" value="Submit" action="#{simpleMB.submit}" />
</h:form>
... and my complicated composite component :) ...
<composite:interface />
<composite:implementation>
<composite:insertChildren />
</composite:implementation>
何か考えや提案はありますか?
前もって感謝します。