Announcement Announcement Module
No announcement yet.
Form selects not populated Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Form selects not populated


    I'm developing a custom portlet for Liferay using Spring and Spring MVC. I have a form with select populated with values taken from a database.

    The problem is that, when the form is displayed for the first time, it shows the values correctly. But when I click the submit button and redirect to the same view (parametrized in order to show form and results at a time), the form selects are empty.

    I'm using the referenceData() method in SimpleFormController to populate the form selects. This is the relevant code of the form controller:

    public class AdvancedSearchController extends SimpleFormController{
    	private SearchService searchService;
    	public AdvancedSearchController(){
    	public void setSearchService(SearchService searchService) {
    		this.searchService = searchService;
    	protected Map referenceData(PortletRequest request,Object command,Errors errors) throws Exception{
    		Map<String, Object> refdata = new HashMap<String, Object>();
    		refdata.put("tipos", getTipos());
    		refdata.put("modalidades", getModalidades());
    		refdata.put("planes", getPlanesFormacion());
    		return refdata;
    	protected void onSubmitAction (ActionRequest request, ActionResponse response, Object command, BindException errors) throws Exception {
    		AdvancedSearchCriteria search = (AdvancedSearchCriteria)command;
    		response.setRenderParameter("action", "advancedSearch");
    		List<TbAccionesFormativa> courses = searchService.listTbAccionesFormativaAdvanced(search);
    		request.setAttribute("courses", courses);
    		response.setRenderParameter("p_p_state", WindowState.MAXIMIZED.toString());
    Note that I'm using the line response.setRenderParameter("action","advancedSear ch"). That is, when the user submits the form, this same controller takes control again.

    Anybody has any suggestion? If there is a better way to get the functionality that I want, I'd like to read your suggestions.

    Thanks in advance.


  • #2
    I suspect it is because it thinks the render phase is for a successful submit (which is correct), in which case the showForm method is not being called, which is where the referenceData method is called and merged into the model.

    You should probably be calling one of the showForm methods from an implementation of one of the onSubmitRender methods.

    You shouldn't need to do the setRenderParameter call for mapping purposes since you are mapping the render back to the same controller that handled the action. That's only needed if you want to map to a different controller.

    Also, if you are working in Spring 2.5, consider using the annotation-based dispatching instead. It makes these form flows much simpler to implement.


    • #3
      Hi again,

      Thanks for your reply. I change my code to use onSubmitRender() and call showForm() inside this method for building the ModelAndView object returned. It works pretty well and it is a much more elegant solution that my previous code.

      I'd like to use annotations, but I'm new to Spring and time is critical in the project we are developing, so I'll have to wait for learning to use it .

      Thanks again!