struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Fletcher, Ken" <ken.fletc...@trs.state.tx.us>
Subject RE: Message resources
Date Thu, 01 Nov 2001 18:15:04 GMT
The property element in html:errors refers to the error you return from a
form's validate method (you can also do this from an Action class, but you
have to add something extra)....

the action mapping section of struts-config.xml file:
.............
<action-mappings>
    <action path="/login"
            type="action.LoginAction"
            name="loginForm"
            scope="request"
            input="/jsp/userLogin.jsp">
        <forward name="notFound" path="/jsp/userLogin.jsp"/>
    </action>
...........

...in the form's validate method:

if (loginUserID == null || loginUserID.equals("")){
ActionErrors errors = new ActionErrors();
errors.add("loginUserID", new ActionError("userID.required"));
return errors;}

...the entry in the resource properties file:

userID.required=You did not enter your user ID

...the jsp would look for the property="loginUserID":

<html:errors property="loginUserID"/>



If you do this in your Action class, be sure to add the ActionErrors object
to the request (the something extra mentioned above) before returning:

.......
ActionErrors errors = new ActionErrors();
errors.add("userNotFound", new ActionError("user.notInSystem"));
request.setAttribute("org.apache.struts.action.ERROR", errors);
return mapping.findForward("notFound");}

.....your resources file would have an entry like this:

user.notInSystem=Could not find your user ID in the System

.....the jsp looks for an error with the property="userNotFound"...

<html:errors property="userNotFound"/>

The errors.header and errors.footer are automatically added (I don't use
them, though).
I'm not sure if this will help you (hope it does)....

-----Original Message-----
From: Justin Piper [mailto:JPiper@bizcotech.com]
Sent: Thursday, November 01, 2001 11:10 AM
To: 'Struts Users Mailing List'
Subject: RE: Message resources


I tried adding

   errors.header=<font color="red">
   errors.footer=</font>

to ApplicationResources.properties, and

   <html:errors property="error.login.password.required"/>
   <html:errors property="password"/>

to login.jsp.  I wasn't sure whether the property attribute referred to a
key in the message resources or to the name of a form element (I suspect the
latter), so I included both.  Both returned an empty string when I attempted
to submit the form without filling out the password form element.

-----Original Message-----
From: Fletcher, Ken [mailto:ken.fletcher@trs.state.tx.us] 
Sent: Thursday, November 01, 2001 10:52 AM
To: 'Struts Users Mailing List'
Subject: RE: Message resources


.......try adding a property value to your <html:errors property="whatever">

-----Original Message-----
From: Justin Piper [mailto:JPiper@bizcotech.com]
Sent: Thursday, November 01, 2001 10:43 AM
To: Struts Users Mailing List
Subject: Message resources


I'm sure I'm missing something obvious, but after a day of trying to solve
this, I'm quite tired of beating my head against the wall.  For some reason
it seems that ActionServlet isn't able to load the message resources for my
application.  I have the following lines in my web.xml file:

   <servlet>
      <servlet-name>action</servlet-name>
      <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
      <init-param>
         <param-name>application</param-name>
         <param-value>ApplicationResources</param-value>
      </init-param>
	<!-- Irrelevant lines snipped -->
      <load-on-startup>2</load-on-startup>
   </servlet>

In the /WEB-INF/classes directory, I have a file named
ApplicationResources.properties, containing the following lines:

   index.title=Index
   error.login.username.required=Username is required
   error.login.password.required=Password is required
   error.login.incorrect=Invalid username/password pair; please try again

If I include '<bean:message key="index.title"/>' in index.jsp and open it in
a web browser, I get a ServletException, "Missing message for key
index.title".  I added some debugging code to index.jsp;

   <%
      String name = "ApplicationResources.properties";
      java.net.URL url = null;
      url = this.getClass().getClassLoader().getResource(name);
      out.println("<code>url</code> is null:" +
         (new Boolean(url == null)).toString() + "<br>");
   %>
   <logic:present name="org.apache.struts.action.MESSAGE"
scope="application">
      Application resources loaded.
   </logic:present>
   <logic:notPresent name="org.apache.struts.action.MESSAGE"
scope="application">
      Application resources not loaded.
   </logic:notPresent>

which produces:

   url is null:true
   Application resources loaded.

The struts-example application functions properly, as do my ActionServlets
(though <html:errors/> always returns an empty string, even if my ActionForm
returns validation errors).  I am at a loss to explain this odd behavior,
and would appreciate any insight you could provide.

--
"Picture the sun as the origin of two intersecting 6-dimensional
hyperplanes from which we can deduce a certain transformational
sequence which gives us the terminal velocity of a rubber duck ..."


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

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

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

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


Mime
View raw message