You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by " (¯`·.k ! k !.·´¯)" <g_...@yahoo.com> on 2008/06/01 14:41:08 UTC

ActionErrors in execute() method of action

hi ... i m very new to struts and using struts 1.2.9 i have a problem .. 
&nbsp;
simple org.apache.struts.action.ActionFrom&nbsp; has a method validate() that return ActionErrors which can b showed by &lt;html:errors/&gt; in jsp page . but i m using org.apache.struts.action.DynaActionForm instead of ActionForm so i dont have validate() method that would return ActionErrors&nbsp; . so is their any method so that i could return some errors in execute() method of org.apache.struts.action.Action class ...&nbsp; if i have some error came in execute() so how i can show that error using ActionErrors&nbsp; ?????
waiting for&nbsp;replies .... 
thanx.&nbsp;

&nbsp;

Re: ActionErrors in execute() method of action

Posted by Martin <mg...@hotmail.com>.
can you display your code for  validate method
(which should look something like..)
public ActionErrors validate(ActionMapping mapping, HttpServletRequest 
request)
{
.....
  ActionErrors errors = new ActionErrors();
  //populate ActionErrors messages as necessary..
.....
   return errors;
 }

http://struts.apache.org/1.x/struts-core/apidocs/org/apache/struts/action/ActionMessages.html#messages

M-
----- Original Message ----- 
From: "(¯`·.k ! k !.·´¯)" <g_...@yahoo.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Sunday, June 01, 2008 11:04 AM
Subject: Re: ActionErrors in execute() method of action


DynaActionForm.validate() returns ActionErrors but it is null ...
see this code...
&nbsp;
&nbsp;&nbsp;&nbsp; public ActionForward execute(ActionMapping mapping, 
ActionForm&nbsp; form,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
HttpServletRequest request, HttpServletResponse response)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throws 
Exception {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LoginBl bl = new LoginBl();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DynaActionForm loginForm = 
(DynaActionForm) form;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String uname = 
loginForm.getString("uname");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String upass = 
loginForm.getString("upass");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(bl.login(uname,upass))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 
mapping.findForward(SUCCESS);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
ActionErrors errors = loginForm.validate(mapping, request);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
errors.add(null,new ActionMessage("login.incorrect"));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 
mapping.getInputForward();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; }
&nbsp;
when i run the application ... if i give the right user and pass its ok .. 
but if give wrong .. instead of showing me the error on the input page .. it 
gives a NullPointerException....
&nbsp;
&nbsp;


&nbsp;


--- On Sun, 6/1/08, Dave Newton &lt;newton.dave@yahoo.com&gt; wrote:

From: Dave Newton &lt;newton.dave@yahoo.com&gt;
Subject: Re: ActionErrors in execute() method of action
To: "Struts Users Mailing List" &lt;user@struts.apache.org&gt;
Date: Sunday, June 1, 2008, 9:16 AM

