This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Struts and the fly likes Listing and Action Form Validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Listing and Action Form Validation " Watch "Listing and Action Form Validation " New topic
Author

Listing and Action Form Validation

Saritha Penumudi
Ranch Hand

Joined: Aug 18, 2003
Posts: 147
1. I have a scenario where I have to show some list of configuration items in the updatable listing format. That is the listing contains the configuration Item Name (uneditable display text), Configuration Item (editable text box). I am getting the list from the database and when user hits save, I have to do some form validations and if valiadtion fails then I have to navigate back to the listing with the error message.

I am getting the configuration Items in the form of ConfigurationVo objects and holding the collection in request scope. In my Jsp I am using <logic:iterate> to loop through the collection and render information as static text or set value in a text field. Now, when user updates some data and clicks "Save" button and if the validation fails, then it is navigating back to the same page but there is nothing being showed in the listing. I guess, it is no more able to find the collection in request scope. When I try to add the collection in session scope I am able to see the listing upon validation error. But, the values are defaulted to the original values but not the one's which user has edited.

I would appreciate of someone could help me in showing the listing with values that user has edited by adding the collection to request scope.

Thank you
[ November 16, 2004: Message edited by: Saritha ventrapragada ]
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

There are a few ways to approach this. You asked for a way to put a new collection in request scope. I'm not sure I would take this approach as the only way I can think of doing this is to create the collection inside of your ActionForm's validate method and set it to request there.

I try not to have my jsp iterate through a non-ActionForm collection unless it is for readonly data.

If the user can change the values, I believe it is best to both get and set the value from the ActionForm. It prevents issues like the one you are having.


A good workman is known by his tools.
Saritha Penumudi
Ranch Hand

Joined: Aug 18, 2003
Posts: 147
I agree with what you have suggested.
But, to set the collection values to the ActionForm class, I have to loop through collection manually and set values to the Form class, which does takes some time to do this process.
My Action form contains the Array of configuration items and values.

with gettter and setter methods.

Is there any short cut to set these collection values to these arrays?
collection contains these values in the form of ConfigurationVO objects.
The strutcture of ConfigurationVO is

with getter and setter methods.

Your help is greatly appreciated

Thank you
Saritha
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

I usually do the manual iterate to arrays but I believe you can simply place the collection in the ActionForm and use indexed=true in the html:text tags. You would still logic:iterate through the collection from the ActionForm.
s penumudi
Ranch Hand

Joined: Nov 17, 2004
Posts: 113
I have tried to implement the same problem. I am getting exceptions

here is the code for ActionForm


This is my JSP


can you please help me in solving my problem
Thank you
[ November 17, 2004: Message edited by: sari perumudi ]
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

To use indexed you must have a collection of bean objects to iterate through. You implemented the "manual iteration" that was previously discussed in which the values are siloed out to their own arrays and that won't work with indexed=true.

Additionally, your logic:iterate tag is in some error. The "type" attribute should specify the bean's object type, not the ActionForm. Additionally, you will need a "property" attribute to specify the ActionForm's getter method for retrieving said collection.

Move your getter/setter methods to a bean class and put a collection (ArrayList for example) of these beans in your ActionForm with a getter/setter for the collection. The name of the collection's getter will be the "property" attribute of logic:iterate. The "type" attribute will be the class of the bean.
Hope this helps.
s penumudi
Ranch Hand

Joined: Nov 17, 2004
Posts: 113
Please correct me if my understanding is wrong.

To use indexed you must have a collection of bean objects to iterate through. You implemented the "manual iteration" that was previously discussed in which the values are siloed out to their own arrays and that won't work with indexed=true.

can you please explain me what bean means?. I guess I am totally missing something. Are you refering ConfigurationVO as bean, which is ofcourse a javabean with getter and setter methods and have a collection of ConfigurationVO objects collection as getter and setter methods in form class?.

If I do this, then how the values that are being updated in the UI would get set to the Actionform?

I would appreciate if you could explain this with an example.

Thank you
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Your previous post made no mention of a value object. Saritha had a ConfigurationVO and that is Saritha's bean. You might have a different one.

If you need an example, look here.

The best example you could see is to try what I offered and learn from it.
s penumudi
Ranch Hand

Joined: Nov 17, 2004
Posts: 113
Hi Marc,

Thank you for the link. I will go through the link.
Yes your right. I was just trying out a example and used same terminology as Saritha used.

I really appreciate all your help.

Thank you
s penumudi
Ranch Hand

Joined: Nov 17, 2004
Posts: 113
Hey I am stuck and Don't know how to go about this.
This is my logic:iterate tag.


ActionForm contains Arraylist of com.project.vo.Lock objects.

I get the following exception.
javax.servlet.jsp.JspException: Cannot find bean null in any scope

when I have assigned name="LockMonitorForm" to logic:iterate,
I get the following exception
javax.servlet.jsp.JspException: Cannot find bean LockMonitorForm in any scope

I don't understand this concept at all..

As far as I understand, if I don't specify name attribute then it should look for that property in the formbean which was configured for that JSP in strus-config.xml file. but I don't see this.

when I look at java code generated for that JSP, I see that it is looking for some object registered with name "mList" in pageContext. As far as I was thinking mList would be a object for my Lock class. but that does not seem to be the case.

I don't know where I can find the complete explanation of these tags and what the java output for these tags would be.

Your help would be greatly appreciated

Please reply
[ December 08, 2004: Message edited by: s penumudi ]
 
GeeCON Prague 2014
 
subject: Listing and Action Form Validation