• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts making me nuts :)

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After a variety of problems, starts and stops i'm now actually recieving some messages back from my action form but apparently it can't find the resources....

Please take a look at the following and let me know if you have any ideas... thanks in advance...

************************************************************************
Submit1.jsp

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-form.tld" prefix="form" %>
<html>
<head>
<title>Struts Number One Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<%@ page language="java"%>
<body>
<html:errors/>
<html:form action="/testing.do" focus="FirstName">
<table width="500" border="0" cellspacing="0" cellpadding="5">
<tr>
<td>First Name:</td>
<td><html:text property="firstName"/></td>
</tr>
<tr>
<td>Last Name:</td>
<td><html:text property="lastName"/></td>
</tr>
<tr>
<td>Address:</td>
<td><html:text property="address"/></td>
</tr>
<tr>
<td>Address 2:</td>
<td><html:text property="address2"/></td>
</tr>
<tr>
<td>City:</td>
<td><html:text property="city"/></td>
</tr>
<tr>
<td>Province/State:</td>
<td><html:text property="provState"/></td>
</tr>
<tr>
<td>Country:</td>
<td><html:text property="country"/></td>
</tr>
<tr>
<td>Postal/Zip:</td>
<td><html:text property="postalZip"/></td>
</tr>
<tr>
<td>Phone:</td>
<td><html:text property="phone"/></td>
</tr>
<tr>
<td>Email:</td>
<td><html:text property="email"/></td>
</tr>
<tr>
<td colspan="2"><html:submit value="submit"/></td>
</tr>
</table>
</html:form>
</body>
</html>


*******************************************************************
struts-config.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>

<form-beans>
<form-bean name="infoForm" type="com.x.struts.InfoForm"/>
</form-beans>

<action-mappings>
<action path="/testing"
type="com.x.struts.InfoAction"
name="infoForm"
scope="request"
validate="true"
input="/Submit1.jsp">
</action>
</action-mappings>
<message-resources parameter="/WEB-INF/classes/Eng_Resources" null="false"/>
</struts-config>


******************************************************************

this is what is being printed out at the top of the form when it is returned


???en_US.validate.FirstName.incomplete???en_US.validate.Address.incomplete???en_US.validate.Phone.incomplete???en_US.validate.Email.incomplete???en_US.validate.LastName.incomplete???

*******************************************************************

I am using messages.GLOBAL_MESSAGE as the key when i add it to the action error collection (how exactly do i get those messages out on the jsp side or does html:errors do it for me?)

*******************************************************************

Eng_Resources.properties file is placed in the /WEB-INF/classes/ directory

validate.FirstName.incomplete=<LI>Please input your first name.</LI>
validate.LastName.incomplete=<LI>Please input your last name.</LI>
validate.Address.incomplete=<LI>Please input your Address.</LI>
validate.Phone.incomplete=<LI>Please input your Phone.</LI>
validate.Email.incomplete=<LI>Please input a valid email address.</LI>

********************************************************************

any thoughts would be appreciated
[ May 22, 2005: Message edited by: Billy Bob ]
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

The "???XXX???" messages appear because Struts couldnt find the appropriate propertie file.

As far as I know, in the "message-resources" tag, the option "parameter" indicate in which package the resource will be found.

So, you dont need to specify "/WEB-INF/classes/" here.

For exemple, just type parameter="Eng_Resources" to indicate that you want Struts to search for the prop file in the root directory of your classes which is your /WEB-INF/classes/ directory by default.

Or type parameter="my.package.Eng_Resources" if you prefer that Struts search for the Eng_Resources.propertie file in the package you want which is /WEB-INF/classes/my/package/ directory.

Hope it helps....
 
Billy Bob
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
tried it but it didn't work... actually tried a number of different things but i'm recieving the same messages at the top... any other thoughts would be appreciated.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try renaming your message resources file ApplicationResources_en_US.properties or simply ApplicationResources.properties, and changing the entry in the <message-resources> tag in the struts-config file. These file names are expected to follow a standard naming convention with <language code>_<country code> appended to the end of the file name before it's extension. If you're not using internationalization features, it's best just to leave it at the default name, which is ApplicationResources.properties.
 
