Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Custom Resource Bundle / Property Extension Library with Struts 2.x

Folks,

At present we use a set of standard properties files with Struts 2.x to provide our I18N functionality - and for the most part, these do exactly what we need them to. However, there are occasions when it would be great to be able to have individual properties reference other properties in the resource bundle, for example:

name.first=John
name.last=Doe
name.full={name.first} {name.last}

I am aware of several extensions to java.util.Properties that provide these sorts of capabilities such as:

  • eproperties: http://code.google.com/p/eproperties/
  • XProperties: http://www2.sys-con.com/itsg/virtualcd/java/archives/0612/mair/index.html

I was wondering if anyone has ever attempted to integrate these somehow into Struts 2.x - is it possible to override the mechanism which handles the parsing of resource bundles?

like image 566
ShaneK Avatar asked Dec 04 '25 23:12

ShaneK


1 Answers

There's nothing like this built-in, but IIRC you can set a text provider via:

<bean type="com.opensymphony.xwork2.TextProvider" name="struts"
     class="com.opensymphony.xwork2.TextProviderSupport" scope="default" />

I've never actually done this, but it's a worthy, interesting experiment.

Properties may include arbitrary OGNL, however–you can fake it (verbosely) in the meantime:

name.first=John
name.last=Doe
name.full=%{getText('name.first')} %{getText('name.last')}

(You may also use ${...}, but I prefer %{...} so it's clear it's OGNL.)

I've bookmarked this question for research, there are several cool ideas here.

like image 100
Dave Newton Avatar answered Dec 07 '25 12:12

Dave Newton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!