• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Invalid property 'username' of bean class [java.lang.String]

 
Ranch Hand
Posts: 165
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm getting following error while running my Spring MVC web application:-

org.springframework.beans.NotReadablePropertyException: Invalid property 'username' of bean class [java.lang.String]: Bean property 'username' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

Why error is pointing to a String class like java.lang.String? It should take from my UserForm object.

UserForm:-


Controller Class (LoginPageController):-


JSP:-


Can you please advise on this where I'm making the mistake? I tried refactor the class name of UserForm to just 'User.java' and also rename username to user accordingly on JSP as well but still showing same error.
Thank you,
 
Ranch Hand
Posts: 951
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure bt i think you are mssing @ModelAttribute in the controller method.. so your method should be like this:

 
Vinod Vijay
Ranch Hand
Posts: 165
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tushar Goel wrote:I am not sure bt i think you are mssing @ModelAttribute in the controller method.. so your method should be like this:



Hi, I appreciate your help however my problem is my login screen itself is not populating means look like following method has some problem:-
@RequestMapping(method = RequestMethod.GET)
public String showLoginPage(@ModelAttribute("userForm") UserForm userForm, BindingResult bindingResult, ModelMap modelMap){
logger.info("**************");
userForm = (UserForm) modelMap.get(userForm);
modelMap.addAttribute("userForm", "userForm");
return "login";
}

I added @ModelAttribute also but somehow I feel like my form bean i.e. UserForm is not being recognized with this login JSP as a result im still getting following error during loading it:-
org.springframework.beans.NotReadablePropertyException: Invalid property 'username' of bean class [java.lang.String]: Bean property 'username' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
 
Vinod Vijay
Ranch Hand
Posts: 165
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tushar Goel wrote:I am not sure bt i think you are mssing @ModelAttribute in the controller method.. so your method should be like this:



Hi, I appreciate your help however my problem is my login screen itself is not populating means looks like following method has some problem:-
@RequestMapping(method = RequestMethod.GET)
public String showLoginPage(@ModelAttribute("userForm") UserForm userForm, BindingResult bindingResult, ModelMap modelMap){
logger.info("**************");
userForm = (UserForm) modelMap.get(userForm);
modelMap.addAttribute("userForm", "userForm");
return "login";
}

I added @ModelAttribute also but somehow I feel like my form bean i.e. UserForm is not being recognized with this login JSP as a result im still getting following error during loading it:-
org.springframework.beans.NotReadablePropertyException: Invalid property 'username' of bean class [java.lang.String]: Bean property 'username' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
 
Tushar Goel
Ranch Hand
Posts: 951
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it may possible your dispatcher_servlet.xml have error? What is your login.html and dispatcher xml?
 
Vinod Vijay
Ranch Hand
Posts: 165
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tushar Goel wrote:it may possible your dispatcher_servlet.xml have error? What is your login.html and dispatcher xml?



Hi, following are my configuration files:-
Web.xml:-


TaskManagement-servlet.xml:-


There is an index.jsp but im not using this default page. I'm trying to access my login JSP by appending /login in URL which is hitting the login controller class (LoginPageController.java) :-
http://localhost:8081/TaskManagamentApp/login
 
Tushar Goel
Ranch Hand
Posts: 951
4
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it. You have issue while adding object to the model.


you have used



but it should be:



 
Vinod Vijay
Ranch Hand
Posts: 165
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tushar Goel wrote:got it. You have issue while adding object to the model.


you have used



but it should be:




Thanks, really appreciated for your help. I overlooked this error. It worked now.
 
Willie Smits increased rainfall 25% in three years by planting trees. Tiny ad:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!