-
-
Save darbyluv2code/debb69b1bf8010d84d50e0542e809ffb to your computer and use it in GitHub Desktop.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Student Confirmation</title> | |
</head> | |
<body> | |
The student is confirmed: ${student.firstName} ${student.lastName} | |
<br><br> | |
Favorite Language: ${student.favoriteLanguage} | |
</body> | |
</html> |
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Student Registration Form</title> | |
</head> | |
<body> | |
<form:form action="processForm" modelAttribute="student"> | |
First name: <form:input path="firstName" /> | |
<br><br> | |
Last name: <form:input path="lastName" /> | |
<br><br> | |
Favorite Language: | |
<form:radiobuttons path="favoriteLanguage" items="${student.favoriteLanguageOptions}" /> | |
<br><br> | |
<input type="submit" value="Submit" /> | |
</form:form> | |
</body> | |
</html> |
package com.luv2code.springdemo.mvc; | |
import java.util.LinkedHashMap; | |
public class Student { | |
private String firstName; | |
private String lastName; | |
private String favoriteLanguage; | |
private LinkedHashMap<String, String> favoriteLanguageOptions; | |
// create no-arg constructor | |
public Student() { | |
// populate favorite language options | |
favoriteLanguageOptions = new LinkedHashMap<>(); | |
// parameter order: value, display label | |
// | |
favoriteLanguageOptions.put("Java", "Java"); | |
favoriteLanguageOptions.put("C#", "C#"); | |
favoriteLanguageOptions.put("PHP", "PHP"); | |
favoriteLanguageOptions.put("Ruby", "Ruby"); | |
} | |
public String getFavoriteLanguage() { | |
return favoriteLanguage; | |
} | |
public void setFavoriteLanguage(String favoriteLanguage) { | |
this.favoriteLanguage = favoriteLanguage; | |
} | |
public LinkedHashMap<String, String> getFavoriteLanguageOptions() { | |
return favoriteLanguageOptions; | |
} | |
// define getter/setter methods | |
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; | |
} | |
} |
Hi Paul,
Can you repost the question to the Udemy classroom discussion Q&A? We can provide tech support on the Udemy platform. Here's the link to the classroom discussion Q&A:
https://www.udemy.com/spring-hibernate-tutorial/learn/v4/questions
thanks for your understanding.
Hi Paul,
Can you repost the question to the Udemy classroom discussion Q&A? We can provide tech support on the Udemy platform. Here's the link to the classroom discussion Q&A:
https://www.udemy.com/spring-hibernate-tutorial/learn/v4/questionsthanks for your understanding.
Hi Chad,
Just thought of clearing the confusion of others, I am already cleared of the things what going there.
Thanks!
I am trying to use radio button by using LinkedHashMap but in my jsp page i am unable to see multiple radio buttons with the label.
It is showing only one radio button with no labels.
Hi can we use List<> in Select statements ?
Will both value, label will become same in that case ?
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
Do we really need this line in student-confirmation.jsp file?
Why?
Hi Ashutosh,
Can you repost the question to the Udemy classroom discussion Q&A? We can provide tech support on the Udemy platform. Here's the link to the classroom discussion Q&A:
https://www.udemy.com/spring-hibernate-tutorial/learn/v4/questions
thanks for your understanding.
Thanks GURU!!
Hi Sai,
(snip of student-fom.jsp file)
As you can see the path & items are having different value in student-fom.jsp file
snip of Student.java file
also, you can find that both
path="favoriteLanguage" items="${student.favoriteLanguageOptions}"
are declared in Student.java file . So, through path, spring is doing the things for favoriteLanguage and rendering to the view page i.e., student-confirmation.jsp(snap of student-confirmation.java)