Get struts attribute

I am having a strange issue in my webapp using struts 2.3.3 and spring 3.2.8.

In one of my JSPs, I am trying to get a simple attribute of my action:

JSP:

<%@taglib prefix="s" uri="/struts-tags"%>
<s:property value="getName()" />
<s:property value="name" />

      

I have defined getter getName()

and attribute name in my action.

When I deploy webapp in tomcat 7 sometimes the first property is not shown (completely blank) and the second is correct. I just need to restart tomcat for them to work.

I suspect there is an initialization problem, but I can't find anything in the tomcat logs. I even tried removing the pre-compiled jsps from the tomcat folder to force a recompile.

Has anyone experienced similar issues in the past?

I saw in the rack documentation that they usually used the second method to access the action attribute

<s:property value="name" />

      

I'll try to move all my calls to this method, but I was wondering why sometimes both methods work, and sometimes the first one doesn't work either ...

UPD:

Here is the action code:

public abstract AbstractAction extends ActionSupport implements ServletRequestAware, ServletResponseAware {
    @Autowired
    private PublisherComponent publisherComponent;

    private String name;

    /* ... */

    public String getName() {
        return publisherComponent.getPublisher().getName();
    }
}

      

All my actions are subclasses AbstractAction

.

The name attribute is not used inside the action itself, only in JSP.

publisherComponent.getPublisher()

retrieved an instance of "Publisher" from MySQL, DAO functions are working correctly (device tests succeed and <s:property value="name" />

also return correct name value).

+3


source to share


1 answer


If you use a tag <s:property>

, then it will only work if you only use the property name for getter or setter methods. Internally, it uses a getter method to map your property value. So, the second option is <s:property value="name" />

correctly implemented. Always follow this approach.



0


source







All Articles