Stripes MVC Model Data
Asked Answered
B

3

6

I am experienced with Spring MVC and am trying out Stripes to decide whether to try it out for a new project.

In Spring MVC I would prepare model data and pass it to the view by adding it to a map in the ModelAndView instance created by my controller. I am having trouble finding the equivalent of this for Stripes.

It seems like the closest parallel is to have an ActionBean prepare my model data and add it to the HttpSession. A ForwardRedirect is used to load the view and the data is accessed from the session.

Is there better support for a front controller provided by Stripes, or is this a totally different design principle than Spring MVC? (ie I have to invoke methods from the view using EL to retrieve data, as some of the examples do)

Thanks!

Brae answered 14/10, 2010 at 7:10 Comment(2)
I don't like the method of adding the model data to the HttpSession, as it should really be stored int request scope for most page requests, not the session scope. This is just the closest equivalent support I have been able to figure out for stripes.Brae
ActionBean is both the controller (Action) and the parent model data (Bean). ;)Asur
A
5

A typical MVC design in Stripes would look like something like the code below.

The JPA entity is automaticaly loaded by a Stripes interceptor provided by Stripersist (but this can also easily implemented on your own if you wish). Thus in this example, requesting http://your.app/show-order-12.html will load a order with id 12 from the database and will show it on the page.

Controller (OrderAction.java):

@UrlBinding("/show-order-{order=}.html")
public class OrderAction implements ActionBean {
    private ActionBeanContext context;
    private Order order;

    public ActionBeanContext getContext() {
        return context;
    }

    public void setContext(ActionBeanContext context) {
        this.context = context;
    }

    public void setOrder(Order order) {
        this.order = order;
    }

    public String getOrder() {
        return order;
    }

    @DefaultHandler
    public Resolution view() {
        return new ForwardResolution(“/WEB-INF/jsp/order.jsp”);
    }
}

View (order.jsp):

<html><body>
    Order id: ${actionBean.order.id}<br/>
    Order name: ${actionBean.order.name)<br/>
    Order total: ${actionBean.order.total)<br/>
</body></html>

Model (Order.java):

@Entity
public class Order implements Serializable {
    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    private String name;
    private Integer total;

    public String getName() {
        return name;
    }

    public Integer getTotal() {
        return total;
    }   
}

BTW there is an really excellent short(!) book on Stripes that covers all these things:

Stripes: ...and Java Web Development Is Fun Again

Awad answered 14/10, 2010 at 23:53 Comment(0)
B
1

Okay I have figured it out. Attributes added to the HttpServletRequest (retrieved from context) ARE available in the page receiving the ForwardRedirect

IE context.getRequest().setAttribute("attr1", "request attribute 1"); return new ForwardResolution("/WEB-INF/pages/hello.jsp");

In hello.jsp ${attr1} is available... yay!

Brae answered 14/10, 2010 at 18:3 Comment(0)
G
0

There is on one nice solution for nopCommerce 3.20 (MVC). It's a payment plugin supporting, authorize, authorize/capture, refund and partially refund. PCI compliance included, no CC info is stored on db http://shop.wama-net.com/en/stripe-payment-plugin-for-nopcommerce

Jacky

Glycoside answered 4/2, 2014 at 17:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.