aspose file tools*
The moose likes Struts and the fly likes Resource Bundle files by Modules setup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Resource Bundle files by Modules setup " Watch "Resource Bundle files by Modules setup " New topic
Author

Resource Bundle files by Modules setup

Benson Fung
Ranch Hand

Joined: Apr 10, 2003
Posts: 211
Dear all,

Here is the scenario :

I have two resource bundles files, ApplicationResources-co.properties and ApplicationResources-po.properties, for co modules and po modules respectively. And there is ApplicationResources.properties for default.

And I have two struts-config.xml files for the above two modules, which is struts-co-config.xml and struts-po-config.xml file.

The problem right now, struts cannot find out the name/value mapping in ApplicationResources-po/co.properties. It only searches in the default file, ApplicationResources.properties.

can anyone how I should config. so that struts can also search the key in the other two resources bundle files?

I am using struts 1.1


Thanks
Benson
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Inside your Web Module, take WSAD as an example, you should have 2 directories: JavaSource and WebContent.

You need to create your own package or directory inside JavaSource, say, abc, and all Resource files are located inside abc.

Then, in the WebContent directory, the struts-config.xml and tiles-defs.xml are there. And inside the tiles-defs.xml, you can specify the resource files in the master layout by:


Thus, the Struts and Tiles can be referred to the messages inside the resource files.

But, it may with different cases for different IDEs, so, you may need to check with your own IDE setting.

Hope this help.

Nick


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Benson Fung
Ranch Hand

Joined: Apr 10, 2003
Posts: 211
Nicholas, it seems you didn't answer the question.

My question is there are two Resource Bundle files in the two modules' struts-config.xml files respectively. The problem right now is it cannot look up the messages at the correct resources bundle file.

How can I fix it?


Thanks
Benson
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
It is because you did not specify which resource files are going to be used, and the files are not placed in the correct directory.

As my example stated, you can see that, in WSAD, the resource files are NOT necessary to be with the same directory of the struts-config file. We put the struts-config.xml files inside WebContent directory, while we put the resource files inside the JavaSource directory.

In this case, if you need to use the resource files, you need to use Tiles. Did you setup all stuffs correctly according to your IDE setting?

In addition, in the struts-config.xml, you need to have the location of the resource bundle:

This resource points to the JavaSource directory in WSAD.

and the Tiles plug-in definition, if you need:


Have you specified the <message-resources> tag inside your struts-config.xml?

Nick
[ May 20, 2004: Message edited by: Nicholas Cheung ]
Benson Fung
Ranch Hand

Joined: Apr 10, 2003
Posts: 211
ok! Let me make it clear.

There are two struts-config.xml files,

1. struts-co-config.xml
2. strtus-po-config.xml

both of these files are in /WEB-INF/conf folder.

There are also two resource bundle files, ApplicationResources-co.xml, ApplicationResources-po.xml. Both files are in /WEB-INF/classes/com/lcl/cpb/resources folder.

In struts-co-config.xml file,

The configuration is

<message-resource parameters="com.lcl.cpb.resources.ApplicationResources-co" />

In strtus-po-config.xml file,

the configuration is

<message-resource parameters="com.lcl.cpb.resources.ApplicationResources-po" />

I am using Eclipse. But I don't think it is IDE problem. I think it must be the configuration problem that I don't know how to set.


Thanks for your help, Nicholas.


Benson
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982

<message-resource parameters="com.lcl.cpb.resources.ApplicationResources-co" />

Is this a typo or the config. really look like this?
The tag name should be message-resources, NOT message-resource
and the attribute should be parameter, NOT parameters.

Nick
[ May 20, 2004: Message edited by: Nicholas Cheung ]
Benson Fung
Ranch Hand

Joined: Apr 10, 2003
Posts: 211
It is just typo. No problem. Anyway, the whole thing is like that.


Benson
Benson Fung
Ranch Hand

Joined: Apr 10, 2003
Posts: 211
Yes, it is just typo.

Anyway, do you know how to fix it?


Benson
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Your modules should not look for the default .properties unless the modules' struts-configs define the default .properties in mess-res.

The problem right now, struts cannot find out the name/value mapping in ApplicationResources-po/co.properties. It only searches in the default file, ApplicationResources.properties.

Could you be more specific about how struts is trying to find them?
Where exactly is your app referencing them?

For any given user session, Struts will only think in one module at a time. If your app has not SwitchActioned to the co module, struts will not use the mess-res defined for the co module.
If the location that references the co.properties can't find it, my first thought is that the session was not SwitchActioned to use the co module.


A good workman is known by his tools.
Benson Fung
Ranch Hand

Joined: Apr 10, 2003
Posts: 211
ok!

scenario :

In struts-co-config.xml, it defines :
<message-resouces key="CO_MESSAGE_KEY" parameter="com.lcl.cpb.resources.ApplicationResourcesCO"/>

In struts-po-config.xml, it defines :
<message-resources key="PO_MESSAGE_KEY" parameter="com.lcl.cpb.resourecs.ApplicationResourcesPO"/>

In web.xml

<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/conf/struts-config.xml</param-value>
</init-param>

<init-param>
<param-name>config/co</param-name>
<param-value>/WEB-INF/conf/struts-co-config.xml</param-value>
</init-param>
<init-param>
<param-name>config/po</param-name>
<param-value>/WEB-INF/conf/struts-po-config.xml</param-value>
</init-param>

in the JSP file,

<bean:message bundle="CO_MESSAGE_KEY" key="app.createCustOrder"/>

The error message :

Cannot look up for CO_MESSAGE_KEY.(or similar meaning)

Please help

THanks
Benson
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
Geez, what a bad thread -- everybody not understanding everybody. Fun to read, but yikes! Anyhooooo, basically there's a problem with Struts allowing resource bundles to be defined by "child" modules. Define them as part of the default config file and leave them out of the others.

How's that for understanding?


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Benson Fung
Ranch Hand

Joined: Apr 10, 2003
Posts: 211
Nathaniel,

Do you think it is struts' bug or somehow there are some tricky things hidden behind that we don't know?

Benson
 
 
subject: Resource Bundle files by Modules setup