aspose file tools*
The moose likes Struts and the fly likes ActionForm and View's initialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "ActionForm and View Watch "ActionForm and View New topic
Author

ActionForm and View's initialization

Alan Mikes
Greenhorn

Joined: Oct 31, 2005
Posts: 3
If I want to initialize my view only once with initial values,
where should I do it?

ActionForm's reset-method seems not to be the right place because it is called every time if the view has e.g. a submit button. Action class seems to be called too late. Where should I handle first initialization of the view? Can anyone please tell me,

Cheers!
Iftikhar Arain
Ranch Hand

Joined: Jul 17, 2002
Posts: 95

I couldn't understand your problem. You want to initialize JSP only one time. Next time when you reach this page you don't want these values.

And what is your path.

1) Browser---> JSP1 ---->Action---->JSP2(View you want to intialize one time only)

2) Browser---->Action---->JSP2(View you want to intialize one time only)
Regards.


SCJP,SCWCD,IBM UML,FLEX & AIR,MCAD,MCSD, Adobe ACE
Alan Mikes
Greenhorn

Joined: Oct 31, 2005
Posts: 3
There is ActionForm between jsp and Action.

Okey, let's explain this detailed.

I want that my view which uses ActionForm and validation (validation.xml)
get default values when the view is first time shown. Those values are allowed to be something else than validation accepts, because I will make a default query from database and show that default data in view.

After that validation should be performed in view's components when user presses e.g. submit button.

So, this is my case. How should it be handled?

Cheers!
Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
Perhaps I have misunderstood your question. Anyway, consider putting java initialization code (constructor or variable initializer) for the your ActionForm's property and put you ActionForm in session scope. Then your ActionForm's property is initialized once in the current session. Is that what you want?
Alan Mikes
Greenhorn

Joined: Oct 31, 2005
Posts: 3
Yes, but there are two things that I don't actually like
1. Validator (xml based) gives sometimes error messages and putting "flag" variables to prevent validation in some cases does not look good in code
2. Like to use request as much as possible.

But, thanks anyway. If some have good ideas or best practices, please
share them.

Cheers!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ActionForm and View's initialization
 
Similar Threads
uninitialized default global variable
Doubt about the initialization block order of execution
ServletContextListener v/s init() method
custom view
Related to Singleton class