Billy Bob
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think the naming of the resource is the problem... i tried everything that was suggested but none of it's working... why is it that the resource that i am trying to access i.e. validate.Address.incomplete is prefaced by en_US when it is printed out?... is there something that has to be set in the web.xml file that i'm missing (i.e. an init parameter that specifies the existance of resources?) or is it because i am using the ActionErrors GLOBAL_MESSAGE as the key when i'm populating in the ActionForm... the following is the web.xml file that i'm using...

once again thanks for your time but i think it lies somewhere other then the naming of the resource.

******************************************************************
web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app>

<!-- Action Servlet Configuration -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>

<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>


<!-- Action Servlet Mapping -->

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>


<!-- Struts Tag Library Descriptors -->
<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/WEB-INF/struts-form.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-form.tld</taglib-location>
</taglib>


</web-app>
[ May 23, 2005: Message edited by: Billy Bob ]
 
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
are you setting your locale explicitly in your code? the locale may be incorrectly set (e.g using locale instead of language locale or vice versa).

you are also missing <html:html locale="true"> on the top of your jsp if you are doing multiple resource files for multiple languages. this html:html tag generates the 'lang' attribute that is required for struts to locate the proper resource file.
 
Billy Bob
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not trying to do multiple resources based on locale but it appears that the resource key that it is trying to find is en_US.validate.FirstName.incomplete when the resource that i'm calling is simply validate.FirstName.incompleteb (why is it prefacing it)... i've put it in ApplicationResources and ApplicationResources_en_US properties files, i've prefaced the key=value pairs in the resource file with en_US. to see if they'll match... i just added the locale key that you mentioned and still the same bloody error messages... this is making me absolutely nuts...

do i have to do more then simply start and stop the local tomcat server? does it have anything to do with the fact that i am using the ActionErrors GLOBAL_MESSAGE value as the key for all my values?

I've put the following in my servlet parameters in web.xml

<init-param>
<param-name>application</param-name>
<param-value>ApplicationResources</param-value>
</init-param>

This is the message resource portion of my struts-config.xml file

<message-resources parameter="ApplicationResources" null="false"/>

and the items mentioned above are in both ApplicationResources.properties and ApplicationResources_en_US.properties files in the /WEB-INF/classes directory.


********************************************************************
my ActionForm

public org.apache.struts.action.ActionErrors validate(org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest request) {
int confirm = 0;
com.x.validation.Validate validateThis = new com.x.validation.Validate();
org.apache.struts.action.ActionErrors messages = new org.apache.struts.action.ActionErrors();

if(request.getParameter("firstName").trim().length() == 0){
confirm += 1;
messages.add(messages.GLOBAL_MESSAGE, new org.apache.struts.action.ActionMessage("validate.FirstName.incomplete"));
}
if(request.getParameter("lastName").trim().length() == 0){
confirm += 1;
messages.add(messages.GLOBAL_MESSAGE, new org.apache.struts.action.ActionMessage("validate.LastName.incomplete"));
}
if(request.getParameter("address").trim().length() == 0){
confirm += 1;
messages.add(messages.GLOBAL_MESSAGE, new org.apache.struts.action.ActionMessage("validate.Address.incomplete"));
}
if(request.getParameter("phone").trim().length() == 0){
confirm += 1;
messages.add(messages.GLOBAL_MESSAGE, new org.apache.struts.action.ActionMessage("validate.Phone.incomplete"));
}
if(!validateThis.email(request.getParameter("email"))){
confirm += 1;
messages.add(messages.GLOBAL_MESSAGE, new org.apache.struts.action.ActionMessage("validate.Email.incomplete"));
}

if(confirm > 0){
return messages;
} else {
return null;
}

}

***********************************************************************
why can't we just state everything in a bloody java class... at least the errors would give me something to track down i'm praying for a null pointer exception right now
[ May 23, 2005: Message edited by: Billy Bob ]
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a way to tell whether or not it's a problem with your resource file. Put the following line somewhere in your jsp just as a test:

