aspose file tools*
The moose likes Struts and the fly likes struts 2 -- name matching when we retrieve attributes from Action class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts 2 -- name matching when we retrieve attributes from Action class" Watch "struts 2 -- name matching when we retrieve attributes from Action class" New topic
Author

struts 2 -- name matching when we retrieve attributes from Action class

ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 375
If an action class has

************
private String name;

public String getMyName() {

return name;
}

// note: there is NOT a "getName()" method in this action class.

..
****************

If this action forwards to a JSP page, then in the JSP page, shall I use ${myName} or ${name} to retrieve the variable "name" defined in the action class ? Again, suppose there is not a "getName()" method in the class. Does struts 2 go by the attribute name or getter method name ?

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Seems like it would have been quicker to try it.

Since the action property is private you access it via "myName".
ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 375
David Newton wrote:Seems like it would have been quicker to try it.

Since the action property is private you access it via "myName".


That's what I found, "myName" should work. But, since there is no such an attribute called "myName" in this class, is it struts 2 snart enough to parse each getter method to find out ? e.g. it "parses" the "getMyName" method name and takes away "get" and keeps "MyName" string and then change the first letter to lower case ? please let me know how things work behind the scene if you can.

Thanks.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

...

OGNL follows JavaBean conventions. If there's a getter named getMyName then "myName" will call the getter. An OGNL statement and a log statement would have shown this.
ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 375
Thanks David
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts 2 -- name matching when we retrieve attributes from Action class