You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Sheldon Hearn <sh...@starjuice.net> on 2003/12/13 11:56:28 UTC

Newbie can't get saveErrors() working

Hi folks,

I'm in love with the validation framework included with Struts.  The
fact that I can do validation with regular expressions and have
client-side JavaScript created for me automatically is fantastic.

However, there's one error that I have to catch on the server-side in
some cases: an attempt to create a duplicate entity.  In this case, I'd
like an error message to appear close to the form input for which it
applies.

So I'm creating an ActionError in my Action and saving it as follows:

    } catch (DuplicateDomainAliasError e) {
	ActionErrors errors = new ActionErrors();
	ActionError error = new ActionError("error.domainAliasName.exists");
	errors.add("domainAliasName", error);
	saveErrors(request, errors);
    }

I have error.domainAliasName.exists in my message bundle:

error.domainAliasName.exists=A domain alias with that name already exists.

Because domainAliasName is a property of the ActionForm associated with
the <html:form/> I have in my JSP, I expect the message to be displayed
with the following tag:

<html:errors property="domainAliasName"/>

However, that tag renders the empty string.

Can someone point out what I'm doing wrong here?  I can get the error
displayed at the top of the page by using declarative exception
handling, but the page has a lot of stuff on it, and I'd like the error
displayed close to the form input that it relates to.

Thanks,
Sheldon.

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


Re: Newbie can't get saveErrors() working

Posted by Marcus Peixoto <mp...@pcltda.com.br>.
Instead using <html:errors .....> try to use:

<html:messages id="error" message="false">
<bean:write name="error" />
</html:messages>



Em Sáb, 2003-12-13 às 08:56, Sheldon Hearn escreveu:
> Hi folks,
> 
> I'm in love with the validation framework included with Struts.  The
> fact that I can do validation with regular expressions and have
> client-side JavaScript created for me automatically is fantastic.
> 
> However, there's one error that I have to catch on the server-side in
> some cases: an attempt to create a duplicate entity.  In this case, I'd
> like an error message to appear close to the form input for which it
> applies.
> 
> So I'm creating an ActionError in my Action and saving it as follows:
> 
>     } catch (DuplicateDomainAliasError e) {
> 	ActionErrors errors = new ActionErrors();
> 	ActionError error = new ActionError("error.domainAliasName.exists");
> 	errors.add("domainAliasName", error);
> 	saveErrors(request, errors);
>     }
> 
> I have error.domainAliasName.exists in my message bundle:
> 
> error.domainAliasName.exists=A domain alias with that name already exists.
> 
> Because domainAliasName is a property of the ActionForm associated with
> the <html:form/> I have in my JSP, I expect the message to be displayed
> with the following tag:
> 
> <html:errors property="domainAliasName"/>
> 
> However, that tag renders the empty string.
> 
> Can someone point out what I'm doing wrong here?  I can get the error
> displayed at the top of the page by using declarative exception
> handling, but the page has a lot of stuff on it, and I'd like the error
> displayed close to the form input that it relates to.
> 
> Thanks,
> Sheldon.
> 
> ---------------------------------------------------------------------
> 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