• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Listing and Action Form Validation

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saritha Penumudi
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Catch Ernie! Catch the egg! And catch this tiny ad too:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic