Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am develoong spring web mvc application.

when i execute the page:
the following exception occurs:
javax.servlet.jsp.JspException: Type [java.lang.String] is not valid for option items



here's the code:
home.jsp
----------
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
    
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form:form action="processLogin" modelAttribute="user">
<form:select path="userType">
<form:options items="${user.userTypes}"/>
</form:select>
<br>
<form:input path="userId"/>
<br>
<form:input path="password"/>
<br>
<input type="submit" value="submit"/>
</form:form>

</body>
</html>



Home controller:
package com.rec.controller;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.rec.model.UserDetails;

@Controller
@RequestMapping("/home")
public class HomeController {

	private static Logger log  = Logger.getLogger(HomeController.class);
	@RequestMapping("/showForm")
	public String Home(Model model)
	{log.info("Home Controller");
     UserDetails user= new UserDetails();
     model.addAttribute("user", user);
		return "Home" ;
		
		
	}
	
	
	@RequestMapping("/processLogin")
	private String processForm(@ModelAttribute("user")UserDetails theUser)
	{
		return "Discom-user-page.jsp";
		
		
	}
}


What I have tried:

<form:select path="userType">
<form:option items="${user.userTypes}"/>
</form:select>
Posted
Comments
Sandeep Mewara 24-Sep-20 5:56am    
Where is the code for: user.userTypes => is that a collection?
Richard MacCutchan 24-Sep-20 6:01am    
The code states that items is a selection of options, but your code is passing a simple string.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900