RE: Question about Struts validator

2006-06-28 Thread mosho

David,

Thanks a lot! I understood the whole concept now.
It's working perfectly!!!

Thanks again!
Rosh
-- 
View this message in context: 
http://www.nabble.com/Question-about-Struts-validator-tf1851247.html#a5089649
Sent from the Struts - User forum at Nabble.com.


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



RE: Question about Struts validator

2006-06-28 Thread David Friedman
Rosh,

> I want to use struts validator and just control
> validation manually. Why do I need saveErrors()
> method and what does it do? Isn't the validator
> does all that. I am little confused.

If you are going to call the validation manually, then you will have to
perform the same steps the validation framework would do.  Those steps are
normally performed in chains (or the RequestProcessor if you use and older
version) and handle a number of things automatically.  Turning the
validation off in the Struts config bypasses much of that so you will have
to do it manually.  Just calling validate gets a list of errors but does
nothing with it so it becomes lost if you do not save it somewhere.  Check
your code and you'll see you do nothing with it and it goes away when you
return your mapping.findForward().

You can learn/find out a lot more by reviewing the code from either the
source code download OR the online (http/web-based) svn repository at:
http://svn.apache.org/viewvc/struts/action/trunk/core/src/main/java/org/apac
he/struts/

> The way it is wortkng now: it is giving me null pointer
> exception if I hit go in the url for selstate.do action.

What is the stack trace?  Stack traces show what leads up to the exception
so you can figure out what class or object is having the problem.

> It is doing client site validation only if i hit submit button.

That is how it is supposed to work: client side validation invokes in the
submit but should not actually submit anything until you have cleared up all
of the client side errors.  If you are not seeing that then perhaps you
don't have the correct html:javascript formName="..." tag setup properly
with the
corresponding onSubmit="" for your  html:form tag.

> public ActionForward execute(ActionMapping mapping, ActionForm form,
> HttpServletRequest request, HttpServletResponse response) throws
> IOException, ServletException
>  {
>   SelStateForm sform = (SelStateForm) form;
>   String isSubmitted = sform.getIsSubmitted();
>   if(isSubmitted == "Yes" || isSubmitted.equalsIgnoreCase("Yes"))
>   {
>   ActionErrors errors = sform.validate( mapping, request );
>if((errors != null) && errors.size() > 0)
>{
> return mapping.findForward(mapping.getInput());
>}
>   }
>return mapping.findForward("success");
>  }
>}

1) Isn't the method signature supposed to be (note one Exception, not two):

public ActionForward execute(ActionMapping mapping,
 ActionForm form,
 javax.servlet.http.HttpServletRequest request,
 javax.servlet.http.HttpServletResponse
response)
  throws java.lang.Exception

2) Is "isSubmitted()" checking some sort of variable in your page?  Why do
you have it at all?  Is this page being called a lot of times for a wizard
or something?

3) Have you put any logging statements (commons Logging Log class or even
System.out.println) anywhere so you can see/feel the flow of where you are
going and what is happening inside your action?  You know, to help you debug
this yourself?

4) See how you do nothing with the errors object so it simply goes away with
garbage collection after you return your mapping?  You need to PUT IT
somewhere to be used, hence the suggestions of using one of the various
saveErrors()/saveMessages() methods where appropriate so it doesn't
disappear with Garbage collection and you can get something meaningful out
of it which is why you are using validation to obtain/get those errors in
the first place.

Regards,
David


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



RE: Question about Struts validator

2006-06-28 Thread mosho


I really appreciate all your help.

David,

I want to use struts validator and just control validation manually. Why do
I need saveErrors() method and what does it do? Isn't the validator does all
that. I am little confused.

I am pasting my execute method below, please let me know what should I add
to make it work.

The way it is wortkng now: it is giving me null pointer exception if I hit
go in the url for selstate.do action.
It is doing client site validation only if i hit submit button.

 public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws
