始める前に、この質問のタイトルの文言がわかりにくい場合はお詫び申し上げます。ここでの説明がより明確になることを願っています。
アプリケーションの JSF テンプレートに、別のテンプレートを含めて、アプリケーション メソッドの結果を保持するパラメータをそれに渡したいと考えています。この親テンプレートには、次のものがあります。
<ui:repeat var="loopObject" value="#{ApplicationBean.objectList}">
<ui:include src="anotherTemplate.xhtml">
<ui:param name="firstParam"
value="#{ApplicationBean.initForOtherTemplate(loopObject)}" />
</ui:include>
</ui:repeat>
しかし、これinitForOtherTemplateはこの時点では実行されておらずfirstParam、予想どおり、その戻り値ではなく、そのメソッドへの参照が含まれていることがわかりました。
実際、 while にinitForOtherTemplateは戻り値がありますが、anotherTemplate.xhtml必要ありません。ただし、メソッドはApplicationBean、この新しいテンプレートが使用する他のいくつかのオブジェクトを設定します。たとえば、他のテンプレートが必要とするimportantInfoとの値を設定します。importantInfoToo
anotherTemplate.xhtml内容:
<ui:remove>
<!--
When a parameter contains a method call, the method isn't executed until
the parameter is referenced. So we reference the parameter here and ignore
the results. There must be a better way.
-->
</ui:remove>
<h:outputText value="#{firstParam}" style="display: none;" />
<h:outputText value="#{ApplicationBean.importantInfo}" />
<h:outputText value="#{ApplicationBean.importantInfoToo}" />
このテンプレートが を参照していない場合firstParam、importantInfoandimportantInfoTooは設定されないか、予測できない値になります。initForOtherTemplateここではなく、親テンプレートで実行されることを期待していたので、これは非常に残念です。
メソッドへの参照を保存するのではなく、メソッドを実際にすぐに実行するようにパラメーターの割り当てを取得するにはどうすればよいですか?