<bean:message key="validate.FirstName.incomplete" />

If you get the same message before you even try to submit the form, then you know for sure that struts can't find your message resource, and that the problem has nothing to do with your validate() method.

If you will do exactly the following, I believe it will solve your problem:

  • Rename the file as I previously suggested
  • Put the properties file in a package (directory structure) all by itself. Any package name will do (e.g. com.myCompany.myapp.resources) and make sure that directory structure exists in your /WEB-INF/classes directory
  • In your struts-config.xml file <message-resourcs parameter="com.myCompany.myapplication.resources.ApplicationResources" />


  • [ May 23, 2005: Message edited by: Merrill Higginson ]
     
    Billy Bob
    Greenhorn
    Posts: 21
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    i did get the same message before i submitted but again changing the directory and file name didn't change it... i do truly appreciate everyones time and if someone has another 15min to spare you can download a zip of the directory i'm using at www.andymellett.com/strutsTests.zip ... this has been driving me nuts for a couple of days and i'm sure its something small, mind you it could also be the tomcat version i'm using, or some config issue in there who knows... if you would care to take a look at the files and let me know what you think i'd appreciate it... do note that i haven't coded anything in the Action simply because it was the form validation using the ActionForm that i was trying out.

    thanks again for your time
    [ May 23, 2005: Message edited by: Billy Bob ]
     
    Sheriff
    Posts: 6450
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    "Billy Bob",

    Welcome to JavaRanch. We don't have many rules here, but we do have a naming policy which we try to strictly enforce. Please re-read this document and edit your display name in order to comply. Thanks in advance, and we look forward to seeing you around the Ranch.
     
    Merrill Higginson
    Ranch Hand
    Posts: 4864
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Andy,

    I downloaded your zip file, and was able to get it working by doing the following:

  • The ApplicationResources_en_US.properties file you sent was a binary object my text editor couldn't read. It should be a simple text file, not a compiled Properties object. I created a new text file named ApplicationResources_en_US.properties and added the messages from your first posting.
  • In the struts-config.xml file, I changed the messages-resources entry to: <message-resources parameter="com.andymellett.resources.ApplicationResources_en_US" null="false"/>
  • In the validate() method of InfoForm, I changed all references of ActionMessage to ActionError


  • Try doing these things with your application, and see if it works
     
    Billy Bob
    Greenhorn
    Posts: 21
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    bloody hell... i could open that file with whatever i wanted, notepad, wordpad, etc... i must have accidentally saved it as unicode when i created it... i hate stuff like that ... all i had to do was recreate that file... thanks so much for your help and time...

    fyi as of struts 1.2 ActionError has been depreciated and as i understand it they will be removing it in 1.3...

    thanks again so much... i was wondering why i was going crazy
     
    Franck Tranchant
    Ranch Hand
    Posts: 75
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Whaow, ApplicationResources.properties file as a binary file ! :roll:
    I would never have thought of it !!
    Congrats Merrill !!
     
    Ranch Hand
    Posts: 83
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi,
    I am not sure whether my reply will help you.Still let me give a try.
    Basically in a struts application we will have a basic messageResources property file, say ApplicationResources.properties . In you struts-config.xml you have to map this into your struts-config.xml file as
    <message-resources parameter="ApplicationResources.properties"/> If there is any package structure for the property file say "org.resources.ApplicationResources" then the mapping will be as follows
    <message-resources parameter="org.resources.ApplicationResoures"/>
    When you handle locale for internationalization, set the locale and provide corresponding property file in the same location of the default one with the corresponding language and country code as
    ApplicationResources_en_US.properties( for language english and country US)
    In your JSP you have to set <html:html locale="true">.

    Hope this will help you.
    You can check ResourceBundle class of Java and MessageResources class of Struts for your further reference.

    All the best
     
    She said she got a brazillian. I think owning people is wrong. That is how I learned ... tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic