Hi!
We were previously using Struts1 session scope form beans to achieve
what we feel was rather natural: We frequently have a pattern were a
user needs to change some settings in some model bean stored in a
persistent storage. With Struts1, we had a jsp with a <html:form> tag
that was bound to an action configuration in struts-config.xml which
defined the corresponding form bean as being session-scoped. Then we
used some other action (i.e. a menu click action or an action behind a
link on some other page) to access the model from the persistent
storage, instantiate the form bean and pre-populate it with the values
from the model. Then, after redirecting the user to the edit.jsp, all
model values were correctly used to pre-fill the html form fields.
Now enter Struts2: From what i learned so far, the closest to what we
had in Struts1 would be a pojo class that implements the ModelDriven and
SessionAware interfaces, so that's what i implemented. In the getModel()
method, i first check the session if my bean is already there and use
the session value as return value. This works ok, i.e. getModel()
correctly returns the session value that was prepared somewhere else.
The <s:textfield> tag is also correctly bound to the corresponding
setter method in my session bean class, i.e. the subsequent action
invocation correctly populates the session bean with the values on the
html form. However, i'm wondering what would be the correct way to have
the html form field pre-filled with what the getter method of my session
bean returns? The following seems to work (assuming that my session bean
is found behind the key "mySessionBeanKey"), but appears ugly to me:
<s:textfield name="theValue" value="#session.mySessionBeanKey.theValue"/>
The form field is only pre-filled if i explicitly use
value="#session...", but with this, i would be forced to use the session
key on all jsps that contain form fields that are supposed to access
this session bean. We have complex wizards with several pages all
accessing the same session bean, so this would be rather uncomfortable.
A different option would (on first glance) be to not redirect the user
to edit.jsp but instead to use a dispatcher. This, however, is also ugly
because then the user browser would ask the user if he wants to
re-submit the previous page. So we would very much like edit.jsp to be
the result of a redirect, not the result of a dispatcher.
Is there a more intelligent method to achieve what i want? Any other
suggestions?
Robert
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]