You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Daniel Kies <da...@gmail.com> on 2006/01/26 22:07:02 UTC

Validation problems

Hello.  I am trying to do some standard validations, but I am failing. Any
ideas why?  I know the errors are getting raised as the request is
forwarding back to the initial page making the request, but the error
messages are not showing on the page.  Any help is appreciated!

Struts config DynaActionForm:
<form-bean name="searchForm" type="org.apache.struts.action.DynaActionForm">
<form-property name="searchString" type="java.lang.String"></form-property>

<action path="/Search" name="searchForm" type="com.actions.SearchAction"
input="/LoadHomePage.do" validate="true">
<forward name="success" path="displaysearchresults.jsp"/>
<forward name="error" path="LoadHomePage.do"/>
</action>


jsp:
<html:form action="/Search">
<html:errors/>
<input type="text" name="searchString" size="30" >
<input type="submit" name="Submit" value="Go">
</html:form>

  if(searchString.equals("kill")){
   ActionErrors errors = new ActionErrors();
   errors.add("errors", new ActionError("errors", "errors"));
   saveErrors(request, errors);

   return mapping.findForward("error");

Re: Validation problems

Posted by Debendra Barik <ba...@yahoo.com>.
Hello,
  I don't know what exactly you are doing, whre you are calling the validation condition.
  But still i have  a copule of alternative for you, just try. Hope your problem will be solved. Because i had same problem and i solved that by applying this teh.
   
  Solution:
  Step1. Your action mapping and form bean looking ok.
   
   <action path="/Search" name="searchForm" type="
com.actions.SearchAction" input="home.jsp" validate="true">
                        <forward name="success" path="
displaysearchresults.jsp"/>
                        <forward name="error" path="home.jsp"/>
                </action>
  
> > Struts config DynaActionForm:
> > <form-bean name="searchForm" type="
> org.apache.struts.action.DynaActionForm">
> > <form-property name="searchString" type="java.lang.String
> "></form-property>

  Step2: is this the page called(home.jsp)if then
  Just use it i have modified your code inside the jsp page.
> > jsp:
> > <html:form action="/Search">
> > 
> > <input type="text" name="searchString" size="30" >
        <html:errors/>
> > <input type="submit" name="Submit" value="Go">
> > </html:form>
   
  Step 3:
  Create an instance of your DynaActionForm in the SearchAction Class
  like example: 
  DynaActionForm dform=(DynaActionForm)form;
  Step4:
  your condition checking appearing wrong, because you cann't directly access the text field defined in the form. So i am suggesting two ways to do this:
  String search=dform.getString("searchString");
  or
  Note: to use bellow method write this statement at the top of your action class(SearchAction) that is:
  import org.apache.commons.beanutils.BeanUtils; then follow step bellow
  String search=(String)PropertyUtils.getSimpleProperty(form,"searchString");
  Step5:
  if(search.equals("kill")){
  ActionMessages errors=new ActionMessages();
  errors.add("searchString", new ActionMessage( "errors.required", "searchString"));
  }
  if(!errors.isEmpty()){
  saveErrors(request,errors);
 }
  return mapping.findForward("error");
    /*
  1. if(dform.get())
> >
> >  if(searchString.equals("kill")){
> >   ActionErrors errors = new ActionErrors();
> >   errors.add("errors", new ActionError("errors", "errors"));
> >   saveErrors(request, errors);
> >
> >   return mapping.findForward("error");
  */


   
  I think now you will able to see your error message in your home page when the searchString field match with the string "kill".
  Note: Make sure your program can able to access your MessageResources.properties file. So the message string for "errors.required"  will be retrieved frorm MessagesResources and it will display on the home.jsp page.
  If still you have problem, then let me know by some more details like action class, enviromnet you are using so i will try to help you out.
  Thanks,
  Debendra.
   
   

			
---------------------------------
 Yahoo! Autos. Looking for a sweet ride? Get pricing, reviews, & more on new and used cars.

Re: Validation problems

Posted by Daniel Kies <da...@gmail.com>.
Niall:

I took your recommendation and removed the action chaning from my struts
config.  I am still not seeing any error text.  Here is my new action
mapping:

                <action path="/Search" name="searchForm" type="
com.actions.SearchAction" input="home.jsp" validate="true">
                        <forward name="success" path="
displaysearchresults.jsp"/>
                        <forward name="error" path="home.jsp"/>
                </action>

On 1/27/06, Niall Pemberton <ni...@gmail.com> wrote:
>
> On 1/26/06, Daniel Kies <da...@gmail.com> wrote:
> > Hello.  I am trying to do some standard validations, but I am failing.
> Any
> > ideas why?  I know the errors are getting raised as the request is
> > forwarding back to the initial page making the request, but the error
> > messages are not showing on the page.  Any help is appreciated!
> >
> > Struts config DynaActionForm:
> > <form-bean name="searchForm" type="
> org.apache.struts.action.DynaActionForm">
> > <form-property name="searchString" type="java.lang.String
> "></form-property>
> >
> > <action path="/Search" name="searchForm" type="com.actions.SearchAction"
> > input="/LoadHomePage.do" validate="true">
> > <forward name="success" path="displaysearchresults.jsp"/>
> > <forward name="error" path="LoadHomePage.do"/>
> > </action>
> >
> >
> > jsp:
> > <html:form action="/Search">
> > <html:errors/>
> > <input type="text" name="searchString" size="30" >
> > <input type="submit" name="Submit" value="Go">
> > </html:form>
> >
> >  if(searchString.equals("kill")){
> >   ActionErrors errors = new ActionErrors();
> >   errors.add("errors", new ActionError("errors", "errors"));
> >   saveErrors(request, errors);
> >
> >   return mapping.findForward("error");
>
> Action chaining is generally not recommended...
>
> http://struts.apache.org/struts-doc-1.2.x/faqs/newbie.html#chaining
>
> ...however, although your input/error is mapped to another action - I
> can't see anything that would prevent your errors being shown. Unless
> your "LoadHomePage" is a redirect? Maybe you could try having your
> input/error mapping straight to a jsp and see if the errors appear
> then? Also, could you show the entry for "LoadHomePage"  in your
> struts-config.xml?
>
> Niall
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Validation problems

Posted by Niall Pemberton <ni...@gmail.com>.
On 1/26/06, Daniel Kies <da...@gmail.com> wrote:
> Hello.  I am trying to do some standard validations, but I am failing. Any
> ideas why?  I know the errors are getting raised as the request is
> forwarding back to the initial page making the request, but the error
> messages are not showing on the page.  Any help is appreciated!
>
> Struts config DynaActionForm:
> <form-bean name="searchForm" type="org.apache.struts.action.DynaActionForm">
> <form-property name="searchString" type="java.lang.String"></form-property>
>
> <action path="/Search" name="searchForm" type="com.actions.SearchAction"
> input="/LoadHomePage.do" validate="true">
> <forward name="success" path="displaysearchresults.jsp"/>
> <forward name="error" path="LoadHomePage.do"/>
> </action>
>
>
> jsp:
> <html:form action="/Search">
> <html:errors/>
> <input type="text" name="searchString" size="30" >
> <input type="submit" name="Submit" value="Go">
> </html:form>
>
>  if(searchString.equals("kill")){
>   ActionErrors errors = new ActionErrors();
>   errors.add("errors", new ActionError("errors", "errors"));
>   saveErrors(request, errors);
>
>   return mapping.findForward("error");

Action chaining is generally not recommended...

http://struts.apache.org/struts-doc-1.2.x/faqs/newbie.html#chaining

...however, although your input/error is mapped to another action - I
can't see anything that would prevent your errors being shown. Unless
your "LoadHomePage" is a redirect? Maybe you could try having your
input/error mapping straight to a jsp and see if the errors appear
then? Also, could you show the entry for "LoadHomePage"  in your
struts-config.xml?

Niall

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Validation problems

Posted by Daniel Kies <da...@gmail.com>.
Either one would work, to be consistent with other struts tags I am using,
html:text is probably better.  This doesn't affect the validation issue.

On 1/26/06, Thomas Garben <tg...@dtcc.com> wrote:
>
> Dan,
>
> Should you be using"
> <html:text
> instead of:
> <input type="text" name="searchString" size="30" >
> <input type="submit" name="Submit" value="Go">
>
> Tom
>
>
>
>
>
> Daniel Kies <da...@gmail.com>
> 01/26/2006 04:07 PM
> Please respond to
> "Struts Users Mailing List" <us...@struts.apache.org>
>
>
> To
> Struts Users Mailing List <us...@struts.apache.org>
> cc
>
> Subject
> Validation problems
>
>
>
>
>
>
> Hello.  I am trying to do some standard validations, but I am failing. Any
> ideas why?  I know the errors are getting raised as the request is
> forwarding back to the initial page making the request, but the error
> messages are not showing on the page.  Any help is appreciated!
>
> Struts config DynaActionForm:
> <form-bean name="searchForm"
> type="org.apache.struts.action.DynaActionForm">
> <form-property name="searchString"
> type="java.lang.String"></form-property>
>
> <action path="/Search" name="searchForm" type="com.actions.SearchAction"
> input="/LoadHomePage.do" validate="true">
> <forward name="success" path="displaysearchresults.jsp"/>
> <forward name="error" path="LoadHomePage.do"/>
> </action>
>
>
> jsp:
> <html:form action="/Search">
> <html:errors/>
> <input type="text" name="searchString" size="30" >
> <input type="submit" name="Submit" value="Go">
> </html:form>
>
>   if(searchString.equals("kill")){
>    ActionErrors errors = new ActionErrors();
>    errors.add("errors", new ActionError("errors", "errors"));
>    saveErrors(request, errors);
>
>    return mapping.findForward("error");
>
>
>

Re: Validation problems

Posted by Thomas Garben <tg...@dtcc.com>.
Dan,

Should you be using"
<html:text 
instead of:
<input type="text" name="searchString" size="30" >
<input type="submit" name="Submit" value="Go">

Tom





Daniel Kies <da...@gmail.com> 
01/26/2006 04:07 PM
Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>


To
Struts Users Mailing List <us...@struts.apache.org>
cc

Subject
Validation problems






Hello.  I am trying to do some standard validations, but I am failing. Any
ideas why?  I know the errors are getting raised as the request is
forwarding back to the initial page making the request, but the error
messages are not showing on the page.  Any help is appreciated!

Struts config DynaActionForm:
<form-bean name="searchForm" 
type="org.apache.struts.action.DynaActionForm">
<form-property name="searchString" 
type="java.lang.String"></form-property>

<action path="/Search" name="searchForm" type="com.actions.SearchAction"
input="/LoadHomePage.do" validate="true">
<forward name="success" path="displaysearchresults.jsp"/>
<forward name="error" path="LoadHomePage.do"/>
</action>


jsp:
<html:form action="/Search">
<html:errors/>
<input type="text" name="searchString" size="30" >
<input type="submit" name="Submit" value="Go">
</html:form>

  if(searchString.equals("kill")){
   ActionErrors errors = new ActionErrors();
   errors.add("errors", new ActionError("errors", "errors"));
   saveErrors(request, errors);

   return mapping.findForward("error");