Announcement Announcement Module
Collapse
No announcement yet.
AbstractWizardFormController does not call referenceData Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AbstractWizardFormController does not call referenceData

    I have a controller that extends AbstractWizardFormController and I have implemented the following methods. But my referenceData method does not get invoked. Shouldn't it be invoked by the showForm() in superclass?

    protected Object formBackingObject(HttpServletRequest request) throws Exception
    {
    long parentId = RequestUtils.getRequiredLongParameter(request, "parentId");
    TranDefGroup tranDefGroup = new TranDefGroup();
    tranDefGroup.setParentId(parentId);
    return tranDefGroup;
    }

    protected Map referenceData(HttpServletRequest arg0) throws Exception
    {
    Map model = new HashMap();
    ArrayList tranList = configurationService.getTranList();
    model.put("tranList", tranList);
    return model;
    }

  • #2
    Lili,

    You are definately correct that this should work. If not solved, could you post the entire controller class?

    -mc

    Comment


    • #3
      You're not overriding a framework method.

      You need to match the signature of any of the protected/public referenceData methods, of which there are none that just take a request object.

      If you're using java 5, you can add the @Override annotation above the method signature and the compiler will check that the method does actually exist in some base class up the hierarchy.

      Comment


      • #4
        gmatthews,

        what did you mean with
        "You need to match the signature of any of the protected/public referenceData methods, of which there are none that just take a request object."???

        I've got the same problem. I'm using an AbstractWizardFormController and my referenceData() -method seems to be ignored. The same code works in a SimpleFormController. I have Java 1.4.2_05.


        Code:
        class OperationAddController extends AbstractWizardFormController {
        
            private OperationService operationService;
            private WorkflowService workflowService;
            
            public void afterPropertiesSet() throws Exception {
                if (this.operationService == null)
                    throw new IllegalArgumentException("An OperationService is required");
                if (this.workflowService == null)
                    throw new IllegalArgumentException("A WorkflowService is required");
            }
        
            protected void processFinish(
                    ActionRequest request, ActionResponse response,
                    Object command, BindException errors)
            		throws Exception {
        		
            	operationService.addOperation((Operation)command);
        		response.setRenderParameter("action","allOperations");
            }
        
            protected void processCancel(
                    ActionRequest request, ActionResponse response,
                    Object command, BindException errors)
                    throws Exception {
        		response.setRenderParameter("action","allOperations");
            }
        
            protected void validatePage(
                    Object command, Errors errors, int page, boolean finish) {
                if (finish) {
                    this.getValidator().validate(command, errors);
                    return;
                }
        		Operation operation = (Operation)command;
        		OperationValidator operationValidator = (OperationValidator)getValidator();
        		switch (page) {
        			case 0: operationValidator.validateName(operation, errors);	break;
        		}
            }
        
            protected Map referenceData(PortletRequest request)throws Exception {
            	Map retval = new HashMap();
            	retval.put("workflows", workflowService.getAllWorkflows());
            	return retval;
        	}
            
            protected Object formBackingObject(PortletRequest request)throws Exception {
        
            	Operation o;
            	o = new Operation();
        	
            	return o;
            }
        	
            
            protected void initBinder(PortletRequest request, PortletRequestDataBinder binder)
        			throws Exception {
            	NumberFormat nf = NumberFormat.getInstance(request.getLocale());
                binder.registerCustomEditor(java.lang.Integer.class,
                        new CustomNumberEditor(java.lang.Integer.class, nf, true));
                binder.registerCustomEditor(Workflow.class, new WorkflowSupport());
        		   
                binder.setAllowedFields(new String[] {"name","description","critical"});
            }
            
          
        	protected ModelAndView renderInvalidSubmit(RenderRequest request, RenderResponse response)
        			throws Exception {
        	    return null;
        	}
        
        	protected void handleInvalidSubmit(ActionRequest request, ActionResponse response)
        			throws Exception {
        	    response.setRenderParameter("action","allOperations");
        	}
        
        	public void setOperationService(OperationService operationService) {
        	    this.operationService = operationService;
        	}
        	public void setWorkflowService(WorkflowService workflowService) {
        	    this.workflowService = workflowService;
        	}
        
        }
        And this is the jsp-code:


        Code:
        <form method="post" action="<portlet:actionURL>
        <portlet:param name="action" value="addOperation"/>
        <portlet:param name="_page" value="${page}"/>
        <portlet:param name="workflowId" value="<%=wfId %>"/>
        </portlet:actionURL>">
        	<table border="0" cellpadding="4">
        		<tr>
        		
        		</tr>
        		<tr>
        			<c:choose> 
        				<c:when test="${page == 0}" > 
        					<th>Name</th>
        					<td>
        					<spring:bind path="operation.name">
                				<input type="text" name="${status.expression}" value="${status.value}"/>
                 				<span>${status.errorMessage}</span>
            				</spring:bind>
        					</td>
        				</c:when> 
        				<c:when test="${page == 1}" > 
        					<th>Workflow:</th>
        					<td><spring:bind path="operation.workflow">
          						<select name="<c:out value="${status.expression}"/>" size="1">
            						<option value="0">--- bitte wählen ---</option>
            						<c:forEach var="workflow" items="${workflows}">
              							<option value='<c:out value="${workflow.id}"/>' <c:if test="${workflow.id == status.value}">selected</c:if>>
                						<c:out value="${workflow.name}"/>
              							</option>
            						</c:forEach>
          						</select>
            				</spring:bind>
        					</td>
        					
        				</c:when> 
        			</c:choose>  
        		<tr>
        			<th colspan="2">
        				<input type="submit" name="_target${nextPage}" ${empty nextPage ? "disabled" : ""} value="Next"/>
        				<input type="submit" name="_finish" value="Finish"/>
        				<input type="submit" name="_target${prevPage}" ${empty prevPage ? "disabled" : ""} value="Previous"/>
        				<input type="submit" name="_cancel" value="Cancel"/>
        			</th>
        		</tr>
        	</table>
        </form>
        Thanks for your help!

        Comment


        • #5
          Problem solved

          In my referenceData method I forgot to use the parameter "int page"!

          Here ist the correct code, now it works

          Code:
           protected Map referenceData(PortletRequest request, int page)throws Exception {
          			Map retval = new HashMap();
          			
          			switch(page){
          				case 0: retval.put("workflows", workflowService.getAllWorkflows()); break;
          			}
          				
          			return retval;
          			}

          Comment


          • #6
            I was wondering where you set you ${nextPage}, ${previousPage} in the controller...

            Comment

            Working...
            X