Announcement Announcement Module
Collapse
No announcement yet.
A question about command-object by using SimpleFormController Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • A question about command-object by using SimpleFormController

    Hi all,

    My controller looks as follow:
    Code:
    public class TestProvisionController extends MQController {
    
    	public TestProvisionController() {
    		setCommandClass(MQDetailForm.class);
    	}
    
    	@Override
    	protected ModelAndView onSubmit(HttpServletRequest request,
    			HttpServletResponse response, Object command, BindException errors)
    			throws Exception {
    		MQDetailForm mqdDetailForm = (MQDetailForm) command;
    		Map<String, Serializable> model = errors.getModel();
    		model.put("provision", mqdDetailForm);
    		return new ModelAndView(getSuccessView(), model);
    	}
    }
    The command-object "MQDetailForm.java" looks as follow:
    Code:
    public class MQDetailForm extends MQForm implements Serializable {
    
    }
    And "MQForm.java":
    Code:
    public class MQForm implements Serializable {
    
    	protected String request;
    
    	public String getRequest() {
    		return request;
    	}
    
    	public void setRequest(String request) {
    		this.request = request;
    	}
    
    }
    And my jsp looks as follow:
    Code:
    <form:form action="test-detail.html" method="post">
    <table>
    	<tr>
    		<td><form:input path="requestStr"/></td>
    		<td rowspan="2"><img src="<c:url value="/images/ampel-gruen-trans.gif"/>" width="50" height="66"/> </td>
    	</tr>
    	<tr>
    		<td>Output: '<c:out value="${provision.requestStr}"></c:out>'</td>
    	</tr>
    	<tr>
    		<td><input type="submit" value="Excecute" /></td>
    	</tr>
    </table>
    </form:form>
    The problem is, the jsp can not show anything.

    But if I change the MQDetailForm.java as follow, i.g. not extend MQForm, it will be OK. Can't I use the extends? Why?

    Code:
    public class MQDetailForm implements Serializable {
    
    	protected String requestStr;
    
    	public String getRequestStr() {
    		return requestStr;
    	}
    
    	public void setRequestStr(String requestStr) {
    		this.requestStr = requestStr;
    	}
    
    }

  • #2
    It looks as though in your JSP you're trying to display something called MQDetailForm.requestStr, which, in the version where you extend the parent form object, simply doesn't exist. So why would this work?

    If MQDetailForm extends MQForm, it will have a "request" property, but not a "requestStr" property.

    Comment


    • #3
      My god!

      You are right. WHat a mistyping I made.

      Comment


      • #4
        Now I change the command object and the controller as follow:

        Code:
        public class MQDetailForm implements Serializable {
        
        	private static final long serialVersionUID = 1L;
        
        	private ProvisionDataForm provisionDataForm;
        
        	public ProvisionDataForm getProvisionDataForm() {
        		return provisionDataForm;
        	}
        
        	public void setProvisionDataForm(ProvisionDataForm provisionDataForm) {
        		this.provisionDataForm = provisionDataForm;
        	}
        
        }
        and:
        Code:
        public class ProvisionDataForm extends MQForm{
        
        	@Override
        	public String getExpectedResponse() {
        		return "Provision Expected Response";
        	}
        }
        Code:
        public class MQForm implements Serializable {
        	protected String request;
        
        	public String getRequest() {
        		return request;
        	}
        
        	public void setRequest(String request) {
        		this.request = request;
        	}
        
        }
        Controller:
        Code:
        public class TestDetailController extends MQController{
        
        	public TestDetailController() {
        		setCommandClass(MQDetailForm.class);
        	}
        
        	@Override
        	protected ModelAndView onSubmit(HttpServletRequest request,
        			HttpServletResponse response, Object command, BindException errors)
        			throws Exception {
        		MQDetailForm mqDetailForm = (MQDetailForm) command;
        		// Provision
         mqDetailForm.getProvisionDataForm().setResponse(mqDetailForm.getProvisionDataForm().getRequest());
        		return new ModelAndView(getSuccessView(), model);
        	}
        }
        The jsp:
        Code:
        ...
        <form:form action="pbv-test-detail.html" method="post">
        	<table title="Service Provision" border="1">
        		<thead>
        			<b>Service Provision</b>
        		</thead>
        		<tbody>
        			<tr>
        				<td align="right" width="100" style="font-weight: bold">Abfrage:&nbsp;</td>
        				<td width="700" align="left"><form:input
        					path="provisionDataForm.request" size="120" /></td>
        			</tr>
        	</table>
        	<table>
        		<tr>
        			<td colspan="3" align="center">
                                 <input name="provision" type="submit"
        				value="Submit" /></td>
        		</tr>
        	</table>
        </form:form>
        ...
        But the jsp can not show anything. I guess it's NULL-pointer error.

        Comment

        Working...
        X