woensdag 6 juni 2007

about spring SimpleFormController

When extending the SimpleFormController you might need some referenceData to be available after submitting the form. For example usefull when formView and successView are equal. This can be achieved by overriding the


/**
* On form submission redisplay the form.
*/
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response,
Object command,
BindException errors) throws Exception {
//TODO handle your command here
//return to formView (so referenceData is still present)
return showForm(request, response, errors);
}


(my tiny thread on this: http://forum.springframework.org/showthread.php?p=123407)


And to finish this post, you might need a collection as command object. In that case you'll need a wrapper class because collections are not supported by default. Example for list:


/**
* Helper class to use a list as spring command object. By default this is not
* supported so need to use this wrapper class in order to have indexed access
* to list.
*
* @author Hans Cappelle
*
*/
public class ListWrapper {

/**
* The actual list to perform actions on
*/
List list = new ArrayList();

/**
* def ctor
*
*/
public ListWrapper() {

}

public ListWrapper(List list) {
this.list = list;
}

// setters & getters

public List getList() {
return list;
}

public void setList(List list) {
this.list = list;
}

}


review generics and see if this can be applied to this wrapper

Geen opmerkingen:

Een reactie plaatsen