Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Property referring to another property

 
Kjeld Sigtermans
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic