File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Can getters/setters be seperated from the ActionSupport class with a bean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Can getters/setters be seperated from the ActionSupport class with a bean?" Watch "Can getters/setters be seperated from the ActionSupport class with a bean?" New topic
Author

Can getters/setters be seperated from the ActionSupport class with a bean?

E Robb
Ranch Hand

Joined: Aug 27, 2010
Posts: 111
I am trying to seperate the getters/setters from an ActionSupport class for reuse in other Action Classes. I dont seem to be able to retrieve the values set in the Action class in the view. Im sure I am missing something silly.

Below is a simple example of what I am trying to do. If anyone could point out where I might be going wrong it would be greatly appreciated.

Struts.xml:


TestAction.java:


PersonBean:


View Page (testaction.jsp):



The results are in the screen shot.

Why can I not retrieve "Hello World" that is set in my Action class?


[Thumbnail for results.jpg]

Mohana Rao Sv
Ranch Hand

Joined: Aug 01, 2007
Posts: 485

Your action should implement modelDriven interface
http://www.vaannila.com/struts-2/struts-2-example/struts-2-model-driven-action-example-1.html refer this example


ocjp 6 — Feeding a person with food is a great thing in this world. Feeding the same person by transferring the knowledge is far more better thing. The reason is the amount of satisfaction which we get through food is of only one minute or two. But the satisfaction which we can get through the knowledge is of life long.
E Robb
Ranch Hand

Joined: Aug 27, 2010
Posts: 111
MoHaNa RaO wrote:Your action should implement modelDriven interface
http://www.vaannila.com/struts-2/struts-2-example/struts-2-model-driven-action-example-1.html refer this example


This worked but now in my view page both <s:property value="FirstName" /> AND <s:property value="firstName" /> work to retrieve the value "Hello World" Shouldnt only "firstName" retrieve the value? I dont understand I thought Java was case sensitive.

Here is the altered code from my edited example. Can anyone tell me wy both firstName and FirstName retrieve the value?

Getters/Setters Model:



The Action:


The view:



Both property values return "Hello World" Shouldnt one or the other return the value but not both?

Thanks
 
GeeCON Prague 2014
 
subject: Can getters/setters be seperated from the ActionSupport class with a bean?