facelets のカスタム コンポーネントに問題があります。ページが初めてレンダリングされるときに、コンポーネント クラスで属性が適切に設定されます。ただし、フォームが送信されると、属性は設定されません。
これをテストするために使用しているクラスは次のとおりです。
public class TestEcho extends UIData
{
/** Logger. */
private static Log log = LogFactory.getLog(TestEcho.class);
private String msg;
public TestEcho()
{
log.debug("Constructor.");
}
public void encodeEnd(FacesContext context) throws IOException
{
ResponseWriter writer = context.getResponseWriter();
writer.startElement("div", this);
writer.writeText("The value of msg is '" + msg + "'.", null);
writer.endElement("div");
}
public void setMsg(String msg)
{
log.debug("Setting msg to '" + msg + "'.");
this.msg = msg;
}
}
コンポーネントは、このように .xhtml ページで使用されます。
<h:form>
<v:testEcho msg="hello" />
<h:commandButton action="#{PictureManager.trigger}" value="Click" />
</h:form>
ページが初めてレンダリングされるとき、コンポーネントは次の html コードをレンダリングします。
<div>The value of msg is 'hello'.</div>
ボタンをクリックすると、これがレンダリングされます。
<div>The value of msg is 'null'.</div>
ログから、コンポーネントが再構築されていることがわかりますが、属性は設定されていません。
13:23:42,955 DEBUG [TestEcho] Constructor.
13:23:42,955 DEBUG [TestEcho] Setting msg to 'hello'.
----- Button was pressed here -----
13:25:48,988 DEBUG [TestEcho] Constructor.
13:25:49,144 DEBUG [PictureManager] Button pressed.
私が理解していることから、Faceletsはすべての属性をコンポーネントに配線するため、タグクラスは必要ありませんが、最初に属性が正しく設定され、2回目では正しく設定されない理由がわかりません。