I'm developing an e-commerce project, and I have some doubts about how to organize input fields and related errors.
In this particular case (but for me it's a general, unanswered question) I wrote two actions, one for a detailed view of a product (
viewProduct) and another one for adding it to cart (
addToCart).
viewProduct (associated with it's own
JSP page) comes with a form like this:
This is good if the form contains no errors, but if not, I cannot display them because I've already moved from viewProduct, losing its state.
I read that usually
Struts 2 programmers use the same action for both showing the "first-request" page (the one I print now with viewProduct) and then working with inputs, but for both code cleanness and logic subdivision I prefer to keep two separated actions (merging them would result in a little chaos).
Plus, using the same action does not allow the framework (or I don't know how to make it) to
distinguish between a first request, where input fields are obviously empty,
and subsequent requests, where empty fields mean errors. This is not good, of course, because in this way a customer gets an error by simply viewing a product.
I hope I've been clear, english's not my language... someone can suggest me a solution?