You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Neal Kaiser <ne...@makeastore.com> on 2001/01/02 18:35:59 UTC
Form errors
I probably missed this in the documentation, but if I want to pull out the
error message for a specific field, how would I do it? Let's say I have a
username which was left blank and I create a new ActionError :
errors.add("username",new ActionError("error.username.required"));
Now, in my .jsp, rather than having all the errors displayed with
<form:errors/>, I want to put the
error.username.required error right next to the username field:
<form:text property="username" size="16" maxlength="16"/>
<form:errors username-only>
I don't want it to use errors.header or errors.footer either in this case.
Is that possible?
Thanks.
Re: Form errors
Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Neal Kaiser wrote:
> I probably missed this in the documentation, but if I want to pull out the
> error message for a specific field, how would I do it? Let's say I have a
> username which was left blank and I create a new ActionError :
>
> errors.add("username",new ActionError("error.username.required"));
>
> Now, in my .jsp, rather than having all the errors displayed with
> <form:errors/>, I want to put the
> error.username.required error right next to the username field:
>
> <form:text property="username" size="16" maxlength="16"/>
> <form:errors username-only>
>
> I don't want it to use errors.header or errors.footer either in this case.
>
> Is that possible?
> Thanks.
The ActionErrors.get("username") method will return you an Iterator of all the
error messages recorded against the "username" property -- there could be more
than one. The <form:errors/> tag currently doesn't have any support for this,
and I'm not sure there is a good generic solution that works in every
circumstance, although I'm open to suggestion.
Craig McClanahan
Re: Pre-compiled JSPs in action.xml path=URI possible ??
Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Ron Bolin wrote:
> >
>
> Is struts designed to work with pre-compiled JSPs? Is it possible in struts
> 1.0 to define and
> use classes in the forward path argument rather than JSP as shown below. I am
> interested
> in speeding up the initial screens in our project.
>
> I have been toying with this, bus so far have not been able to get it to work.
>
> Any insight would be appreciated. The example below does not reflect the new
> Struts 1.0
> ActionMappings, but is being presented for clarification.
>
> Example using JSP not pre-compiled.
>
> <!-- Main Administration-->
> <action path="/mainAdmin"
> actionClass="org.hp.awsadmin.action.MainAdminAction"
> formAttribute="mainForm"
> formClass="org.hp.awsadmin.form.MainForm">
> <forward name="success" path="/jsp/awsMain.jsp"/>
> </action>
>
> Example using compiled JSP class.
>
> <!-- Main Administration-->
> <action path="/mainAdmin"
> actionClass="org.hp.awsadmin.action.MainAdminAction"
> formAttribute="mainForm"
> formClass="org.hp.awsadmin.form.MainForm">
> <forward name="success" path="/classes/awsMain"/>
> </action>
>
> Thanks in advance.
>
There is nothing about Struts that would care about precompiled versus not
precompiled JSP pages, but the details of how you set them up depends on the
servlet container you are using. With Tomcat, for example, running the "jspc"
command line tool will compile all your pages, but it will also create a bunch of
<servlet> and <servlet-mapping> tags that need to go into your web.xml file.
In particular (at least for Tomcat), though, the path of a JSP page does *not*
change when you use precompiled pages. The reason this works is that the compiler
generates a servlet mapping for "/jsp/awsMain.jsp" for you -- and, because this is
an exact match, it has higher priority than extension mapping on "*.jsp", which
would send the page back to the JSP servlet.
Try leaving the path for the compiled case the same as the path for the uncompiled
case, and make sure that you've included the necessary stuff in web.xml.
>
> Ron
Craig McClanahan
Re: Pre-compiled JSPs in action.xml path=URI possible ??
Posted by Ron Bolin <rb...@issl.atl.hp.com>.
>
Is struts designed to work with pre-compiled JSPs? Is it possible in struts
1.0 to define and
use classes in the forward path argument rather than JSP as shown below. I am
interested
in speeding up the initial screens in our project.
I have been toying with this, bus so far have not been able to get it to work.
Any insight would be appreciated. The example below does not reflect the new
Struts 1.0
ActionMappings, but is being presented for clarification.
Example using JSP not pre-compiled.
<!-- Main Administration-->
<action path="/mainAdmin"
actionClass="org.hp.awsadmin.action.MainAdminAction"
formAttribute="mainForm"
formClass="org.hp.awsadmin.form.MainForm">
<forward name="success" path="/jsp/awsMain.jsp"/>
</action>
Example using compiled JSP class.
<!-- Main Administration-->
<action path="/mainAdmin"
actionClass="org.hp.awsadmin.action.MainAdminAction"
formAttribute="mainForm"
formClass="org.hp.awsadmin.form.MainForm">
<forward name="success" path="/classes/awsMain"/>
</action>
Thanks in advance.
Ron
Re: Form errors
Posted by Johan Compagner <jc...@j-com.nl>.
Use my ErrorTag attached.
I copied almost from ErrorsTag but only generated it for the property that was set.
I hope this or another one just like it will be in the default struts lib.
(they can use mine attached)
The current implementation isn't used very much on the internet. Users want
to see what the did wrong and where to fix it.
And that's why the ErrorTag is much handier then the ErrorsTag.
If multiply errors are set for one property it will be comma seperated.
johan
> I probably missed this in the documentation, but if I want to pull out the
> error message for a specific field, how would I do it? Let's say I have a
> username which was left blank and I create a new ActionError :
>
> errors.add("username",new ActionError("error.username.required"));
>
> Now, in my .jsp, rather than having all the errors displayed with
> <form:errors/>, I want to put the
> error.username.required error right next to the username field:
>
> <form:text property="username" size="16" maxlength="16"/>
> <form:errors username-only>
>
> I don't want it to use errors.header or errors.footer either in this case.
>
> Is that possible?
> Thanks.
>
>