Issue
Invalid property 'stCode' of bean class [java.lang.String]: Bean property 'stCode' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
Regist.jsp
<div class="container">
<div class="row centered-form">
<div class="col-xs-12 col-sm-8 col-md-4 col-sm-offset-2 col-md-offset-4">
<div class="panel panel-default">
<div class="panel-heading">
</div>
<div class="panel-body">
<f:form action="registSave" modelAttribute="r" method="post">
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
State Name
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<f:input path="stCode" class="form-control input-sm"/>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
District Name
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<f:input path="distCode" class="form-control input-sm"/>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
Phone number
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<f:input path="phone" class="form-control input-sm"/>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
Name
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<f:input path="name" class="form-control input-sm"/>
</div>
</div>
</div>
<!-- <div class="form-group">
<input type="email" name="email" id="email" class="form-control input-sm" placeholder="Email Address">
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="password" name="password" id="password" class="form-control input-sm" placeholder="Password">
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="password" name="password_confirmation" id="password_confirmation" class="form-control input-sm" placeholder="Confirm Password">
</div>
</div>
</div> -->
<input type="submit" value="Register" class="btn btn-info btn-block">
</f:form>
</div>
</div>
</div>
</div>
</div>
RBean
package max.Bean;
public class RBean {
String stCode;
String distCode;
String phone;
String name;
public String getStCode() {
return stCode;
}
public void setStCode(String stCode) {
this.stCode = stCode;
}
public String getDistCode() {
return distCode;
}
public void setDistCode(String distCode) {
this.distCode = distCode;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Controller
package max;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import max.Bean.RBean;
@Controller
public class MainController {
@Autowired
RBean rBean;
@RequestMapping("home")
public String home()
{
return "registLayout";
}
@RequestMapping("regist")
public ModelAndView registration()
{
return new ModelAndView("reg","r","rBean");
}
@RequestMapping(value="registSave", method=RequestMethod.POST)
public ModelAndView registrationSave(@ModelAttribute("r") RBean rBean)
{
return new ModelAndView("reg","r","rBean");
}
}
Solution
if you are trying to set rBean
into r
variable which is available in view then you should remove the "
used for rBean
. Eg: return new ModelAndView("reg","r",rBean);
Answered By - msucil
Answer Checked By - Timothy Miller (JavaFixing Admin)