IOException, ServletException
  {
   SelStateForm sform = (SelStateForm) form;
   String isSubmitted = sform.getIsSubmitted();
   if(isSubmitted == "Yes" || isSubmitted.equalsIgnoreCase("Yes"))
   {
   ActionErrors errors = sform.validate( mapping, request );   
if((errors != null) && errors.size() > 0)
{
 return mapping.findForward(mapping.getInput()); 
}
   } 
return mapping.findForward("success");
  }
}

Wendy, thanks for letting me know about making validate false in config
file.

Thanks.
Rosh
-- 
View this message in context: 
http://www.nabble.com/Question-about-Struts-validator-tf1851247.html#a5087526
Sent from the Struts - User forum at Nabble.com.


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



RE: Question about Struts validator

2006-06-27 Thread David Friedman
Rosh,

1. Were any errors produced?  You never check.  Perhaps:
(errors != null) && errors.size() > 0

2. Do you save the errors with a method such as saveMessages() /
saveErrors() ?   How are you going to get them to your html:form so you can
show them to the client with html:errors, html:messages, etc.

3. Do you go anywhere if you FIND errors?  No.  Your code snippet ALWAYS
returns to your "success" mapping.  If you find errors you might want to go
the "input" mapping or one of your own choosing.  I think the input mapping
might be jumped to by something like this:

return mapping.findForward(mapping.getInput());

I might have typed incorrectly but you can probably get the idea of what I
am suggesting from that code suggestion above.

4. Where in your example JSP do you show your errors if any occur?  See the
section from the html: taglib on html:errors at:
http://struts.apache.org/struts-action/struts-taglib/apidocs/org/apache/stru
ts/taglib/html/package-summary.html#doc.Other.errors
Though I thought it was html:messages now.  I must be using an older version
but the rest should apply.  *shrug*

Much of this is listed in Wendy's example.  I recommend you review it again
before you consider my suggestions so you can see how my suggestions mirror
much of what is shown in her examples.

Regards,
David

-Original Message-
From: mosho [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 27, 2006 5:18 PM
To: user@struts.apache.org
Subject: RE: Question about Struts validator



Thanks David and Wendy for your help but it doesn't seem to work.
I added manually validate in my execute method. It still validates if I
directly enter the url.

I am pasting part of my code for you to take a look and let me know where I
am going wrong. Thanks again!


--Struts config part--

  


---SelStateAction--
SelStateForm sform = (SelStateForm) form;
   String isSubmitted = sform.getIsSubmitted();
   if(isSubmitted == "Yes" || isSubmitted.equalsIgnoreCase("Yes"))
   {
   ActionErrors errors = sform.validate( mapping, request );
   }

return mapping.findForward("success");

---JSP file---


 .
.
 



--
View this message in context:
http://www.nabble.com/Question-about-Struts-validator-tf1851247.html#a507421
7
Sent from the Struts - User forum at Nabble.com.


-
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: Question about Struts validator

2006-06-27 Thread Wendy Smoak

On 6/27/06, mosho <[EMAIL PROTECTED]> wrote:


Thanks David and Wendy for your help but it doesn't seem to work.
I added manually validate in my execute method. It still validates if I
directly enter the url.

...

--Struts config part--

  



You need to set validate="false" in the action mapping.  The default
is true, which is the behavior you're seeing.

--
Wendy

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



RE: Question about Struts validator

2006-06-27 Thread mosho

Thanks David and Wendy for your help but it doesn't seem to work.
I added manually validate in my execute method. It still validates if I
directly enter the url.

I am pasting part of my code for you to take a look and let me know where I
am going wrong. Thanks again!


--Struts config part--

  


---SelStateAction--
SelStateForm sform = (SelStateForm) form;
   String isSubmitted = sform.getIsSubmitted();
   if(isSubmitted == "Yes" || isSubmitted.equalsIgnoreCase("Yes"))
   {
   ActionErrors errors = sform.validate( mapping, request );  
   }  
 
return mapping.findForward("success");

---JSP file---


 .
.
 



-- 
View this message in context: 
http://www.nabble.com/Question-about-Struts-validator-tf1851247.html#a5074256
Sent from the Struts - User forum at Nabble.com.


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



RE: Question about Struts validator

2006-06-27 Thread mosho

Thanks David and Wendy for your help but it doesn't seem to work. 
I added manually validate in my execute method. It still validates if I
directly enter the url.

I am pasting part of my code for you to take a look and let me know where I
am going wrong. Thanks again!


--Struts config part--

  


---SelStateAction--
SelStateForm sform = (SelStateForm) form;
   String isSubmitted = sform.getIsSubmitted();
   if(isSubmitted == "Yes" || isSubmitted.equalsIgnoreCase("Yes"))
   {
   ActionErrors errors = sform.validate( mapping, request );  
   }   
  
return mapping.findForward("success");

---JSP file---


 .
.
 



-- 
View this message in context: 
http://www.nabble.com/Question-about-Struts-validator-tf1851247.html#a5074217
Sent from the Struts - User forum at Nabble.com.


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



RE: Question about Struts validator

2006-06-27 Thread David Friedman
I'll +1 that with one reminder for Rosh:

You mentioned using the Validation Framework so don't forget to have your
ActionForm extend either ValidateActionForm or ValidatorForm.  Since I
didn't see any notes about that in Wendy's below link, and I've made this
mistake in the past, I thought I would emphasize the point for you. :)