--- On Sun, 6/1/08, (¯`·.k ! k !.·´¯) &lt;g_f_g_5@yahoo.com&gt; wrote:
&gt; but im using org.apache.struts.action.DynaActionForm instead of
&gt; ActionForm so i dont have validate() method that would
&gt; return ActionErrors&amp;nbsp; .

What does your version of DynaActionForm.validate() return?

Dave


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


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


Re: ActionErrors in execute() method of action

Posted by " (¯`·.k ! k !.·´¯)" <g_...@yahoo.com>.
@ Martin ... 
ohhhh sorryyy ....&nbsp; actually i just copy pasted the code from IDE to here . so thats why thes &amp;nbsp;'s are coming ..&nbsp; i write it my self again ... 
&nbsp;
public ActionForward execute(ActionMappning mapping,ActionForm form,HttpServletRequest request, HttpServletResponse response) 
throws Exception&nbsp; {
&nbsp;&nbsp; 




--- On Sun, 6/1/08, Dave Newton &lt;newton.dave@yahoo.com&gt; wrote:

From: Dave Newton &lt;newton.dave@yahoo.com&gt;
Subject: Re: ActionErrors in execute() method of action
To: "Struts Users Mailing List" &lt;user@struts.apache.org&gt;
Date: Sunday, June 1, 2008, 11:47 AM

Did you implement a validate method that returns a non-null ActionErrors? If
not, why wouldn't you just create your own instance of an ActionErrors?

http://struts.apache.org/1.2.9/api/org/apache/struts/action/ActionForm.html#validate(org.apache.struts.action.ActionMapping,%20javax.servlet.ServletRequest)

I guess I'm not sure what the issue is; you're calling a method
that's documented to return null and trying to call one of its methods.

Dave

--- On Sun, 6/1/08, (¯`·.k ! k !.·´¯) &lt;g_f_g_5@yahoo.com&gt; wrote:

&gt; From: (¯`·.k ! k !.·´¯) &lt;g_f_g_5@yahoo.com&gt;
&gt; Subject: Re: ActionErrors in execute() method of action
&gt; To: "Struts Users Mailing List" &lt;user@struts.apache.org&gt;
&gt; Date: Sunday, June 1, 2008, 11:04 AM
&gt; DynaActionForm.validate() returns ActionErrors but it is
&gt; null ... 
&gt; see this code...
&gt; &amp;nbsp;
&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; public ActionForward
&gt; execute(ActionMapping mapping, ActionForm&amp;nbsp; form,
&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&gt; HttpServletRequest request, HttpServletResponse response)
&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&gt; throws Exception {
&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&gt; LoginBl bl = new LoginBl();
&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&gt; DynaActionForm loginForm = (DynaActionForm) form;
&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&gt; String uname = loginForm.getString("uname");
&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&gt; String upass = loginForm.getString("upass");
&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&gt; 
&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&gt; if(bl.login(uname,upass))
&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&gt; return mapping.findForward(SUCCESS);
&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&gt; else{
&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&gt; ActionErrors errors = loginForm.validate(mapping, request);
&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&gt; errors.add(null,new
&gt; ActionMessage("login.incorrect"));
&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&gt; return mapping.getInputForward();
&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&gt; 
&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&gt; }
&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&gt; &amp;nbsp;
&gt; when i run the application ... if i give the right user and
&gt; pass its ok .. but if give wrong .. instead of showing me
&gt; the error on the input page .. it gives a
&gt; NullPointerException.... 
&gt; &amp;nbsp;
&gt; &amp;nbsp;
&gt; 
&gt; 
&gt; &amp;nbsp;
&gt; 
&gt; 
&gt; --- On Sun, 6/1/08, Dave Newton
&gt; &amp;lt;newton.dave@yahoo.com&amp;gt; wrote:
&gt; 
&gt; From: Dave Newton &amp;lt;newton.dave@yahoo.com&amp;gt;
&gt; Subject: Re: ActionErrors in execute() method of action
&gt; To: "Struts Users Mailing List"
&gt; &amp;lt;user@struts.apache.org&amp;gt;
&gt; Date: Sunday, June 1, 2008, 9:16 AM
&gt; 
&gt; --- On Sun, 6/1/08, (¯`·.k ! k !.·´¯)
&gt; &amp;lt;g_f_g_5@yahoo.com&amp;gt; wrote:
&gt; &amp;gt; but im using
&gt; org.apache.struts.action.DynaActionForm instead of
&gt; &amp;gt; ActionForm so i dont have validate() method that
&gt; would
&gt; &amp;gt; return ActionErrors&amp;amp;nbsp; .
&gt; 
&gt; What does your version of DynaActionForm.validate() return?
&gt; 
&gt; Dave
&gt; 
&gt; 
&gt; ---------------------------------------------------------------------
&gt; To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
&gt; For additional commands, e-mail:
&gt; user-help@struts.apache.org

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

Re: ActionErrors in execute() method of action

Posted by Dave Newton <ne...@yahoo.com>.
Did you implement a validate method that returns a non-null ActionErrors? If not, why wouldn't you just create your own instance of an ActionErrors?

http://struts.apache.org/1.2.9/api/org/apache/struts/action/ActionForm.html#validate(org.apache.struts.action.ActionMapping,%20javax.servlet.ServletRequest)

I guess I'm not sure what the issue is; you're calling a method that's documented to return null and trying to call one of its methods.

Dave

--- On Sun, 6/1/08, (¯`·.k ! k !.·´¯) <g_...@yahoo.com> wrote:

> From: (¯`·.k ! k !.·´¯) <g_...@yahoo.com>
> Subject: Re: ActionErrors in execute() method of action
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Date: Sunday, June 1, 2008, 11:04 AM
> DynaActionForm.validate() returns ActionErrors but it is
> null ... 
> see this code...
> &nbsp;
> &nbsp;&nbsp;&nbsp; public ActionForward
> execute(ActionMapping mapping, ActionForm&nbsp; form,
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> HttpServletRequest request, HttpServletResponse response)
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> throws Exception {
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> LoginBl bl = new LoginBl();
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> DynaActionForm loginForm = (DynaActionForm) form;
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> String uname = loginForm.getString("uname");
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> String upass = loginForm.getString("upass");
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> if(bl.login(uname,upass))
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> return mapping.findForward(SUCCESS);
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> else{
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> ActionErrors errors = loginForm.validate(mapping, request);
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> errors.add(null,new
> ActionMessage("login.incorrect"));
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> return mapping.getInputForward();
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> }
> &nbsp;&nbsp;&nbsp; }
> &nbsp;
> when i run the application ... if i give the right user and
> pass its ok .. but if give wrong .. instead of showing me
> the error on the input page .. it gives a
> NullPointerException.... 
> &nbsp;
> &nbsp;
> 
> 
> &nbsp;
> 
> 
> --- On Sun, 6/1/08, Dave Newton
> &lt;newton.dave@yahoo.com&gt; wrote:
> 
> From: Dave Newton &lt;newton.dave@yahoo.com&gt;
> Subject: Re: ActionErrors in execute() method of action
> To: "Struts Users Mailing List"
> &lt;user@struts.apache.org&gt;
> Date: Sunday, June 1, 2008, 9:16 AM
> 
> --- On Sun, 6/1/08, (¯`·.k ! k !.·´¯)
> &lt;g_f_g_5@yahoo.com&gt; wrote:
> &gt; but im using
> org.apache.struts.action.DynaActionForm instead of
> &gt; ActionForm so i dont have validate() method that
> would
> &gt; return ActionErrors&amp;nbsp; .
> 
> What does your version of DynaActionForm.validate() return?
> 
> Dave
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org

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


Re: ActionErrors in execute() method of action

Posted by " (¯`·.k ! k !.·´¯)" <g_...@yahoo.com>.
DynaActionForm.validate() returns ActionErrors but it is null ... 
see this code...
&nbsp;
&nbsp;&nbsp;&nbsp; public ActionForward execute(ActionMapping mapping, ActionForm&nbsp; form,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpServletRequest request, HttpServletResponse response)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throws Exception {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LoginBl bl = new LoginBl();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DynaActionForm loginForm = (DynaActionForm) form;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String uname = loginForm.getString("uname");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String upass = loginForm.getString("upass");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(bl.login(uname,upass))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return mapping.findForward(SUCCESS);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ActionErrors errors = loginForm.validate(mapping, request);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; errors.add(null,new ActionMessage("login.incorrect"));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return mapping.getInputForward();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
&nbsp;&nbsp;&nbsp; }
&nbsp;
when i run the application ... if i give the right user and pass its ok .. but if give wrong .. instead of showing me the error on the input page .. it gives a NullPointerException.... 
&nbsp;
&nbsp;


&nbsp;


--- On Sun, 6/1/08, Dave Newton &lt;newton.dave@yahoo.com&gt; wrote:

From: Dave Newton &lt;newton.dave@yahoo.com&gt;
Subject: Re: ActionErrors in execute() method of action
To: "Struts Users Mailing List" &lt;user@struts.apache.org&gt;
Date: Sunday, June 1, 2008, 9:16 AM

--- On Sun, 6/1/08, (¯`·.k ! k !.·´¯) &lt;g_f_g_5@yahoo.com&gt; wrote:
&gt; but im using org.apache.struts.action.DynaActionForm instead of
&gt; ActionForm so i dont have validate() method that would
&gt; return ActionErrors&amp;nbsp; .

What does your version of DynaActionForm.validate() return?

Dave


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

Re: ActionErrors in execute() method of action

Posted by Dave Newton <ne...@yahoo.com>.
--- On Sun, 6/1/08, (¯`·.k ! k !.·´¯) <g_...@yahoo.com> wrote:
> but im using org.apache.struts.action.DynaActionForm instead of
> ActionForm so i dont have validate() method that would
> return ActionErrors&nbsp; .

What does your version of DynaActionForm.validate() return?

Dave


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