Link to home
Start Free TrialLog in
Avatar of mbutu
mbutu

asked on

Struts <html:errors/>

Hi

I'm trying to use the <html:errors/> tag.

- I have a page where I have put the tag.

<html:errors/>

- In struts-config.xml I have defined the resource bundle for the error messages.

<message-resources parameter="tm-struts-messages" null="false"></message-resources>

- In the Struts action I add the error to the request with the following code.

errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("field.empty"));

if (errors.size() > 0) {
saveErrors(request, errors);
}

- The resource bundle contains the key "field.empty".

- But the problem is that on the page I get the following error message (not the text in the resource bundle):

???en_US.field.empty???

<b>What's the problem?</b>
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Try adding in web.xml -- inside the

  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>

bit,

    <init-param>
      <param-name>application</param-name>
      <param-value>tm-struts-messages</param-value>
    </init-param>

and changing:

<message-resources parameter="tm-struts-messages" null="false"></message-resources>

to

<message-resources parameter="resources.application"/>

This is the way I've got mine set up, and it seems to work fine :-)

Hope this helps :-)

Tim
Avatar of mbutu
mbutu

ASKER

Tried it but it did not help.
Hi,

If you are using Struts 1.1, you will need to change the following line

------
<message-resources parameter="tm-struts-messages" null="false"></message-resources>
------

Try to place the resource file under the classes folder, and reference it like a class name as one does it in ResourceBundle class.

E.g.You have placed the file tm-struts-messages.properties in ... WEB-INF/classes/com/temp/resources

then the tage should be like

------
<message-resources parameter="com.temp.resources.tm-struts-messages"></message-resources>
------

Hope this helps

Kartik
Avatar of mbutu

ASKER

Hi

I've checked and the file is in the /WEB-INF/classes folder.
It's not inside a package so therefore I don't put the package name in front of the file name.

Mbutu

ASKER CERTIFIED SOLUTION
Avatar of _marko_
_marko_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mbutu

ASKER

You are fantastic _marko_ I've never met a Struts expert like you. Thank you so much. Now I won't get fired from the project. Can I send you a small gift. I'm considering a couple of hundred dollars as a gift to you _marko_. For saving me and my family. Do you accept PayPal.

Yours truly
Mbutu and family
Hahaha :) You're welcome.



(I know mbutu IRL, he's being sarcastic)