You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by 艳龙 周 <zy...@yahoo.com.cn> on 2005/01/14 03:03:55 UTC

Why Can't show the errors generated by a ActionForm's validate method

hi, I'm new to struts and I really can't find a way to solve the proplem.
plese help me. thank you so much.
Here is the proplem. I have a input.jsp,a ActionForm and a Action
public class HelloForm extends ActionForm
{
    private String name=null;
    
   public ActionErrors validate(ActionMapping map,HttpServletRequest req)
    {
        ActionErrors err=new ActionErrors();
        if(name.length()<1||name==null)
            err.add("nouser" ,new ActionMessage("jsp.no.user"));
      
        return err;
    }
when name!=null &&name.lengh>1 ,everything is normal ,the Action goto the jsp page I expect
but  when (name.length()<1|| name==null) is true,I think it should go to the input.jsp,and use <html:errors> to display the AcionMessage("jsp.no.user") ..But the proplem comes out:

java.lang.ClassCastException	org.apache.struts.taglib.html.ErrorsTag.doStartTag(ErrorsTag.java:215)	org.apache.jsp.input_jsp._jspx_meth_html_errors_0(input_jsp.java:349)	org.apache.jsp.input_jsp._jspx_meth_html_html_0(input_jsp.java:133)	org.apache.jsp.input_jsp._jspService(input_jsp.java:87)	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)	org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)	org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:1012)	org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:980)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:255)	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)	org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)	javax.servlet.http.HttpServlet.service(HttpServlet.java:709)	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)please help me~






---------------------------------
Do You Yahoo!?
注册世界一流品质的雅虎免费电邮

Re: Why Can't show the errors generated by a ActionForm's validate method

Posted by 艳龙 周 <zy...@yahoo.com.cn>.
thank you, the proplem has been solved. 





---------------------------------
Do You Yahoo!?
注册世界一流品质的雅虎免费电邮

Re: Why Can't show the errors generated by a ActionForm's validate method

Posted by Kishore Senji <ks...@gmail.com>.
On Fri, 14 Jan 2005 10:03:55 +0800 (CST), 艳龙 周 <zy...@yahoo.com.cn> wrote:
> hi, I'm new to struts and I really can't find a way to solve the proplem.
> plese help me. thank you so much.
> Here is the proplem. I have a input.jsp,a ActionForm and a Action
> public class HelloForm extends ActionForm
> {
>    private String name=null;
> 
>   public ActionErrors validate(ActionMapping map,HttpServletRequest req)
>    {
>        ActionErrors err=new ActionErrors();
>        if(name.length()<1||name==null)
>            err.add("nouser" ,new ActionMessage("jsp.no.user"));
> 

<html:errors/> expects ActionError.
So add an ActionError instead of ActionMessage or use <html:messages/>

>        return err;
>    }
> when name!=null &&name.lengh>1 ,everything is normal ,the Action goto the jsp page I expect
> but  when (name.length()<1|| name==null) is true,I think it should go to the input.jsp,and use <html:errors> to display the AcionMessage("jsp.no.user") ..But the proplem comes out:
> 
> java.lang.ClassCastException    org.apache.struts.taglib.html.ErrorsTag.doStartTag(ErrorsTag.java:215)  org.apache.jsp.input_jsp._jspx_meth_html_errors_0(input_jsp.java:349)   org.apache.jsp.input_jsp._jspx_meth_html_html_0(input_jsp.java:133)     org.apache.jsp.input_jsp._jspService(input_jsp.java:87) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)       javax.servlet.http.HttpServlet.service(HttpServlet.java:802)    org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069) org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:1012)     org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:980)
>        org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:255)    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482) org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)   javax.servlet.http.HttpServlet.service(HttpServlet.java:709)    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)please help me~
> 
> 
> ---------------------------------
> Do You Yahoo!?
> 注册世界一流品质的雅虎免费电邮
>

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