struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Timothy Orme <>
Subject Best Practices for Forms
Date Mon, 02 Mar 2009 19:32:50 GMT
Hello All,

I'm relatively new to Struts 2 and have a few questions as far as how to lay out a form correctly.

I have the following scenario:

1. User is presented a form. (addData.jsp)
2. User submits form, we go off to an action to add form information to the database. (SubmitData.action)
3. We send the user to a page that displays information about the data they just entered.

The problem I was initially having was that, after step 2, I was using the dispatcher result
type to send the user to their view. SubmitData.action was providing viewData.jsp with the
necessary stack 
values to fill in the page with the appropriate data.

This was problematic, because at this point, due to the forward, the browser was still at
SubmitData.action, and refreshing the view caused the data to be submit again. To fix this,
I tried changing 
the result type to redirect to the jsp page instead. This fixed the problem of the user refreshing
the page. The browser was now at viewData.jsp, so refreshing the page didn't submit the data

However, because I had redirected, I no longer had the value stack the SubmitData.action provided,
so I arrived at the view with no data. I can come up with ways to work around this, but none
of them 
feel right. For instance, I can pass the necessary keys to viewData.jsp result like so:

<action name="SubmitData" class="action.SubmitDataAction">
	<result name="success">/viewData.jsp?dataId=%{dataId}</result>

And then in the jsp page have action tags which gather the correct objects and put them on
the stack:

<s:action name="GetData" namespace="/" var="data">
	<s:param name="dataId" value="%{dataId}" />

But again, this seems messy. What do people recommend? I know this has got to be a very frequent
case, I'm just not sure the best way to handle it.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message