0

In a JSP page I got a bean namely School which has a method called getDescription(String Locale). If I pass en_US it will return English text and for fr_CA it will return French text.

I have no problem using fmt tags like: <fmt:message key="school_list.title2"/> for static content but is there a way I can pass parameter for beans so I can use something like: ${school.description} or ${school.description(locale)}?

Are there any good ways to handle this using standard EL and JSTL?

Bogdan
  • 23,890
  • 3
  • 69
  • 61
Jimmy Page
  • 343
  • 1
  • 6
  • 12

3 Answers3

0

Put it into the bean. Add a method getDescription() that calls the existing method with the current Locale.

user207421
  • 305,947
  • 44
  • 307
  • 483
0

Have you tried with #{school.getDescription(locale)} instead?

Community
  • 1
  • 1
Med
  • 628
  • 9
  • 29
0

If you are using JSP 2.2 then you can go for ${school.getDescription(locale)} or as @Med suggested, for a deferred syntax.

If your environment doesn't offer JSP 2.2 then, if you have at least JSP 2.0 then you can wrap a method call inside a generic function that takes your bean, method name to call and list of parameters and reflectively call the method. You then do something of the likes of this: ${f:invoke(bean, 'getDescription', locale)}.

If you are on JSP 1.2 then you can get a similar behavior to the function in JSP 2.0 but using a tag instead (functions were added in JSP 2.0).

Community
  • 1
  • 1
Bogdan
  • 23,890
  • 3
  • 69
  • 61