3

I'm passing parameter projectId to Struts action

http://localhost:8080/app/myaction.action?projectId=100

Simple action class is defined as:

public class MyAction extends AnyStrutsAction  {
   private ParamReader paramReader = new ParamReader();

   public ParamReader getParamReader() {
        return paramReader;
   }

   public void setProjectId(String id) {
       getParamReader().setProjectId(id);
   }

   public  void execute()
       // ...
   }
}

And everything works ok (/)

Next method setProjectId is extracted to interface and implemented as Java8 default method:

public interface ParamReaderAware  {

    ParamReader getParamReader();

    default void setProjectId(String id) {
        getParamReader().setProjectId(id);
    }
}

public class MyAction extends AnyStrutsAction implements ParamReaderAware {

    private ParamReader paramReader = new ParamReader();

    @Override
    public ParamReader getParamReader() {
        return paramReader;
    }

    public  void execute()
    // ...
    }
}

Now calling http://localhost:8080/app/myaction.action?projectId=100 does not set parameter projectId. The default implementation is not visible for struts

My question is: - does Struts2 support default interface method ? - Is there any way to do so (any struts configuration, version (currentyly im using 2.3.16) )

Why I extract method to interface. - I want to add reading parameter feature to multiple class actions

Roman C
  • 49,761
  • 33
  • 66
  • 176
marek
  • 31
  • 1
  • It depends on how it is implemented. If it is settled on Bean introspection, it doesn’t work, as discussed [here](http://stackoverflow.com/q/23219006/2711488) and [here](http://stackoverflow.com/q/31703563/2711488). Similar issue [as with Spring](http://stackoverflow.com/q/30477367/2711488)… – Holger May 25 '16 at 10:36
  • The version of Struts that you are using is not ready to work with Java 8 – Roman C May 25 '16 at 15:35
  • Thanks for info. I will check newer version and get feedback if works – marek May 27 '16 at 20:09

0 Answers0