struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carl Walker <walke...@georgetown.edu>
Subject Re: Simple ActionError question
Date Wed, 25 Feb 2004 16:01:47 GMT
You ActionError constructor takes additional parameters.  Here's a sample from some code that
passes two parameters to a message I'm working
on.  In my example, if the user tries to insert a group with the same name as one in the DB,
an error is thrown and html:errors is used to
display the errors to the user

In the resources.properties file there is the following entry

    errors.unique={0} has already been used as a {1}

There are two parameters I'm passing to the resource.  Since there are many places in the
code where I could get a unique constraint
violation, I pass the field name along with the field name value to prompt the user.

The code follows...
        try {
            dao.insertSomething(groupName)
        }
        catch(SQLException exc) {

            servlet.log("[InsertSomething] - WARNING: error inserting " +
                        groupName + " msg: " + exc.getMessage());

            if( exc.getErrorCode() == 1 ) {  // constraint violation

                ActionErrors errors = new ActionErrors();
                ActionError error = new ActionError( "errors.unique", groupName, "Group Name"
);
                errors.add( ActionErrors.GLOBAL_ERROR, error );
                _request.setAttribute( Globals.ERROR_KEY, errors );

                fwd = new ActionForward( _mapping.getInput() );
            }
        }


Theodosios Paschalidis wrote:

> Hi all,
>
> just a newbie question. I have a PlaceOrderAction and I want to display as an ActionError
the items that were out of stock.
>
> I would like to be able to pass a String to my ActionError. Is there a way to do this
may using Format? Could somebody provide an example?
>
> Suppose I have a string outOfStock = "<UL><LI>title1</LI></UL>"
>
> I want to have an effect equivelant to
> new ActionError("outofstock"));
>                        new ActionError(outOfStock));
>
> if I had new ActionError(error.outofstock));
> and in my resources error.outofstock = {0}
>
> How would I pass my string value?
>
> Thank you for your time,
> Theo


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


Mime
View raw message