pavel_kazlou
pavel_kazlou

Reputation: 2046

struts2: select tag doesn't like beans with "parameters" property?

I have a base class ReportElement which has type property:

public abstract class ReportElement {
    private ReportElementType type;

    public ReportElementType getType() {
        return type;
    }

    public void setType(ReportElementType type) {
        this.type = type;
    }
}

ReportElementType is just an enum with specified code and i18nKey properties for each element. I have a couple of subclasses of ReportElement, each of them introducing their own properties. One of them is Plot:

public class Plot extends ReportElement {
    public Plot() {
        setType(ReportElementType.PLOT);
    }

    private Collection<Parameter> parameters = new ArrayList<Parameter>();

    public Collection<Parameter> getParameters() {
        return parameters;
    }
}

On some page I needed to display a collection of different ReportElement instances, so I just used struts2 select tag:

<s:select list="myElements" listKey="type.code" listValue="type.i18nKey" size="20"/>

This worked like a charm for every element except for Plot instaces. Instead of invoking getType().getCode() or getType().getI18nKey() plain toString() was invoked on every instance of Plot! After several hours of fun debugging I noticed that during tag evaluation Plot's getParameters() method is called! So it seems struts was trying to evaluate type.code and type.i18nKey using getParameters() method! Failing to do that it ignored the existence of the properties, that I have clearly specified for usage!

After renaming getParameters to a kind of odd name like getParamms the problem gone. Also the problem hasn't occured when using iterator tag together with property tag instead of select tag.

Does anyone have an idea WHY struts select tag uses parameters property of my bean, when I have clearly specified what property should be used? Is it some "cool" feature or a bug?

P.S. I use struts 2.2.3.1

Upvotes: 0

Views: 714

Answers (2)

pavel_kazlou
pavel_kazlou

Reputation: 2046

Found corresponding issue in struts JIRA: https://issues.apache.org/jira/browse/WW-3268

2.3 is specified as fix version.

Upvotes: 0

Dave Newton
Dave Newton

Reputation: 160171

The argument used in all the FreeMarker templates representing a tag's parameters is called parameters. By providing a parameters property that takes precedence, S2 was unable to get to the object on the stack containing the tag's parameters.

It's neither a cool feature nor a bug, it's just how the templates are implemented. Checking the template source may have saved the few hours of debugging.

Upvotes: 2

Related Questions