Why model-driven action is preferred over bean properties

I am learning struts2 from the book struts-2 in action. they say that for transferring data to model-driven actions, objects are preferable to beans-supported objects.

can someone explain to me why they say so?

is there a reason to do something with the need to mention the link name in the presentation layer

+1
source share
2 answers

In cases when you are dealing with several properties, the book protects the use of an object to store these properties, instead of having a direct action to make your work easier. Consider the following examples:

public class CreateNewWidgetAction extends ActionSupport {
    private String property1;
    private String property2;
    private Long property3;
    ...

    public String execute() throws Exception {
        Widget widget = new Widget();
        // set properties on widget
    }

    // getters and setters for properties here
}

public class CreateNewWidgetAction extends ActionSupport {
    private Widget widget;

    public String execute() throws Exception {
        // sub properties for widget were already set, less work to do here
    }

    // getter and setter for widget here (or the
    // getModel method if you are using the Model Driven approach)
}

Widget (, 1, 2 3).

, , , .

: ModelDriven, property1, property2, property3 .. , , .

ModelDriven, widget.property1, widget.property2, widget.property3 .. , , .

, . :

JavaBeans , ModelDriven Java . , .

- Struts 2 , 3. Struts 2 > - . 62

+6

, , bean, den jsp, - user.name, OGNL , .

, , bean , , bean , - user.name jsp.

,

+2

Source: https://habr.com/ru/post/1788299/


All Articles