Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struts2 Convention Plugin Results Using Inheritance

Is there a way to make the struts2 convention plugin use results from a super class?

I'm trying to create a general CRUD, and use general results if there is no implementation in the child class. Is this possible?

like image 662
partkyle Avatar asked Nov 14 '22 19:11

partkyle


1 Answers

Yes, you can.

For an example :

General CRUD

@Results({
        @Result(name = "input", location = "input.jsp"),
        @Result(location = "input.jsp")
})
public abstract class CrudActionSupport extends ActionSupport {

    @Action("update/{entityId}") // wildcard mapping
    public String actionUpdate() {
        return SUCCESS;
    }
}

Action

public class PersonAction extends CrudActionSupport {

}

The annotation at CrudActionSupport will always in effect, except it is overridden in subclass.

e.g.

@Results({
        @Result(name = "input", location = "person.jsp"),
        @Result(location = "person.jsp")
})
public class PersonAction extends CrudActionSupport {

    @Override
    public String actionUpdate() {
        return SUCCESS;
    }

    // or 

    /*

    @Action("update/{id}")
    @Override
    public String actionUpdate() {
        return SUCCESS;
    }

    */
}
like image 151
lschin Avatar answered Dec 09 '22 19:12

lschin