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