2

SCENARIO
I have a group of entities in my app that have independent translation depending of some user choices, different of labels, errors and descriptions that are localized in properties files.

All this entities extends I18N a super class with methods, the important now is this:

public String getName(int language) {
    switch(language) {
    // returns the localized name of the object.
}

In the view, there is a dropbox with some items that change the name depending of another language dropbox in same form (remember, it does not change the language of the application!!). But as long as I can call other getters without parameters, if I try to call getName(language) like item.name(1):

TRIES
I tried in regular way:

<form:options items="${someI18NClass.items}" itemLabel="name(1)" itemValue="id"/> 

But is showing a org.springframework.beans.NotReadablePropertyException:

Bean property 'name(1)' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

And with a bit of workaround:

<c:forEach var="item" items="${someI18NClass.items}">
    <form:option value="${item.id}"><c:out value="${item.name(1)}"/></form:option>
    //                    ↑ OK!                               ↑ PNFE here!
</c:forEach>

But is showing a javax.el.PropertyNotFoundException:

Property 'name' not found in class com.test.SomeI18NClass.

I also tried Constructor Injection but as long as I'm not creating this dropbox items I cannot find the way to use it...

PROBLEM
I know this getter breaks the POJO rules accepting the argument, so:

QUESTION

  • There is some way to pass some parameters to a method in Spring?
  • There is any workaround I can make to I18N class to have a getter without accepting arguments BUT returning the correct result

Any ideas?

Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109

1 Answers1

1

if you are on EL 2.2 , you can do ${item.getName(1)}

Amit.rk3
  • 2,417
  • 2
  • 10
  • 16