Results 1 to 6 of 6

Thread: AbstractWizardFormController does not call referenceData

Hybrid View

  1. #1

    Default 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;
    }
    cheers,
    Lili

  2. #2

    Default

    Lili,

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

    -mc

  3. #3
    Join Date
    Aug 2004
    Location
    Sydney
    Posts
    503

    Default

    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.

  4. #4
    Join Date
    Aug 2006
    Posts
    3

    Default

    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!

  5. #5
    Join Date
    Aug 2006
    Posts
    3

    Default 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;
    			}

  6. #6
    Join Date
    Nov 2008
    Posts
    13

    Default

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

Similar Threads

  1. Replies: 0
    Last Post: Jun 6th, 2005, 01:30 PM
  2. Replies: 2
    Last Post: May 19th, 2005, 09:39 AM
  3. Replies: 1
    Last Post: Feb 10th, 2005, 09:57 AM
  4. Replies: 0
    Last Post: Dec 19th, 2004, 11:50 PM
  5. Replies: 2
    Last Post: Sep 2nd, 2004, 08:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •