Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

displaying data - reuse

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks,

In my struts 2 application, I extend ActionSupport, and in my action class it queries a controller to get data from the model. Then I provide a getter on my action so that the data is available to the view.

Problem is, I need to show this data on many pages, So Im finding in a lot of my actionSupport classes I'm duplicating the getter.

For example, I have the following in many of my actions:



Is there a way around this duplication?

Thanks
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, that's the way Java works: it's like crack for people that like to type. For things like this I usually just create another base class if it's functionality used all over the place. Unfortunately, Java provides no trivial mechanism for sharing implementation.
 
Billy Vandory
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:No, that's the way Java works: it's like crack for people that like to type. For things like this I usually just create another base class if it's functionality used all over the place. Unfortunately, Java provides no trivial mechanism for sharing implementation.



Thanks David, for your reply.

Taking it one step further, the content that I'm displaying, that uses that columnData getter, in multiple pages looks as follows:



I was thinking of making a custom tag, or struts component or something that contains that markup so that in the pages I can just use a <me:showColumnData/> tag.. But my problem now is, to use that tag, the columnData has to be in the action (I guess on the ValueStack in struts world?) or the tag will not work. Here are the two options I thought of:

1. The tag would work on every page I need it, if the tag queries the controller instead of having the action do it

2. The tag could just have the columnData passed to it, and it would render the markup

I think #2 is the better way to go, but perhaps there are other options?

Thanks again
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There probably are other options, but personally, I think passing the data would be more in the spirit of how custom tags are supposed to work.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic