You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jeff Smith <je...@centralscheduling.net> on 2003/03/08 05:54:13 UTC

[Q] Indexing properties via bean values

In my database, I have country codes. CA for Canada, US for the States, DE for Germany, etc.

I'd like to have "friendly" names associated with each, and I'd like to put them in the application.properties so that they can be localized for different languages.

So I put some entries into the resources file like so:
countryname.CA=Canada
countryname.DE=Germany
countryname.US=United States

And in a request-scope arraylist bean, called countrycodes, I have the list: CA, DE, US...

I'd like to be able to populate a selection list that displays friendly names, and returns the countrycodes as values.

Now I'm trying to figure out how to construct the struts-bean message key to access the long names.

I've tried several approaches and have only succeeded in crashing the servlet compiler.

Have I painted myself into a corner with this approach, or is it doable?

Jefficus

Re: [Q] Indexing properties via bean values

Posted by Jeff Smith <je...@centralscheduling.net>.
Obviously, keeping everything in the bean would be simpler. But I have two
problems with that approach:

1) It complicates localization. If I keep everything in the properties file
I18N is much cleaner.
2) This is just one example of places where database-resident information is
going to be presented to the user. You could also imagine having the same
problem with product names, user roles and a whole whack of other things.
Sooner or later, I'm going to have to tackle bean-based indexing. Might as
well figure it out now.

Jefficus
----- Original Message -----
From: "Rick Reumann" <r...@reumann.net>
>
> I haven't had to tackle this issue, but I was wondering if maybe a
> better approach would be to let the DB handle the proper language names
> as well for the different codes. Then based on whatever locale being
> used your query would make sure to select the appropriate country codes
> and names. In another words I was thinking you'd have a typical bean:
>
> Country {
>   String id; //CA
>   String description; //Canada
> }
>
> But your business logic that would return your Collection of these might
> take a Locale as a parameter so that it would return the Collection of
> Country objects populated with the proper language for the description
> field.
>
> Not sure if this is the best approach to take or not so I'm interested
> to hear what you finally go with.
>
> --
> Rick
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [Q] Indexing properties via bean values

Posted by Rick Reumann <r...@reumann.net>.
On Fri, Mar 07,'03 (09:54 PM GMT-0700), Jeff wrote: 

> In my database, I have country codes. CA for Canada, US for the
> States, DE for Germany, etc.
> 
> I'd like to have "friendly" names associated with each, and I'd like
> to put them in the application.properties so that they can be
> localized for different languages.
> 
> So I put some entries into the resources file like so:
> countryname.CA=Canada
> countryname.DE=Germany
> countryname.US=United States

I haven't had to tackle this issue, but I was wondering if maybe a
better approach would be to let the DB handle the proper language names
as well for the different codes. Then based on whatever locale being
used your query would make sure to select the appropriate country codes
and names. In another words I was thinking you'd have a typical bean:

Country {
  String id; //CA
  String description; //Canada
}

But your business logic that would return your Collection of these might
take a Locale as a parameter so that it would return the Collection of
Country objects populated with the proper language for the description
field. 

Not sure if this is the best approach to take or not so I'm interested
to hear what you finally go with.

-- 
Rick

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org