aspose file tools*
The moose likes Struts and the fly likes Classic Struts  Issue [A beginner] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Classic Struts  Issue [A beginner]" Watch "Classic Struts  Issue [A beginner]" New topic
Author

Classic Struts Issue [A beginner]

Dishpal Bhaluja
Ranch Hand

Joined: Dec 30, 2007
Posts: 96
I need a solution to this problem.My webdiagram is

My Scenario:
I have one action class subclassed using DispatchAction and one FormBean

trypath.jsp uses name and occupation fields of formbean
and when user submits the page its forwarded to trybuy.jsp displaying username and occupation got from trypath.jsp and asks for sex and age in this page.And then when the user submits this page its forwarded to total.jsp which is designed to display the whole fields in the formbean.My problem is that the first two values I got(ie name and occupation gets resetted here).

How can I get around this issue without deleting my reset function in FormBean class.

My resulting screens




[I deleted the reset function in formBean and changed scope of bean to session .The problem got solved.But now when I try to reaccess the first page,I need a clean page(ie resetted page and there lies the problem)].

I need a good method to solve this multipage form submissal using subclassing and single FormBean(obvious).

[ October 01, 2008: Message edited by: Dishpal Bhaluja ]

[ October 01, 2008: Message edited by: Dishpal Bhaluja ]
[ October 01, 2008: Message edited by: Dishpal Bhaluja ]
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Originally posted by Dishpal Bhaluja:


[...But now when I try to reaccess the first page,I need a clean page(ie resetted page and there lies the problem)].



Can you set the empty strings to your input FORM field like this



So that , when you re access the first page , you get the the initial empty values in test field !


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Dishpal Bhaluja
Ranch Hand

Joined: Dec 30, 2007
Posts: 96
That was a real eye opener.
Then why this much discussion about multi part forms in Struts and its implementation details.If we implement like in this way,why we need web flow and all in extension to struts.

This approach i can use in large forms which spread across several pages or so?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

The problem we are discussing is common and there is no hard and fast rule to solve it. Generally , I ll go with what you did, like using session scoped beans , which have one draw back , when user quit in middle of form submitting, the bean stays for its default timeout period !

and I don't have great experience in solving this kind of problem , so I cant help you much , May others Ranchers help us !!
Dishpal Bhaluja
Ranch Hand

Joined: Dec 30, 2007
Posts: 96
I guess there will be problem with validation,while using this technique.
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
In trybuy.jsp, are you storing the Name and Occupation in hidden fields on the screen?
Dishpal Bhaluja
Ranch Hand

Joined: Dec 30, 2007
Posts: 96
No its not stored as a hidden field.Why should I?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Originally posted by Dishpal Bhaluja:
I guess there will be problem with validation,while using this technique.


No I don't think so , Have you tried out validation of those fields ?
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
If you store the Name and Occupation values in hidden fields in trybuy.jsp they would be returned to the application server and placed into your form class so they could then be available in your try.jsp. This would prevent you from having to put your form into session scope.

if Merrill Higginson reads this he probably won't be happy that I'm discouraging the use of session scope again but, as you are already seeing with your problem of the values showing back up when you return to your first screen, using session scope forces you to add code to prevent unexpected session data from showing up on your screen. If your app is only 3 pages then it may be managable but if its more than that and the users can use back, forward, and book marks on thier browsers, you may find there are more scenarios then you can effectively predict. But digres...
Dishpal Bhaluja
Ranch Hand

Joined: Dec 30, 2007
Posts: 96
If that are hidden fields how a user is going to populate.I guess using session scope or so is not the trouble here.But how can I create a multi page form in a robust way?
Dishpal Bhaluja
Ranch Hand

Joined: Dec 30, 2007
Posts: 96
Merrill Higginson was a part of similar discussion here in this forum.I noticed it
http://www.coderanch.com/t/59020/Struts/Multipage-Form-implementation

But infact it never discuss about validation and all when using multipage forms.

Struts validation is real pain.
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
Looks to me like in trybuy.jsp you are displaying the data for name and occupation as text (not in a field), probably with a bean:write. So it appears to me that the user couldn't populate them on trybuy.jsp anyway (looks like they are populated by the user on trypath.jsp). The hidden fields on trybuy for name and occupation would be in addition to the bean:write tags you use to display the data.

The hidden fields are needed because the text displayed by bean:write is not returned to the application server when the html form is submitted. To get the data to the application server you can store the data in hidden input fields (html:hidden) which will be returned to the application server. Or you can use session scope for your form bean which will allow you to access the data stored there in a previous request. but you already know how I feel about that.
Dishpal Bhaluja
Ranch Hand

Joined: Dec 30, 2007
Posts: 96
Tom really I got it now.
So thats the use of hidden fields there.
I will try updating my code and will post the complete follow ups including validator implementation in this.
Dishpal Bhaluja
Ranch Hand

Joined: Dec 30, 2007
Posts: 96
I used hidden fields and successfully got through.But my next problem is that validate() method.Its called and validate detects my error.
But it shows the tryPath.jsp without any errors displayed.

I used the normal errors.add and is not giving me the errors

This is struts 1.1

and Im using html:errors for displaying errors
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Post your code with validate() method and tryPath.jsp , which prints the validation errors !
Dishpal Bhaluja
Ranch Hand

Joined: Dec 30, 2007
Posts: 96
<html:form action="/mrealPath">
<html:text property="name" value=""></html:text>
<html:text property="occupation"value=""></html:text>
<html:submit property="work" value="flow1"></html:submit>
<html:reset />
</html:form>

and <html:errors/> above the form tag

and my validate() method has

ActionErrors errors = new ActionErrors();
if (name.length() < 3)
{
System.out.println("Quick");
errors.add("quick",new ActionError("error.name","Name"));


}


return errors;
}
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

The code you posted is fine , and seems to be right ! But I still required your real working code, directly copy pasted from source ! Please PostRealCode.

And I hope you have this key error.name in Message.properties file and that .properties file is placed in classpath !
 
Don't get me started about those stupid light bulbs.
 
subject: Classic Struts Issue [A beginner]