You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Denis Wang <dw...@brandmuscle.com> on 2003/07/03 17:48:27 UTC

struts: error/message handling: saveErrors

Hello, all,

I have the following problem:
In ActionA{
	....
                ActionErrors errors = new ActionErrors();
                errors.add( ActionErrors.GLOBAL_ERROR, new ActionError(
"Afailed" ) );
                saveErrors( request, errors );
}

In ActionB{
	....
                ActionErrors errors = new ActionErrors();
                errors.add( ActionErrors.GLOBAL_ERROR, new ActionError(
"Bfailed" ) );
                saveErrors( request, errors );
}

When ActionA returns it will forward the processing to ActionB and then the
"Bfailed" error will override the "Afailed" error.

How can I show both "Afailed" and "Bfailed" error messages?  Thanks a lot!
Denis



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


RE: struts: error/message handling: saveErrors

Posted by Denis Wang <dw...@brandmuscle.com>.
Thanks for your attention.
Note that ActionA and ActionB are totally different classes.
In this case, the 'errors' attached to request in ActionA will get lost in
ActionB if the following statement is executed:
// in ActionB
ActionErrors errors = new ActionErrors();
...
saveErrors( request, errors );


In order that the ActionB remembers the "Afailed" error, i need
functionalities like the following:
In ActionB {
ActionErrors errors = getErrors( request ); // This is the faked code which
should have been enabled by struts
errors.add(...)
saveErrors( request, errors );

Unfortunately struts does not provide such functionalities, I doubt.
Denis
-----Original Message-----
From: Jamie M. Guillemette [mailto:Jamie_Guillemette@av-basesystems.com]
Sent: Thursday, July 03, 2003 11:59 AM
To: Struts Users Mailing List
Subject: Re: struts: error/message handling: saveErrors


we probably need to know more about your code to really answer your
question. But here are few pointers.

when using actionErrors.  note that many functions return boolean by
returning actionErrors.isEmpty();

in these cases if an error was found.. it will not bother to process the
other errors.. ( cause lets face it .. the first error may be the only
reason the next error was caused.... )

if you are using the validate() method. you can achieve this by simply
adding new errors prior to returning.

JMG



----- Original Message -----
From: "Denis Wang" <dw...@brandmuscle.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Thursday, July 03, 2003 11:48 AM
Subject: struts: error/message handling: saveErrors


> Hello, all,
>
> I have the following problem:
> In ActionA{
> ....
>                 ActionErrors errors = new ActionErrors();
>                 errors.add( ActionErrors.GLOBAL_ERROR, new ActionError(
> "Afailed" ) );
>                 saveErrors( request, errors );
> }
>
> In ActionB{
> ....
>                 ActionErrors errors = new ActionErrors();
>                 errors.add( ActionErrors.GLOBAL_ERROR, new ActionError(
> "Bfailed" ) );
>                 saveErrors( request, errors );
> }
>
> When ActionA returns it will forward the processing to ActionB and then
the
> "Bfailed" error will override the "Afailed" error.
>
> How can I show both "Afailed" and "Bfailed" error messages?  Thanks a lot!
> Denis
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>


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




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


Re: struts: error/message handling: saveErrors

Posted by "Jamie M. Guillemette" <Ja...@av-basesystems.com>.
we probably need to know more about your code to really answer your
question. But here are few pointers.

when using actionErrors.  note that many functions return boolean by
returning actionErrors.isEmpty();

in these cases if an error was found.. it will not bother to process the
other errors.. ( cause lets face it .. the first error may be the only
reason the next error was caused.... )

if you are using the validate() method. you can achieve this by simply
adding new errors prior to returning.

JMG



----- Original Message -----
From: "Denis Wang" <dw...@brandmuscle.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Thursday, July 03, 2003 11:48 AM
Subject: struts: error/message handling: saveErrors


> Hello, all,
>
> I have the following problem:
> In ActionA{
> ....
>                 ActionErrors errors = new ActionErrors();
>                 errors.add( ActionErrors.GLOBAL_ERROR, new ActionError(
> "Afailed" ) );
>                 saveErrors( request, errors );
> }
>
> In ActionB{
> ....
>                 ActionErrors errors = new ActionErrors();
>                 errors.add( ActionErrors.GLOBAL_ERROR, new ActionError(
> "Bfailed" ) );
>                 saveErrors( request, errors );
> }
>
> When ActionA returns it will forward the processing to ActionB and then
the
> "Bfailed" error will override the "Afailed" error.
>
> How can I show both "Afailed" and "Bfailed" error messages?  Thanks a lot!
> Denis
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>


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


Re: Centralized Way of Acessing the Form Bean

Posted by AshokD <as...@visualsoft-tech.com>.
Hi,

I need to acess the other forms in Action class not in jsp page.

I seen just now ActionFormBeans.

I think it may solve my problem. I am testing on that.

Thanks & Regards,
Ashok.D
----- Original Message -----
From: "Jamie M. Guillemette" <Ja...@av-basesystems.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Thursday, July 03, 2003 10:05 PM
Subject: Re: Centralized Way of Acessing the Form Bean


> use the struts bean tag to get your form.. it will search all layers of
the
> session.
>
> JMG
>
> ----- Original Message -----
> From: "AshokD" <as...@visualsoft-tech.com>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Sent: Thursday, July 03, 2003 12:23 PM
> Subject: Centralized Way of Acessing the Form Bean
>
>
> Hi,
>
> I have a Session, Request scope beans in my Application.
>
> To acess Session Scope component I am using below logic:
>
> LoginForm lLoginForm = (LoginForm )session.getAttribute("formName");
>
> To acess Request Scope component I am using below logic:
>
> NewLoginForm lNewLoginForm =
> (NewLoginForm )request.getAttribute("formName");
>
>
>
> If i change the scope in configuration(strut-config.xml) I need to change
my
> Action classes also (where ever I am acessing the form).
>
> Their is any centralized Way of acessing the Form Bean is their ?
>
> like:
>
> Acessing all beans from request instead of session and request.
>
> Thanks in Advance,
> Ashok.D
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


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


Re: Centralized Way of Acessing the Form Bean

Posted by "Jamie M. Guillemette" <Ja...@av-basesystems.com>.
use the struts bean tag to get your form.. it will search all layers of the
session.

JMG

----- Original Message -----
From: "AshokD" <as...@visualsoft-tech.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Thursday, July 03, 2003 12:23 PM
Subject: Centralized Way of Acessing the Form Bean


Hi,

I have a Session, Request scope beans in my Application.

To acess Session Scope component I am using below logic:

LoginForm lLoginForm = (LoginForm )session.getAttribute("formName");

To acess Request Scope component I am using below logic:

NewLoginForm lNewLoginForm =
(NewLoginForm )request.getAttribute("formName");



If i change the scope in configuration(strut-config.xml) I need to change my
Action classes also (where ever I am acessing the form).

Their is any centralized Way of acessing the Form Bean is their ?

like:

Acessing all beans from request instead of session and request.

Thanks in Advance,
Ashok.D


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


Re: Centralized Way of Acessing the Form Bean

Posted by Kris Schneider <kr...@dotech.com>.
As with most things in Struts, the key abstraction is the action mapping. If you
know the path for a particular mapping, you should be good to go (untested):

public static ActionForm getActionForm(String mappingPath,
                                       ServletContext context) {
  ActionForm form = null;

  ConfigHelper helper = new ConfigHelper();
  helper.setApplication(context);
  ActionMapping mapping = helper.getActionMapping(mappingPath);

  if (mapping != null) {
    String formAttribute = mapping.getAttribute();
    if (formAttribute != null) {
      if ("session".equals(mapping.getScope())) {
        HttpSession session = request.getSession(false);
        if (session != null) {
          form = (ActionForm)session.getAttribute(formAttribute);
        }
      } else {
        form = (ActionForm)request.getAttribute(formAttribute);
      }
    }
  }

  return form;
}

Quoting AshokD <as...@visualsoft-tech.com>:

> Hi,
> 
> I have a Session, Request scope beans in my Application.
> 
> To acess Session Scope component I am using below logic:
> 
> LoginForm lLoginForm = (LoginForm )session.getAttribute("formName");
> 
> To acess Request Scope component I am using below logic:
> 
> NewLoginForm lNewLoginForm = (NewLoginForm
> )request.getAttribute("formName");
> 
> 
> 
> If i change the scope in configuration(strut-config.xml) I need to change my
> Action classes also (where ever I am acessing the form).
> 
> Their is any centralized Way of acessing the Form Bean is their ?
> 
> like:
> 
> Acessing all beans from request instead of session and request.
> 
> Thanks in Advance,
> Ashok.D

-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

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


Centralized Way of Acessing the Form Bean

Posted by AshokD <as...@visualsoft-tech.com>.
Hi,

I have a Session, Request scope beans in my Application.

To acess Session Scope component I am using below logic:

LoginForm lLoginForm = (LoginForm )session.getAttribute("formName");

To acess Request Scope component I am using below logic:

NewLoginForm lNewLoginForm = (NewLoginForm )request.getAttribute("formName");



If i change the scope in configuration(strut-config.xml) I need to change my Action classes also (where ever I am acessing the form).

Their is any centralized Way of acessing the Form Bean is their ?

like:

Acessing all beans from request instead of session and request.

Thanks in Advance,
Ashok.D

RE: struts: error/message handling: saveErrors

Posted by Denis Wang <dw...@brandmuscle.com>.
Thanks a lot.  it works for me.
Denis

-----Original Message-----
From: Varun Garg [mailto:varun_garg@yahoo.com]
Sent: Thursday, July 03, 2003 11:55 AM
To: 'Struts Users Mailing List'
Subject: RE: struts: error/message handling: saveErrors


Instead of doing a new ActionErrors I have a function in my base Action
(U can just put it in the action that your are working on Baction).

    public ActionErrors getErrors(HttpServletRequest request){
        if (request.getAttribute(ERROR_KEY) != null) {
            return (ActionErrors) request.getAttribute(ERROR_KEY);
        }
        return new ActionErrors();
    }

Use this inside the execute.
        ActionErrors errors = getErrors(request);

 
Varun

-----Original Message-----
From: Denis Wang [mailto:dwang@brandmuscle.com] 
Sent: Thursday, July 03, 2003 10:48 AM
To: Struts Users Mailing List
Subject: struts: error/message handling: saveErrors


Hello, all,

I have the following problem:
In ActionA{
	....
                ActionErrors errors = new ActionErrors();
                errors.add( ActionErrors.GLOBAL_ERROR, new ActionError(
"Afailed" ) );
                saveErrors( request, errors );
}

In ActionB{
	....
                ActionErrors errors = new ActionErrors();
                errors.add( ActionErrors.GLOBAL_ERROR, new ActionError(
"Bfailed" ) );
                saveErrors( request, errors );
}

When ActionA returns it will forward the processing to ActionB and then
the "Bfailed" error will override the "Afailed" error.

How can I show both "Afailed" and "Bfailed" error messages?  Thanks a
lot! Denis



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



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




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


RE: struts: error/message handling: saveErrors

Posted by Varun Garg <va...@yahoo.com>.
Instead of doing a new ActionErrors I have a function in my base Action
(U can just put it in the action that your are working on Baction).

    public ActionErrors getErrors(HttpServletRequest request){
        if (request.getAttribute(ERROR_KEY) != null) {
            return (ActionErrors) request.getAttribute(ERROR_KEY);
        }
        return new ActionErrors();
    }

Use this inside the execute.
        ActionErrors errors = getErrors(request);

 
Varun

-----Original Message-----
From: Denis Wang [mailto:dwang@brandmuscle.com] 
Sent: Thursday, July 03, 2003 10:48 AM
To: Struts Users Mailing List
Subject: struts: error/message handling: saveErrors


Hello, all,

I have the following problem:
In ActionA{
	....
                ActionErrors errors = new ActionErrors();
                errors.add( ActionErrors.GLOBAL_ERROR, new ActionError(
"Afailed" ) );
                saveErrors( request, errors );
}

In ActionB{
	....
                ActionErrors errors = new ActionErrors();
                errors.add( ActionErrors.GLOBAL_ERROR, new ActionError(
"Bfailed" ) );
                saveErrors( request, errors );
}

When ActionA returns it will forward the processing to ActionB and then
the "Bfailed" error will override the "Afailed" error.

How can I show both "Afailed" and "Bfailed" error messages?  Thanks a
lot! Denis



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



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