Reputation: 31
I'm experiencing a strange issue in my webapp using struts 2.3.3 and spring 3.2.8.
In one of my JSP I'm trying to retrieve a simple attribute of my action:
JSP:
<%@taglib prefix="s" uri="/struts-tags"%>
<s:property value="getName()" />
<s:property value="name" />
I have defined the getter getName()
and the attribute name in my action.
When I deploy the webapp in tomcat 7 sometimes the first property is not displayed (completely empty) whereas the second one is correctly rendered. I just need to restart tomcat to have both working.
I suspect an initialization issue but I can't find anything in tomcat logs. I even tried to remove the precompiled jsps from tomcat folder to force a recompilation.
Has someone experienced a similar issue in the past?
I've seen on struts documentation that they generally used the second method to access action attribute
<s:property value="name" />
I will try to move all my calls to this method but I was wondering why sometimes both methods work and sometimes the first one is failing...
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 of AbstractAction
.
The name attribute is not used inside the action itself, only in the JSP.
The publisherComponent.getPublisher()
retrieved a "Publisher" instance from MySQL, the DAO functions are working correctly (Unit tests succeed and <s:property value="name" />
also returns the correct name value).
Upvotes: 3
Views: 1272
Reputation: 559
If you are using <s:property>
tag then it will work only if you will use property name only not getter or settter methods. Internally it uses getter method to map your property value.
So second one <s:property value="name" />
is correctly implemented. Always follow this approach.
Upvotes: 1