• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

poulate a form from the reset (good practice)?

 
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys,

When a user logs to my application he has the following information:

my account
projects
.
.

in order to populate information (say to 'my account') I'm using the reset method in the form. If the user clicks on 'projects' and return to 'my account' the reset method kicks-in again (not good)

question: (1) is that a good practice to populate the information in the reset method? if yes, (2a) how can I overcome the problem stated above?

(2b) If not, how to populate the form BEFORE it gets to the jsp page? I understand I should do it in the action prior to the jsp page, but how can I get that specific form, and fw it?

thanks for any advise
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Guys,

When a user logs to my application he has the following information:

my account
projects
.
.

in order to populate information (say to 'my account') I'm using the reset method in the form. If the user clicks on 'projects' and return to 'my account' the reset method kicks-in again (not good)

question: (1) is that a good practice to populate the information in the reset method?



No. From all of the reading that I have done/advice from people on here you should only use the reset to make sure check boxes are put into an initial state.

if yes, (2a) how can I overcome the problem stated above?

(2b) If not, how to populate the form BEFORE it gets to the jsp page? I understand I should do it in the action prior to the jsp page, but how can I get that specific form, and fw it?


The following site might clear up your question.

http://www.theserverside.com/tt/articles/article.tss?l=StrutsActionMapping

If it doesn't let me know
*Note* I'm fairly new to struts as well so this is just my impression.
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is such a coincident, i just consulted this page yesterday.

how do you populate a form before it gets to the jsp page (from a different action class)?
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just create two different actions: pageXPrepare that gets the data from the database and displays pageX, and pageXProcess that acts on the form once it's submitted. Both actions should use the same ActionForm in the same scope. The URL you would use to display PageX initially would be:

http://myserver.com/myapp/pageXPrepare.do

instead of

http://myserver.com/myapp/pageX.jsp
[ November 23, 2006: Message edited by: Merrill Higginson ]
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, so if I get you right, there suppose to be an action before the jsp page that uses the same formBean and there to populate the form (cool).

so...how would the struts-config should look like? also, do I need a jsp page to redirect?

thank you.


thanks
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, it's done.

I eliminated the input from the struts-config.

but one thing remain unclear - the menu looks like this:
my account
projects

when I click 'my account' the prepareXpageAction kicks in and do all business logic (great)

then, I click the project and when I return to 'my account' the prepareXpageAction kicks again. oh....this is not good because:
1. redundant work
2. (even worse) all new info the user typed is gone

how can I make sure the prepareXpageAction will kick only once?

my intuitive solution is to have a boolean flag on the session, but this sounds to me like a bad disgen.

what do you think?
THANK YOU!
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

2. (even worse) all new info the user typed is gone


If this is the case, there's something very wrong with your design. If a user modifies information on the "my account" page, there needs to be some sort of save button that initiates a write to the database. Once the data has been written to the database, any subsequent reads will pick up the new information.

I wouldn't worry too much about the fact that data is being read a second time from the database. Whenever you're reading and modifying data in a web application, it's always best to read the latest data right before you give the user an opportunity to change it. That way you lessen the possibility of another application or user updating the information while you're still contemplating whether to change it or not. As Brent pointed out in a recent post, reads on an indexed database are quite fast these days, and one shouldn't worry excessively about the resource cost of the reads.
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Merrill,

the scenario is this:
The user has a save button and if he clicks save - the info is saved and everyone is happy. The problem occurs when he type something (say he added a middle name) and didn't click save, now he clicks 'Projects' and went back to 'my account' ---> (prepareXpageAction will kick in ...db...) the added middle name is gone.

I wonder how to avoid the second prepareXpageAction

thanks
 
A knibbs
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Peter Primrose:
Hi Merrill,

the scenario is this:
The user has a save button and if he clicks save - the info is saved and everyone is happy. The problem occurs when he type something (say he added a middle name) and didn't click save, now he clicks 'Projects' and went back to 'my account' ---> (prepareXpageAction will kick in ...db...) the added middle name is gone.

I wonder how to avoid the second prepareXpageAction
thanks


The entire point of the save button is to only save once that button is clicked. The application works fine if it only saves information when the save button is clicked. If your users want the application to try and be a mind reader you might best try and manage user expectations instead of trying to change the code to suit them.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I wonder how to avoid the second prepareXpageAction



My advice is to give up on trying to avoid the second prepareXpageAction. If a user modifies data, forgets to click the save button and then navigates to another page, what should they expect to happen? In every web application in the known world, they will lose the data if they do this. Why should your application be any different?

As I already mentioned, reads to the database are cheap these days, and it's worth the peace of mind of knowing you got the latest information from the database right before giving the user an opportunity to change it.
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
maybe I didn't explain myself correctly.

Think about this white-box that I'm typing my reply.

Now, I have some text above, If I click the back button and click fw the text above remains intact! and that exactly what I need. If the user clicks save - it will be saved if he navigate to a different page and return it will not be saved but will be there.

is this doable?
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, you are right, no application can do that.
Yes, you can navigate with the back/fw and have the data remain intact but once an action kicks in it's different.

Ok ok ok ok...I got it.


thank you guys!
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The back button is a little different. It pulls data from the browser cache. If you try the same experiment with this white box, except this time highlight the URL that appears at the top of the page while the white box is being displayed and copy it into the clipboard using <ctrl>c before hitting the back button. Now, instead of hitting the forward button, paste the URL into the browser's URL area and hit enter. What happens? The data is gone. If you use the back and forward buttons in your application in the scenario you describe, the data will be there as well, provided you haven't turned off browser caching in your JSPs.

The point I wish to make is that if you want to bend over backwards to deal with this situation, go ahead. I don't really have any advice for helping you do so. My point of view is that a user has no right to expect that data will remain if he forgets to click the save button and navigates away from the page. What I normally do in this situation, especially if the data is critical, is warn the user with a Javascript "confirm" dialog box that she has changed data on the page and is about to leave the page without having saved it.
reply
    Bookmark Topic Watch Topic
  • New Topic