Component initialization ordering issue

Hi,

I'm noticing a strange behavior for the component initialization ordering on a page. I have a simple application with two pages which look like:

page1:

<jsp:root ..>

...

<ui:textField .../>

<ui:passwordField .../>

<ui:button .../>

...

</jsp:root >

page2:

<jsp:root ..>

...

<ui:staticText ... text="Something" />

...

</jsp:root >

In the backing bean of page1.jsp, I save the value entered in the textField1 in sessionBean1.userId by doing something like:

public String button1_action(){

getSessionBean1().setUserId((String)textField1.getText());

System.out.println("User added to session. User: "+getSessionBean1().getUserId());

return"page2";

}

In the backing bean of page2.jsp, I have a code like shown below to greet the user:

publicvoid prerender(){

String msg ="Welcome "+ getSessionBean1().getUserId();

System.out.println("Message: "+msg);

staticText1.setText(msg);

}

The problem is that the greeting message that gets displayed on the page2 is not what I set in the prerender() method above (rather it is the one I specify in the "text" attribute of "ui:staticText" element in page2.jsp). It gets updated only if I click some other link (or a button) that I may have on page2. However, if I do not set the "text" attribute on the "ui:staticText" element on the page2.jsp then I can correctly see whatever text I set in the prerender() method of page2.java.

This has sort of confused me on the ordering of component initialization on a page. The documentation of the prerender() of the backing bean says that prerender() gets executed just prior to rendering the page, so then why aren't my values getting reflected on the rendered page even though in the server logs I can see (by the adding a log stmt) that the "text" was updated?

Thanks.

[2368 byte] By [b.sodhia] at [2007-11-27 5:02:40]
# 1

This is explained in http://developers.sun.com/jscreator/learning/tutorials/2/about_components.html:

NOTE: As with the JavaServer Pages implementation, when the server constructs a page from JSP source, the tag attribute settings in the JSP source take precedence over runtime settings. For example, if you set the text property for a Static Text component to "moon," the IDE adds text="moon" to the Static Text component's tag in the JSP file. Even if the page's prerender method has a staticText1.setText("sun") statement, the Static Text component shows "moon" when the application renders the page. If the page is rerendered, the staticText1.setText("sun") statement takes affect and the Static Text component shows "sun." If you visit another page and come back, the server once again constructs the page from the JSP source, the values set in the JSP tag attributes take precedence, and the page displays "moon."

TIP: To ensure that property setting code always takes effect, do not set that property to a static value in the Properties window.

jetsonsa at 2007-7-12 10:20:36 > top of Java-index,Development Tools,Java Tools...