JSP cannot detect new added element in java model class - java

Here is my java model class - CustomerProperty.java
package model;
import java.io.InputStream;
public class CustomerProperty {
public CustomerProperty() {
}
public int propertyid;
public String name;
public String phone;
public String occupation;
public String address1;
public String address2;
public String postcode;
public String city;
public String state;
public String payment;
public InputStream photo;
public String agent;
public String IDproject;
public String[] quickSale;
public String ICnumber;
public String bag;
public String mydate;
public int getPropertyid() {
return propertyid;
}
public void setPropertyid(int propertyid) {
this.propertyid = propertyid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getICnumber() {
return ICnumber;
}
public void setICnumber(String ICnumber) {
this.ICnumber = ICnumber;
}
public String getICNUMBER() {
return ICnumber;
}
public void setICNUMBER(String ICnumber) {
this.ICnumber = ICnumber;
}
public String getOccupation() {
return occupation;
}
public void setOccupation(String occupation) {
this.occupation = occupation;
}
public String getAddress1() {
return address1;
}
public void setAddress1(String address1) {
this.address1 = address1;
}
public String getAddress2() {
return address2;
}
public void setAddress2(String address2) {
this.address2 = address2;
}
public String getPostcode() {
return postcode;
}
public void setPostcode(String postcode) {
this.postcode = postcode;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String dateTime) {
this.state = dateTime;
}
public String getPayment() {
return payment;
}
public void setPayment(String payment) {
this.payment = payment;
}
public InputStream getPhoto() {
return photo;
}
public void setPhoto(InputStream photo) {
this.photo = photo;
}
public String getAgent() {
return agent;
}
public void setAgent(String agent) {
this.agent = agent;
}
public String getIDproject() {
return IDproject;
}
public void setIDproject(String IDproject) {
this.IDproject = IDproject;
}
public String[] getQuickSale() {
return quickSale;
}
public void setQuickSale(String[] quickSale) {
this.quickSale = quickSale;
}
public String getMyDate() {
return mydate;
}
public void setMyDate(String mydate) {
this.mydate = mydate;
}
Whenever my JSP calling this java class, it only can detect the original element. I have added a new element - mydate and it is like forever cannot detect it.
Below is the error code.
pe Exception report
messageInternal Server Error
descriptionThe server encountered an internal error that prevented it
from fulfilling this request.
exception
org.apache.jasper.JasperException: javax.el.PropertyNotFoundException:
The class 'model.CustomerProperty' does not have the property
'mydate'. root cause
javax.el.PropertyNotFoundException: The class 'model.CustomerProperty'
does not have the property 'mydate'. note The full stack traces of the
exception and its root causes are available in the GlassFish Server
Open Source Edition 4.0 logs.
I have try to delete the java class and recreate again but still, the JSP only can detect for my first 16 elements and not any new added element.
Any solutions? Thanks
Below is my JSP file code.
<head>
<title>Project Sales Report</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">
</head>
<body>
<p align="center" style="font-family:times;font-size:40pt"><c:out value="${project2.projectName}"/> Sales Report</p>
<table align="center" bgcolor="silver" border="1" cellspacing="0" cellpadding="20" class="customer" >
<thead>
<tr>
<th>Unit ID</th>
<th>Agent</th>
<th>Customer Name</th>
<th>IC Number</th>
<th>Phone Number</th>
<th>Occupation</th>
<th>Address 1</th>
<th>Address 2</th>
<th>Postcode</th>
<th>City</th>
<th>State</th>
<th>Payment Type</th>
<th>Receipt</th>
</tr>
</thead>
<tbody>
<c:forEach items="${customerdetail}" var="abc">
<tr>
<td><c:out value="${abc.propertyid}"/></td>
<td><c:out value="${abc.agent}" /></td>
<td><c:out value="${abc.name}" /></td>
<td><c:out value="${abc.ICnumber}" /></td>
<td><c:out value="${abc.phone}" /></td>
<td><c:out value="${abc.occupation}" /></td>
<td><c:out value="${abc.address1}" /></td>
<td><c:out value="${abc.address2}" /></td>
<td><c:out value="${abc.postcode}" /></td>
<td><c:out value="${abc.city}" /></td>
<td><c:out value="${abc.mydate}" /></td>
<td><c:out value="${abc.payment}" /></td>
</tr>
</c:forEach>
</tbody>
</table>
<p> </p>
<div align="center">
<button type="button" style="width:70px;">Print</button>
<input type="button" value="Back" onClick="history.go(-1);
return true;" style="width:70px;"/>
</div>
</body>

Note your getter setters -
public String mybag() {
return mydate;
}
public void setmybag(String mydate) {
this.mydate = mydate;
}
It should be setMydate and getMydate. isn't it ?
Update -
It is case sensative.
public String mydate;
this should be
public String myDate;
Your JSP should be abc.myDate and not abc.mydate
<td><c:out value="${abc.mydate}" /></td>

Related

Why is the controller saving the user with null property fields

Basically, Spring crashes with this error "value [null]; codes [NotNull.user.email,NotNull.email,NotNull.java.lang.String,NotNull]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [user.email,email]; arguments []; default message [email]]; default message [must not be null], Field error in object 'user' on field 'firstName': rejected value [null]; codes" everytime I try to submit the completeProfile form. So, naturally, I looked at what data was saved after clicking submit on form. It turns out that the User object saved was having all the submitted property from the form as null. I checked inside the controller what was passed inside, all submitted properties from the form were null. Why does this happen?
User.java
#Entity
public class User {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
#NotNull
#Size(min = 2, max = 80)
private String firstName;
#NotNull
#Size(min= 2, max = 80)
private String lastName;
#NotNull
#Email
private String email;
private Boolean enabled = false;
private String password = "";
private String role = "AUTHOR";
private String location = "";
private String topics = "";
private String job = "";
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Boolean getEnabled() {
return enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getTopics() {
return topics;
}
public void setTopics(String topics) {
this.topics = topics;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
}
completeProfile.html
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<p>Complete your profile</p>
<form action="#" th:action="#{/completed-profile}" th:object="${user}" method="post">
<p>Email: <p th:text="${user.email}"></p>
<table>
<tr>
<td>Location:</td>
<td><input type="text" th:field="*{location}" /></td>
<td th:if="${#fields.hasErrors('location')}" th:errors="*{location}"></td>
</tr>
<tr>
<td>Job</td>
<td><input type="text" th:field="*{job}" /></td>
<td th:if="${#fields.hasErrors('job')}" th:errors="*{job}"></td>
</tr>
<tr>
<td>Topics of interest</td>
<td><input type="text" th:field="*{topics}" /></td>
<td th:if="${#fields.hasErrors('topics')}" th:errors="*{topics}"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" th:field="*{password}" /></td>
<td th:if="${#fields.hasErrors('password')}" th:errors="*{password}"></td>
<td th:text="${password_error}"></td>
</tr>
<tr>
<td><button type="submit">Submit</button></td>
</tr>
</table>
</form>
</body>
</html>
ProfileController.java
#Controller
public class ProfileController {
UserRepository userRepository;
public ProfileController(UserRepository userRepository) {
this.userRepository = userRepository;
}
#RequestMapping(value = {"/profile", "/profile.html"}, method = RequestMethod.GET)
public String profileForm(){
return "auth/profile";
}
#RequestMapping(value = "/complete-profile", method = RequestMethod.GET)
public String completeProfileForm(){
return "auth/completeProfile";
}
#RequestMapping(value = "/completed-profile", method = RequestMethod.POST)
public String submitProfileForm(#Valid User user, BindingResult bindingResult, Model model){
System.err.println(user.getEmail());
if (user.getPassword() == null || user.getPassword().equals("")){
// model.addAttribute("password_error", "password cannot be null");
model.addAttribute("user", user);
return "auth/completeProfile";
}
if(bindingResult.hasErrors()){
System.out.println(bindingResult.getAllErrors());
return "auth/completeProfile";
}
userRepository.save(user);
return "auth/login";
}
}

Property Not Found! same naming convention

I'm here again asking a question, I've tried asking this a while ago (for today) but I've reconstructed my code. So, my problem is that when I click the button to show the details from the database, it show me an error that Property Not Found, I'm confused as to why this error pops out, Here is an example of the error, as you can see it can read the elements in the database when I sysout it, displaying it in the console pic of error
)
//empServlet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
empServices empserv= new empServices();
ArrayList <empGetSet> empgs = new ArrayList<empGetSet>();
if (request.getParameter("process")!=null && request.getParameter("process").equals("showdis")) {
empgs.addAll(empserv.getAll());
request.setAttribute("empdet", empgs);
RequestDispatcher rd = request.getRequestDispatcher("showdet.jsp"); //forward to xxxpage after submit by button
rd.forward(request,response);
}
//empServices
package emppackage;
import java.util.ArrayList;
public class empServices {
empServlet empservlet = new empServlet();
empDAO empdao = new empDAO();
public ArrayList <empGetSet> getAll()
{
return empdao.getAllEmp();
}
//empDAO
public ArrayList<empGetSet> getAllEmp()
{
ArrayList<empGetSet> empdetails = new ArrayList<empGetSet>();
try {
Connection conn = getConnection();
String showsql = "SELECT *FROM csemp;";
PreparedStatement psread= conn.prepareStatement(showsql);
ResultSet rsread = psread.executeQuery();
while (rsread.next())
{
empGetSet readgetset = new empGetSet();
readgetset.setFname(rsread.getString(1));
//System.out.println(readgetset.getFname());
System.out.println(rsread.getString(1));
readgetset.setLname(rsread.getString(2));
readgetset.setNameRes(rsread.getString(3));
readgetset.setSerials(rsread.getString(4));
readgetset.setJrss(rsread.getString(5));
readgetset.setBand(rsread.getString(6));
readgetset.setAcct(rsread.getString(7));
readgetset.setPMPs(rsread.getString(8));
readgetset.setsJRSS(rsread.getString(9));
readgetset.setOpenSeatDesc(rsread.getString(10));
readgetset.setReqSkills(rsread.getString(11));
readgetset.setReqBand(rsread.getString(12));
readgetset.setDreject(rsread.getString(13));
readgetset.setsRreject(rsread.getString(14));
readgetset.setDetActPlan(rsread.getString(15));
readgetset.setDataComplete(rsread.getString(16));
readgetset.setStat(rsread.getString(17));
empdetails.add(readgetset);
}
psread.close();
conn.close();
}
catch (Exception e)
{
e.printStackTrace();
}
return empdetails;
}
This is my Getters and Setters with really the same naming convention
package emppackage;
public class empGetSet {
private String Fname;
private String Lname;
private String NameRes;
private String Serials;
private String Jrss;
private String Band;
private String Acct;
private String PMPs;
private String sJRSS;
private String OpenSeatDesc;
private String ReqSkills;
private String ReqBand;
private String Dreject;
private String Rreject;
private String DetActPlan;
private String DataComplete;
private String Stat;
public String getFname() {
return Fname;
}
public void setFname(String Fname) {
this.Fname=Fname;
}
public String getLname() {
return Lname;
}
public void setLname(String Lname) {
this.Lname=Lname;
}
public String getNameRes() {
return NameRes;
}
public void setNameRes(String NameRes) {
this.NameRes=NameRes;
}
public String getSerials() {
return Serials;
}
public void setSerials(String Serials) {
this.Serials=Serials;
}
public String getJrss() {
return Jrss;
}
public void setJrss(String Jrss) {
this.Jrss=Jrss;
}
public String getBand() {
return Band;
}
public void setBand(String Band) {
this.Band=Band;
}
public String getAcct() {
return Acct;
}
public void setAcct(String Acct) {
this.Acct=Acct;
}
public String getPMPs() {
return PMPs;
}
public void setPMPs(String PMPs) {
this.PMPs=PMPs;
}
public String getsJRSS() {
return sJRSS;
}
public void setsJRSS(String sJRSS) {
this.sJRSS=sJRSS;
}
public String getOpenSeatDesc() {
return OpenSeatDesc;
}
public void setOpenSeatDesc(String OpenSeatDesc) {
this.OpenSeatDesc=OpenSeatDesc;
}
public String getReqSkills() {
return ReqSkills;
}
public void setReqSkills(String ReqSkills) {
this.ReqSkills=ReqSkills;
}
public String getReqBand() {
return ReqBand;
}
public void setReqBand(String Acct) {
this.Acct=Acct;
}
public String getDreject() {
return Dreject;
}
public void setDreject(String Dreject) {
this.Dreject=Dreject;
}
public String getRreject() {
return Rreject;
}
public void setsRreject(String Rreject) {
this.Rreject=Rreject;
}
public String getDetActPlan() {
return DetActPlan;
}
public void setDetActPlan(String DetActPlan) {
this.DetActPlan=DetActPlan;
}
public String getDataComplete() {
return DataComplete;
}
public void setDataComplete(String DataComplete) {
this.DataComplete=DataComplete;
}
public String getStat() {
return Stat;
}
public void setStat(String Stat) {
this.Stat=Stat;
}
}
This is my .jsp
<%# taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Show Details</title>
</head>
<body>
<div align="right"><button>Back</button></div>
<form action ="empServlet" method="get">
<table border =1 cellpadding="18">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Name of Resource (LN ID Format)</th>
<th>Serial Number</th>
<th>JRSS</th>
<th>Band</th>
<th>Account (Proposed)</th>
<th>PMP Seat</th>
<th>Seat JRSS</th>
<th>Open Seat Description</th>
<th>Required Skills</th>
<th>Required Band low/high</th>
<th>Date of Rejection</th>
<th>Reason for Rejection</th>
<th>Detailed Action Plan</th>
<th>Target Date of Completion</th>
<th>Status(Ongoing/Closed)</th>
<th colspan=2>Do This</th>
</tr>
</thead>
<tbody>
<c:forEach items ="${empdet}" var="empdet" >
<tr>
<td><c:out value ="${empdet.Fname}" /></td>
<td><c:out value ="${empdet.Lname}" /></td>
<td><c:out value ="${empdet.NameRes}" /></td>
<td><c:out value ="${empdet.Serials}" /></td>
<td><c:out value ="${empdet.Jrss}" /></td>
<td><c:out value ="${empdet.Band}" /></td>
<td><c:out value ="${empdet.Acct}" /></td>
<td><c:out value ="${empdet.PMPs}" /></td>
<td><c:out value ="${empdet.sJRSS}" /></td>
<td><c:out value ="${empdet.OpenSeatDesc}" /></td>
<td><c:out value ="${empdet.ReqSkills}" /></td>
<td><c:out value ="${empdet.ReqBand}" /></td>
<td><c:out value ="${empdet.Dreject}" /></td>
<td><c:out value ="${empdet.Rreject}" /></td>
<td><c:out value ="${empdet.DetActPlan}" /></td>
<td><c:out value ="${empdet.DataComplete}" /></td>
<td><c:out value ="${empdet.Stat}" /></td>
<td>Update</td>
<td>Delete</td>
</c:forEach>
</tbody>
</table>
<br>
Show All
</form>
</body>
</html>

how to retrieve and create nested object from an spring mvc form

i am learning spring mvc right now and I am facing with a question. I have two objects Country and Capital. What I am trying to accomplish is when I created an new country in the jsp I would like to create an new capital along with it (country name , population, and capital name will be enter by user). I am not sure how to retrieve the Capital object and how to pass it to my controllers. Please explain. Thanks!!
Country.java
#Entity
#Table(name="COUNTRY")
public class Country{
#Id
#Column(name="id")
#GeneratedValue(strategy=GenerationType.IDENTITY)
int id;
#Column(name="countryName")
String countryName;
#Column(name="population")
long population;
#OneToOne
#JoinColumn(name="capitalId")
Capital capital;
public Country() {
super();
}
public Country(int i, String countryName,long population) {
super();
this.id = i;
this.countryName = countryName;
this.population=population;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCountryName() {
return countryName;
}
public void setCountryName(String countryName) {
this.countryName = countryName;
}
public long getPopulation() {
return population;
}
public void setPopulation(long population) {
this.population = population;
}
public Capital getCapital() {
return capital;
}
public void setCapital(Capital capital) {
this.capital = capital;
}
}
Capital.java
#Entity
#Table(name="CAPITAL")
public class Capital {
#Id #GeneratedValue(strategy=GenerationType.IDENTITY)
#Column(name="id")
private int id;
#Column(name="capitalName")
private String capitalname;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCapitalname() {
return capitalname;
}
public void setCapitalname(String capitalname) {
this.capitalname = capitalname;
}
}
countryDetails.jsp
<form:form method="post" modelAttribute="country" action="/SpringMVCHibernateCRUDExample/addCountry">
<table>
<tr>
<th colspan="2">Add Country</th>
</tr>
<tr>
<form:hidden path="id" />
<td><form:label path="countryName">Country Name:</form:label></td>
<td><form:input path="countryName" size="30" maxlength="30"></form:input></td>
</tr>
<tr>
<td><form:label path="population">Population:</form:label></td>
<td><form:input path="population" size="30" maxlength="30"></form:input></td>
</tr>
<tr>
<td><form:label path="capital">Capital</form:label></td>
</tr>
<tr>
<td colspan="2"><input type="submit"
class="blue-button" /></td>
</tr>
</table>
</form:form>

how to update only modified values in spring mvc from spring form

I am displaying checkboxes on a page and want to only update values in the db for which the values were changed. Also I would like to display an error if nothing was changed and form was submitted.
This is what i have so far. Any suggestion?
View
public class PersonView {
private List<Person> personList;
public List<Person> getPersonList() {
return personList;
}
public void setPersonList(List<Person> personList) {
this.personList = personList;
}
}
Domain
public class Person {
private String fullName;
private Boolean isSupervisor;
private Boolean isManager;
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public Boolean isSupervisor() {
return isSupervisor;
}
public void setSupervisor(Boolean isSupervisor) {
this.isSupervisor = isSupervisor;
}
public Boolean isManager() {
return isManager;
}
public void setManager(Boolean isManager) {
this.isManager = isManager;
}
}
Controller
#Controller
#RequestMapping("/person.html")
public class PersonsController {
#Autowired
private PersonService personService;
#RequestMapping(method = RequestMethod.GET)
public String initForm() {
return "member";
}
#RequestMapping(method = RequestMethod.POST)
public String submitForm(#ModelAttribute PersonView personView) {
model.addAttribute("persons", personView);
return "successMember";
}
#ModelAttribute
public PersonView getPersonView(){
List<Person> persons= personService.getPersonList();
PersonView pv = new PersonView();
pv.setPersonList(persons);
return pv;
}
}
JSP
<html>
<title>Persons Information</title>
</head>
<body>
<form:form method="POST" modelAttribute="personView">
<table>
<tr>
<th>Full Name</th>
<th>Supervisor</th>
<th>Manager</th>
</tr>
<c:forEach var="person" items="${personView.personList}"
varStatus="row">
<tr>
<td>{person.fullName}</td>
<td><form:checkbox path="personList[row.index].supervisor" value="true" />
</td>
<td><form:checkbox path="personList[row.index].manager" value="true" />
</td>
</tr>
</c:forEach>
<tr>
<td><input type="submit" name="submit" value="Submit">
</td>
</tr>
<tr>
</table>
</form:form>
</body>
</html>

Spring form send null model object to database

I want to send data from form to PostgreSQL. When I send data by form, hibernate save (by save() method) blank record .. I did it manually (for test) without using form and then everything is ok.
Spitter.class (entity for user)
#Entity
#Table(name="spitter")
public class Spitter implements Serializable {
private static final long serialVersionUID = 829803238866007413L;
#Id
//#SequenceGenerator(name = "hibernate_sequence")
#GeneratedValue(strategy=GenerationType.AUTO) #Column(name="spitter_id")
private Long id;
#Column(unique=true) #Size(min=3, max=20) #Pattern(regexp = "^[a-zA-Z0-9]+$", message="Nie poprawna nazwa uzytkownika.")
private String username;
#Size(min=5, max=15, message="Haslo musi miec minimum 5 znakow.")
private String password;
#Size(min=3, max=25, message="Blad w imieniu i nazwisku.")
private String fullName;
#OneToMany(mappedBy="spitter")
private List<Spittle> spittles;
#Email(message="Nie poprawny adres email.")
private String email;
private boolean updateByEmail;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public List<Spittle> getSpittles() {
return spittles;
}
public void setSpittles(List<Spittle> spittles) {
this.spittles = spittles;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public void setUpdateByEmail(boolean updateByEmail) {
this.updateByEmail = updateByEmail;
}
public boolean isUpdateByEmail() {
return updateByEmail;
}
#Override
public boolean equals(Object obj) {
Spitter other = (Spitter) obj;
return other.fullName.equals(fullName) && other.username.equals(username) && other.password.equals(password);
}
#Override
public int hashCode() {
// TODO Auto-generated method stub
return super.hashCode();
}
}
SpitterController.class
createSpitterProfile - shows form (edit.jsp) and sends model object (spitter) to form
addSpitterFromForm - receives binding data from form and save it to database and redirects to simply user profile
showSpitterProfile - there is of course null model object exception
#Controller
#RequestMapping("/spitters")
public class SpitterController {
private final SpitterService spitterService;
#Inject //#Autowired
public SpitterController(SpitterService spitterService) {
this.spitterService = spitterService;
}
//...
#RequestMapping(method = RequestMethod.GET, params = "new")
public String createSpitterProfile(Model model) {
model.addAttribute("spitter", new Spitter());
return "spitters/edit";
}
#RequestMapping(method = RequestMethod.POST)
public String addSpitterFromForm(#Valid Spitter spitter, BindingResult bindingResult) {
if(bindingResult.hasErrors())
return "spitters/edit";
spitterService.saveSpitter(spitter);
return "redirect:/spitters/" + spitter.getUsername();
}
#RequestMapping(value="/{username}", method = RequestMethod.GET)
public String showSpitterProfile(#PathVariable String username, Model model) {
model.addAttribute(spitterService.getSpitter(username));
return "spitters/view";
}
edit.jsp (registration form for new user (Spitter))
<%# taglib prefix="sf" uri="http://www.springframework.org/tags/form"%>
<%# taglib prefix="s" uri="http://www.springframework.org/tags"%>
<div>
<h2>New account test</h2>
<sf:form method="POST" modelAttribute="spitter"
enctype="multipart/form-data">
<fieldset>
<table>
<tr>
<th><sf:label path="fullName">Full name:</sf:label></th>
<td><sf:input path="fullName" size="15" /><br/>
<sf:errors path="fullName" cssClass="error" />
</td>
</tr>
<tr>
<th><sf:label path="username">Username:</sf:label></th>
<td><sf:input path="username" size="15" maxlength="15" />
<small id="username_msg">No spaces, please.</small><br/>
<sf:errors path="username" cssClass="error" />
</td>
</tr>
<tr>
<th><sf:label path="password">Password:</sf:label></th>
<td><sf:password path="password" size="30"
showPassword="true"/>
<small>6 characters or more (be tricky!)</small><br/>
<sf:errors path="password" cssClass="error" />
</td>
</tr>
<tr>
<th><sf:label path="email">Email Address:</sf:label></th>
<td><sf:input path="email" size="30"/>
<small>In case you forget something</small><br/>
<sf:errors path="email" cssClass="error" />
</td>
</tr>
<tr>
<th></th>
<td>
<sf:checkbox path="updateByEmail"/>
<sf:label path="updateByEmail">Send me email updates!</sf:label>
</td>
</tr>
<tr>
<th></th>
<td>
<input name="commit" type="submit"
value="I accept. Create my account." />
</td>
</tr>
</table>
</fieldset>
</sf:form>
</div>
and blank saved record to Postgres..
Try adding #modelattribute in this method .It fill fetch the required model object.
#RequestMapping(method = RequestMethod.POST)
public String addSpitterFromForm(**#ModelAttribute("spitter")** #Valid Spitter spitter, BindingResult bindingResult) {
if(bindingResult.hasErrors())
return "spitters/edit";
spitterService.saveSpitter(spitter);
return "redirect:/spitters/" + spitter.getUsername();
}
and just to check if it is getting the values from form,syso some values like syso(spitter.getUserName) to check if values are coming.
ALso, I believe that you are making a constructor and passing service to it ,so there is no need of #Inject
#Inject //#Autowired///Why are you injecting it if it is a constructor?
public SpitterController(SpitterService spitterService) {
this.spitterService = spitterService;
}
You have enctype="multipart/form-data in your FORM,
Check that you have something like that in your App-servlet.xml:
<bean id="multipartResolver" class=
"org.springframework.web.multipart.commons.CommonsMultipartResolver"
p:maxUploadSize="500000" />

Categories