On 6/13/05, Paul Goepfert <[EMAIL PROTECTED]> wrote:
> ok here is what I am talking about.  I have a form that takes in first
> name, last name, street address, city, state and zipcode.  When I press
> on the button to enter that information into a database.  I want the
> page to  reload with clear input fields.
> 
> -Paul

So you want to be able to click "Save", and you app would:
* pick up values you entered
* store them in database
* respond with the same page, but with cleaned up fields

So, you need web interface for inserting data record by record, with
no stupid messages and intermediate screens. Something like
bookkeeping or banking app. Right?

Have you thought on the following:
* What happens if data is incorrect? (usually redisplay the same page
with error message)
* What happens if a user clicks Refresh browser button?
* What happens if a user clicks Back browser button?
* What if the same data is entered twice? On the same note, where do
you create/assign unique ID to your records? Can you detect that same
data is entered twice, or you want web framework to check this for
you?
* Do you care if a user saw nagging "Do you want to resend POSTDATA?" message?
* Do you think regular users understand what this message mean? ;)
* Do you want to create new record by duplicating existing one?

If you just started web development, the whole "double submit" thing
is a huge issue and you will need to address it in some way.

(Option 1)

Basically, if you do not care much for Refresh, Back and Forward
buttons, and you are OK that a user would see POSTDATA message when he
refreshes a page, then you can go with tokens. Struts has built-in
support for tokens. You will need to do this to ensure that same data
is not posted twice. You can use tokens with any data.

You can also ensure that your data is not posted twice by using object
ID. Before server shows a form with empty fields to fill in, it
generates object ID (or database PK) and uses it as hidden field in
the HTML FORM. If a user tries to resubmit the same data, database
would reject it, because it cannot insert data with the same key. But
still, you would see POSTDATA message, if you try to refresh a page.

Well, how many people refresh a dialog page? Apparently, not many. So
you might get away with this simple design. So, to do this:
* read about tokens.
* use action form with request scope.
* Use some flavor of DispatchAction to better structure your code,
using methods as event handlers.

When you receive the request, validate it. If it is not valid,
generate error messages. If you defined "input" property with the same
JSP name as your input form, Struts will show it for you. If data is
ok, your action class will be called. Store it in the database, then
manually clean fields in the form bean, and forward to your JSP.
That's it.

(Option 2)

If you want something that look more easy on user, and behaves more
robust and professional, but with a little more involvement, you might
use two-phase I/O processing: process data input via POST request,
then redirect, then load result page with GET request. This way a user
would be able to click as many reload buttons as he likes. And data
will be there.

In this case you might want to look at my DialogAction, which I wrote
specifically for cases like this:
http://struts.sourceforge.net/strutsdialogs/dialogaction.html See live
demo, check the source code, it is simple. You might like it.

You would have only one page, so you will need to define one view
mapping in your config file, nothing to code in action class. Then see
login() method. It redisplays the same page on error, and moves to
different page on success. Your case is even simpler, you need to
display the same page anyway. You just need to validate input data. If
it is valid, store it, clean form fields, and forward to
DialogConstants.DIALOG_RELOAD_KEY, which will reload same action. If
data is wrong, stick error message to session, and forward to the same
DialogConstants.DIALOG_RELOAD_KEY, it will show the page with errors.
Cannot be simpler.

Michael.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to