0

I have a JSP page that takes values from the user and shows it in next page (review page before saving). I have bean that has all the values mapped to the fields of the JSP.

@Component
@Scope("session")
public class Campaign implements Serializable {
     protected List<Reason> reasons;
     .....
     .....
}

Reason.java

@Component
public class Reason implements Serializable {

    private static final long serialVersionUID = 1L;

    private int id;
    private String reason;
    private int retryDuration;
    ....
}

In the jsp a table populates the values of the Reasons. When I press submit, the reasons gets the populated values. If there were any validation error in other fields, the page reloads with the error labels displayed below the respective fields. Now if I delete a row in the table that populates the reasons and submit the form, the form still contains the values that was removed too. In the jsp the row is deleted, to check this, I even deleted rows in the jsp using firebug and submitted the page. Still I see the fields are not reset. why is this strange behavior? Am I missing anything in the configuration?

vvra
  • 2,832
  • 5
  • 38
  • 82
  • Which is what I would expect. You have a session scoped object which is used for binding. When you remove an element from the list it is only removed on the client not the server. After form submit binding takes place, it is a list so binding takes place based in index. If you have 3 rows, remove row with index 2 no binding will happen but also no delete will happen. This is due to the fact that you have a session scoped object that way the object is reused and not rebuild. Also why does it need to be a component (same for `Reason`)? – M. Deinum Aug 28 '14 at 10:28
  • Okay. I understand it now. But, am I following the right approach to implement a functionality with many pages (without using webflow), in my case with 2 pages and finally the details are saved the database? – vvra Aug 28 '14 at 10:58
  • And, also I would like to know why the @Component is unnecessary for the beans? Will the spring be able to bind the bean with the request? – vvra Aug 28 '14 at 11:10

0 Answers0