Validation Problem - very urgent please reply

2006-01-10 Thread Sony Thomas

Dear friends,

I have a Add user jsp page and in my jsp page the user can select his 
language from a dropdown menu. I am generating it from the ArrayList 
property in UserForm.


   td
   html:select name=UserForm property=language 
tabindex=8
   html:optionsCollection name=UserForm 
property=languages label=name value=code/

   /html:select
   /td

My problem is ,  when there is a validation error and control returns to 
the jsp page it is not able to find the languages collection, ie 
ArrayList. I know it is possible to solve by setting the form to 
session. but I dont want it to be in the session. Is there is any way 
out for this problem ??


Please reply to me

thanks in advance


Sony

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Validation Problem - very urgent please reply

2006-01-10 Thread Peter . Zoche
I had the same problem, and besides setting the form to session scope
you could do the following: Instead of storing your list of languages in
an ArrayList, store them in an array of Strings. Then on your jsp you
should be able to iterate over this list and sent all languages via the
html:hidden tag (that is why you have to use Strings, because they are sent
as Strings) with your request. So the languages are stored in your form with
every request, and when validation fails, you still have the languages
there.
The iteration should look something like this:

logic:iterate id=languageEntry name=UserForm property=languages
html:hidden property=languages value=${languageEntry} /
/logic:iterate

Hope that helps, perhaps you could reply when it works!

Peter

