wood burning stoves 2.0*
The moose likes Struts and the fly likes Property referring to another property Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Property referring to another property" Watch "Property referring to another property" New topic
Author

Property referring to another property

Kjeld Sigtermans
Ranch Hand

Joined: Aug 10, 2006
Posts: 122
Is it possible to have a property in ApplicationResources.properties refer to another property?
I thought I had seen this once somewhere but I am not sure.
For example:

my.property.foo = foo

some.other.property = I am trying to include { my.property.foo } but I don't know how to do that.

Which should result in:
I am trying to include foo but I don't know how to do that.

Is something like that possible?


Kjeld Sigtermans - SCJP 1.4 - SCWCD 1.4
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
probably not exactly what you are looking for, put you can parametrize one property with say



and put the value of another property in when you evaluate it...

btw: i usually find it pretty hard to read / organize / maintain a property file. specially when several coders develop, you'll find inconsistencies en masse, no matter how well organized everything was at the beginning...

would that be clearer if you define those dependencies?

best regards,
jan
Vijendra Babar
Greenhorn

Joined: Jul 28, 2006
Posts: 18
This is what I understood form your description:

You have 2 .proprerties file & Now you want to add values of one key to another key present in .properties file.

In technical terms you have 2 files namely first.properties & second.properties.

Now you want to add value of key (say) label.form1.value from first.propeties to second.properties for key (say) label.form2.value

Yes this possible by using Properties object.

You need to create object of Properties (presnent java.util package).

It contains 2 methods, load() file which laods your .properties file in as Inputstream & another method (.set() not sure ) in OutputStream mode.

You have to first find value using Properties object & set it to another object.

This is bit confusing so Refer Java Doc for more clear idea.

Vijendra.
Kjeld Sigtermans
Ranch Hand

Joined: Aug 10, 2006
Posts: 122
Vijendra, Jan, thanks.
My apologies for not describing my problem more clearly. Both properties are in one .properties file.

The exact implementation that I'd like to achieve is the following:

I have one property file ApplicationResources.properties, containing two keys:

columnname = Last Name
columnname.error = The field '{ some reference to columnname }' is mandatory.

In the form, I add a new ActionError("columnname.error") to the ActionErrors object. At runtime, when not filling in the Last Name, it would be nice if it would say onscreen:

The field 'Last Name' is mandatory.

instead of:

The field '{ some reference to columnname }' is mandatory.

The property is not referred to from a jsp file directly, so I am unable to embed param elements in a bean:message element or so, using an implementation like {1}, right?

Jan, I agree such an implementation will make the file less maintainable, nevertheless I prefer consistence in this case, assuming columnname will change a couple of times during test stage.
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
hi Kjeld,

you are not the first with this problem, so this is ecactly what message-parameters have been built for... :-)

check this out: struts-taglib-doc

Up to five parametric replacements (such as "{0}") may be specified.


hope this helps,
jan
[ August 21, 2006: Message edited by: Jan Groth ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Property referring to another property
 
Similar Threads
Struts: How does indexed data get into a Form Bean?
doubt on two questions..(Topic:: Session Migration & EL)
Connecting to MOM using propertries files
Locate SYSTEM entities when SAX parsing an XML document