Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6900401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:32:30+00:00 2026-05-27T07:32:30+00:00

I have been working with a small project recently which involves Struts 2 and

  • 0

I have been working with a small project recently which involves Struts 2 and Spring 3 and my colleague had written very BAD code:

We have to implement two modules of similar functionalities: the both needs to list/add/show/update/delete Java Bean object, and those two Java Bean object has many fields in common, they all have id/content/image_url/created_time/user, the only difference is one bean has 2 fields to store offsets in created_time and the other has to store start_time and end_time.

So my colleague decided to implement one of them in one struts Action class and copy the code and made some small changes then he had another Action class in place.

I am struggling to fix his mistake, what design pattern or practice can solve my problem?

ADD:

I have tried to make those two Action classes extend the same base class, unfortunately, Struts 2 seem to ignore setters/getters of parent classes, and you can’t use generic types either because again, Struts 2 won’t know which class to instantiate and give to the setters in Action classes.

I want to reduce the repeated code, but because of those 2 problems stated above, I ended up making even more repeated code and much too complicated class structure which is on the edge of being broken.

ADD 2:

I tested the following code using stuts2-json-plugin(because it’s easier to observe data in JSON format):

struts.xml:

<package name="inherit" namespace="/inherit" extends="json-default">
        <action name="base" method="doStuff" class="com.carllee.exp.BaseAction">
            <result type="json">
                <param name="excludeNullProperties">true</param>
            </result>
        </action>
        <action name="extended" method="doStuff" class="com.carllee.exp.ExtendedAction">
            <result type="json">
                <param name="excludeNullProperties">true</param>
            </result>
        </action>
</package>

the Java code

package com.carllee.exp;

import com.carllee.exp.bean.Message;
import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport {

    private Message message; // and getter/setter
    private String text;     // and getter/setter

    public String doStuff() {
        return SUCCESS;
    }

}

child class:

package com.carllee.exp;

public class ExtendedAction extends BaseAction {

}

if I run this test and go to http://localhost:8080/struts2-exp/inherit/base?message.content=hello, the result would be:

{"message" : {"content":"hello"}}

if I go to http://localhost:8080/struts2-exp/inherit/extended?message.content=hello, the result would be:

{}

and there would be warnings in the console

This is why I say Struts 2 ignores setters/getters in parent class.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:32:30+00:00Added an answer on May 27, 2026 at 7:32 am
    • Subclass the action and add the other properties?
    • Use the same action but different views?
    • Make one bean with all three fields, different views, default when not used?
    • Use ModelDriven and decide which model to instantiate based on a single action’s "method" configuration?
    • Etc…

    Lots of options. Which is “best” depends on details we don’t have.

    If that’s the extend of BAD code you have to deal with, consider yourself lucky–this sounds trivial to refactor. What’s the actual struggle?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working through a very small-scale WPF project in order to familiarize
I have been working with Struts for some time, but for a project I
I am working on a small project which involves a dictionary based text searching
I have been working on a small project on recent delived ASP.NET MVC 3
I have this small project I have been working on. I have a MySQL
I have a small c++ project I've been working on in XCode, that I'd
I have been working on a project which uses Tiger's SQLite3 library (which if
I have been working on a small file manager module in a project where
I have been working on a small php app (400K total). But in the
I have been working on a web services related project for about the last

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.