-Ursprüngliche Nachricht-
Von: Sony Thomas [mailto:[EMAIL PROTECTED]
Gesendet: Dienstag, 10. Januar 2006 10:51
An: user@struts.apache.org
Betreff: Validation Problem - very urgent please reply


Dear friends,

I have a Add user jsp page and in my jsp page the user can select his 
language from a dropdown menu. I am generating it from the ArrayList 
property in UserForm.

td
html:select name=UserForm property=language 
tabindex=8
html:optionsCollection name=UserForm 
property=languages label=name value=code/
/html:select
/td

My problem is ,  when there is a validation error and control returns to 
the jsp page it is not able to find the languages collection, ie 
ArrayList. I know it is possible to solve by setting the form to 
session. but I dont want it to be in the session. Is there is any way 
out for this problem ??

Please reply to me

thanks in advance


Sony

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Validation Problem - very urgent please reply

2006-01-10 Thread Meenakshi Singh
Hi,

I would suggest that manually call validate and use Request Scope
Not many people seem to be using this approach, yet I have found it to be
the best overall solution.

This is how it works:
First of all make sure you do not have validate=”true” set in your action
mapping.You should call form.validate(..) manually.

Then create a method to set up your request with any lists in scope. For
example if you are using a DispatchAction you can simply have a private
setUp(..) method in this Action. If you are creating separate Action classes
for all of your different actions you might want to make this a separate
class, or put it in a base Action class that your Actions can extend from.
Now manually call your form’s validate method, and then, based on whether
ActionErrors return or not, you can decide what to do. If ActionErrors
returns null/empty then validation was successful and you can continue your
processing and forward on to success. If ActionErrors is not null/not empty,
you have validation errors and need to call the setUp method to repopulate
any lists then forward back to the JSP form.

I am pasting a sample code from an article from a website to implement the
above.
You can look at this sample code  then try to implement it at your end.


//class EmployeeDispatchAction

private void setUp( HttpServletRequest request ) {
Collection jobCodes = Service.getJobCodes();
request.setAttribute(“jobCodes”, jobCodes);
}

public ActionForward setUpForm(ActionMapping mapping, ...) throws
Exception {
setUp( request );
return (mapping.findForward(UIconstants.TO_FORM));
}

public ActionForward update(ActionMapping mapping, ...) throws Exception
{
ActionErrors errors = form.validate( mapping, request );
if ( errors != null  !errors.isEmpty ) {
saveErrors(request, errors);
setUp(request);
return (mapping.findForward(UIconstants.VALIDATION_FAILURE));
}
//Everything OK, continue on...
return (mapping.findForward(UIconstants.SUCCESS));
}


Give it a try!!!

Thanks  Regards,
Meenakshi.

PS: Let me know whether it worked for you or not.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Validation Problem - very urgent please reply

2006-01-10 Thread Vishal Gaurav
Hi,

I feel that the approach given by Peter would be fine.

You might be populating the drop down by iterating a collection fetched from
Database. When you submit the form only the selected value is submitted from
the drop down not the entire collection (That is why you do not get the
collection back on page load after validation failure).

Ideal workaround is to iterate the entire collection again within the JSP
and submit the same as hidden.

If your collection is of some object having attributes like id and value
then you need to submit two separate collections one for each type of
attribute.

In this case you need to ensure that in your form bean if there is a
validation error you need to map the hidden collection back into the form
just the way you do it while loading the page from the action class. You
will need to iterate through both the collections and remake the collection
of objects from the same and set it into the appropriate form property.

Please let me know if you need any further information.

Regards,
Vishal

On 1/10/06, Meenakshi Singh [EMAIL PROTECTED] wrote:

 Hi,

 I would suggest that manually call validate and use Request Scope
 Not many people seem to be using this approach, yet I have found it to be
 the best overall solution.

 This is how it works:
 First of all make sure you do not have validate=true set in your action
 mapping.You should call form.validate(..) manually.

 Then create a method to set up your request with any lists in scope. For
 example if you are using a DispatchAction you can simply have a private
 setUp(..) method in this Action. If you are creating separate Action
 classes
 for all of your different actions you might want to make this a separate
 class, or put it in a base Action class that your Actions can extend from.
 Now manually call your form's validate method, and then, based on whether
 ActionErrors return or not, you can decide what to do. If ActionErrors
 returns null/empty then validation was successful and you can continue
 your
 processing and forward on to success. If ActionErrors is not null/not
 empty,
 you have validation errors and need to call the setUp method to repopulate
 any lists then forward back to the JSP form.

 I am pasting a sample code from an article from a website to implement the
 above.
 You can look at this sample code  then try to implement it at your end.


 //class EmployeeDispatchAction

 private void setUp( HttpServletRequest request ) {
 Collection jobCodes = Service.getJobCodes();
 request.setAttribute(jobCodes, jobCodes);
 }

 public ActionForward setUpForm(ActionMapping mapping, ...) throws
 Exception {
 setUp( request );
 return (mapping.findForward(UIconstants.TO_FORM));
 }

 public ActionForward update(ActionMapping mapping, ...) throws
 Exception
 {
 ActionErrors errors = form.validate( mapping, request );
 if ( errors != null  !errors.isEmpty ) {
 saveErrors(request, errors);
 setUp(request);
 return (mapping.findForward(UIconstants.VALIDATION_FAILURE));
 }
 //Everything OK, continue on...
 return (mapping.findForward(UIconstants.SUCCESS));
 }


 Give it a try!!!

 Thanks  Regards,
 Meenakshi.

 PS: Let me know whether it worked for you or not.


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]




Re: Validation Problem - very urgent please reply

2006-01-10 Thread Raghu Kanchustambham
The trick is to point the input variable in your struts-config.xml to the
action class that generated the JSP page rather than the JSP page itself.

 action attribute=enquiryForm name=enquiryForm path=/Enquiry
scope=request
 validate=true type=com.tuningfork.action.EnquiryAction
parameter=operation input=/Enquiry.do?operation=validateFailed

On failure of validation, you should redirect it to the preparation action
class for the form that solicits information for you - the action class
where you would be populating the arraylist that you are using in the JSP.

HTH,
~raghu~


On 1/10/06, Sony Thomas [EMAIL PROTECTED] wrote:

 Dear friends,

 I have a Add user jsp page and in my jsp page the user can select his
 language from a dropdown menu. I am generating it from the ArrayList
 property in UserForm.

td
html:select name=UserForm property=language
 tabindex=8
html:optionsCollection name=UserForm
 property=languages label=name value=code/
/html:select
/td

 My problem is ,  when there is a validation error and control returns to
 the jsp page it is not able to find the languages collection, ie
 ArrayList. I know it is possible to solve by setting the form to
 session. but I dont want it to be in the session. Is there is any way
 out for this problem ??

 Please reply to me

 thanks in advance


 Sony

 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]