Announcement Announcement Module
Collapse
No announcement yet.
binding in spring portlet MVC Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • binding in spring portlet MVC

    Hi all. I've created a portlet in my project using portlet MVC. In this portlet, I have implemented a Command object:

    Code:
    public class ApplicationProjectVO implements Serializable {
    	private Application application;
    	private List<Project> projects;
    }
    To abbreviate, I've dropped getters and setters on this post, but them exist in my code. This is my controller:

    Code:
    @Controller("applicationProjectManagerController")
    @RequestMapping("VIEW")
    public class ApplicationProjectManagerController {
    
    	private static final Logger logger = Logger
    			.getLogger(ApplicationProjectManagerController.class);
    
    	@Autowired
    	@Qualifier("applicationService")
    	private ApplicationService applicationService;
    
    	@Autowired
    	@Qualifier("projectService")
    	private ProjectService projectService;
    
    	public void setApplicationService(ApplicationService applicationService) {
    		this.applicationService = applicationService;
    	}
    
    	public void setProjectService(ProjectService projectService) {
    		this.projectService = projectService;
    	}
    
    	@RenderMapping(params = "myaction=viewApplicationProjectForm")
    	public String doView() {
    		return "viewApplicationProjectForm";
    	}
    
    	@ModelAttribute(value = "applicationList")
    	public List<Application> getApplications() {
    		return applicationService.getApplications();
    	}
    
    	@ModelAttribute(value = "projectList")
    	public List<Project> getProjects() {
    		return projectService.getProjects();
    	}
    
    	@ModelAttribute("appProj")
    	public ApplicationProjectVO getCommandObject() {
    		return new ApplicationProjectVO();
    	}
    
    	@ActionMapping(params = "myaction=addApplicationProject")
    	public void addApplicationProject(
    			@ModelAttribute ApplicationProjectVO application,
    			BindingResult bindingResult, ActionResponse response,
    			SessionStatus sessionStatus) {
    
    		try {
    			if (!bindingResult.hasErrors()) {
    				logger.info("Application = "
    						+ application.getApplication().getApplicationName());
    				response.setRenderParameter("myaction",
    						"viewApplicationProjectForm");
    				sessionStatus.setComplete();
    			} else {
    				logger.info("A binding error happened");
    				List<ObjectError> errorList = bindingResult.getAllErrors();
    				Iterator<ObjectError> it = errorList.iterator();
    				while (it.hasNext()) {
    					logger.info("ObjectError: " + it.next().getDefaultMessage());
    				}
    				response.setRenderParameter("myaction","viewApplicationProjectForm");
    			}
    		} catch (Exception e) {
    			logger.error("ERROR: addApplicationProject method", e);
    		}
    	}
    
    }
    As you can see, I've sent 2 model Objects: a List<Application> and a List<Project>, and a command object: ApplicationProjectVO.

    What I'm trying to do is showing in a table the Application list and in another table the Project list. The last column of Application list is a radio button to choose one project and bind it to ApplicationProjectVO.application:

    Code:
    <portlet:actionURL var="showAddApplicationProjectActionUrl">
    	<portlet:param name="myaction" value="addApplicationProject" />
    </portlet:actionURL>
    
    <form:form name="appProjCatalogForm" commandName="appProj" method="post"
    	action="${showAddApplicationProjectActionUrl}">
    	<div>
    	<p>
    	<table border="1" cellspacing="2" cellpadding="4">
    		<tr bgcolor="#99CCFF">
    			<td valign="top"><b>Id</b></td>
    			<td valign="top"><b>Name</b></td>
    			<td valign="top"><b>Version</b></td>
    			<td valign="top"><b>Path SVN</b></td>
    			<td valign="top"><b>Status</b></td>
    			<td valign="top"><b>Note</b></td>
    			<td></td>
    		</tr>
    		<c:if test="${not empty applicationList}">
    			<c:forEach var="app" items="${applicationList}">
    				<tr>
    					<td valign="top"><c:out value="${app.idapplication}" /></td>
    					<td valign="top"><c:out value="${app.applicationName}" /></td>
    					<td valign="top"><c:out value="${app.applicationVersion}" /></td>
    					<td valign="top"><c:out value="${app.applicationPathsvn}" /></td>
    					<td valign="top"><c:out value="${app.applicationStatus}" /></td>
    					<td valign="top"><c:out value="${app.applicationNotes}" /></td>
    					<td><form:radiobutton path="application" value="${app}" /></td>
    				</tr>
    			</c:forEach>
    			<tr>
    				<td colspan="6"></td>
    				<td><input type="submit" value="Add ApplicationProject" /></td>
    			</tr>
    		</c:if>
    	</table>
    	</p>
    	</div>
    </form:form>
    When I press Submit I get this message:

    Failed to convert property value of type 'java.lang.String' to required type 'com.oami.qaportal.domain.Application' for property 'application'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.oami.qaportal.domain.Application] for property 'application': no matching editors or conversion strategy found
    I don't understand.Take a look to my radio button code:

    Code:
    <form:radiobutton path="application" value="${app}" />
    Where application is a field of type Application in my command object (ApplicationProjectVO) and ${app} is the iterating variable over the list of applications.

    What I'm doiing wrong?
Working...
X