Regards,
David

-Original Message-
From: Wendy Smoak [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 27, 2006 4:27 PM
To: Struts Users Mailing List
Subject: Re: Question about Struts validator

On 6/27/06, mosho <[EMAIL PROTECTED]> wrote:

> If I call validate method manually, can I still use validator framework
and
> use the input attribute in the config file to display the errors?
>
> I need to validate only if form is submitted by clicking on a button.
> If, yes can you show me with an example how to call validate method in
> Action class, execute method.

Here's a tutorial that explains how to do it:
 * http://www.learntechnology.net/validate-manually.do

Another option is to override the 'validate' method of the form, and
only call super.validate() if the form was submitted.

--
Wendy


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



Re: Question about Struts validator

2006-06-27 Thread Wendy Smoak

On 6/27/06, mosho <[EMAIL PROTECTED]> wrote:


If I call validate method manually, can I still use validator framework and
use the input attribute in the config file to display the errors?

I need to validate only if form is submitted by clicking on a button.
If, yes can you show me with an example how to call validate method in
Action class, execute method.


Here's a tutorial that explains how to do it:
* http://www.learntechnology.net/validate-manually.do

Another option is to override the 'validate' method of the form, and
only call super.validate() if the form was submitted.

--
Wendy

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



RE: Question about Struts validator

2006-06-27 Thread mosho

Thanks David for your reply.

If I call validate method manually, can I still use validator framework and
use the input attribute in the config file to display the errors?

I need to validate only if form is submitted by clicking on a button.
If, yes can you show me with an example how to call validate method in
Action class, execute method.

Thanks
Rosh



-- 
View this message in context: 
http://www.nabble.com/Question-about-Struts-validator-tf1851247.html#a5073203
Sent from the Struts - User forum at Nabble.com.


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



RE: Question about Struts validator

2006-06-26 Thread David Friedman
In your execute method, you can manually call the ActionForm's validate()
method.  The 'validate="true"' attribute/parameter is there for you
convenience - you do not have to use it.

Regards,
David

-Original Message-
From: mosho [mailto:[EMAIL PROTECTED]
Sent: Monday, June 26, 2006 4:20 PM
To: user@struts.apache.org
Subject: Question about Struts validator



Hi All,

I want to validate a form by using struts validator, it is working fine. It
validates the form if I click submit button, and it also validates the form
if I pass it as a url
for example: http://111.22.80.244:8989/eNOI/test.do
I want to validate the form only if I hit submit button not by directly
entering the url.
How can I handle this situation?

Thanks for your help!
Rosh
--
View this message in context:
http://www.nabble.com/Question-about-Struts-validator-t1851247.html#a5054174
Sent from the Struts - User forum at Nabble.com.


-
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]