Need to create custom taglib similar to bean:message

J

jason.stiles

First off let me just say that while I know "java" pretty well from
about 3-4 years ago, but I am not really up to speed on all the JSP and
Struts things going on but I'm learning as fast as possible :)

That being said, I have been thrown feet first into a new project and
have been asked to do this.

So anyway I am using resource.properties files to store all of our
strings and I have been adding them to our JSP's using the bean:message
taglib.

This works great and I have no problem creating different property
files for multiple languages using localization.

My problem is that the app we are writing is for one company that
operates in different states (OH, IN, etc...) The business logic for
each company is very similar but sometimes the language needs to change
between states. Further confusing the issue is that this one company
has sub companies which operate in multiple states and each company is
very similar. So I have come up with the idea that I would like to use
the "key" element of bean:message to try to create a sort of
localization scheme for the companies and states.

Here is is my idea. I would like to create a taglib that works exactly
like the bean:message taglib except that you pass in key names that are
like "promptname.company.state". The taglib will look for a key named
"promptname.company.state" and if it exists it will return it, if not
it looks for generic key for that company "promptname.company" if that
does not exist it looks for "promptname". If that key does not exist
it returns error or ???key?? as normal.

The idea is that we create a generic base for the application and
customize the prompts from the differences. Seems like a good idea to
me, heck, there may even already be a taglib out there that does this?

My problem is that I don't know where to start with extending the
bean:message tag. Theoretically it wouldn't be a problem to just keep
sending requests and stripping off .company and .state until you found
one.

Can someone point me in the right direction for doing this? This would
really save me some time.

Jason Stiles
(e-mail address removed)
 
R

Roedy Green

Here is is my idea. I would like to create a taglib that works exactly
like the bean:message taglib except that you pass in key names that are
like "promptname.company.state". The taglib will look for a key named
"promptname.company.state" and if it exists it will return it, if not
it looks for generic key for that company "promptname.company" if that
does not exist it looks for "promptname". If that key does not exist
it returns error or ???key?? as normal.
Your locale has three parts , language, country and variant. Java
already has logic to go for the best fit it can get. You can abscond
with the variant level to decide your business logic.

You have to be able to code it as if it were translations of a base
set of strings.

I have not yet experimented to know what happens if after Java has
decided on a resource bundle, if a key is missing it tries the next
best bit, the more general fit until it gets a match, or if it just
gives up.
 
T

Tim B

My problem is that I don't know where to start with extending the
bean:message tag. Theoretically it wouldn't be a problem to just keep
sending requests and stripping off .company and .state until you found
one.


your best bet is to look at the source of MessageTag, particularly the
doStartTag() method. This is probably the only method you would need to
override.
 
O

ozgwei

I vaguely remember that Spring Framework's MVC also provides a tag that
meets your requirements, for error message rendering. You may read
their source code to get some inspiration.
 
J

jason.stiles

I had thought of using the variant as the functionality is identical
and already available. The problem is that I need company and state,
but there is only one variant tag.

"I have not yet experimented to know what happens if after Java has
decided on a resource bundle, if a key is missing it tries the next
best bit, the more general fit until it gets a match, or if it just
gives up."

The keys are treat as whole unique fields so it just gives up.

Thanks for your response
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top