A typical Stripes MVC design would look something like the code below.
The JPA object is automatically loaded by the Stripes interceptor provided by the Stripersist (but this can also be easily implemented as you wish , if you like). Thus, in this example, the request http://your.app/show-order-12.html will load the order with identifier 12 from the database and display 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; } }
By the way, there is a really great short (!) Book about Stripes that covers all of these things:
Stripes: ... and Java Web Development is fun again!
Kdeveloper
source share