Created
February 20, 2014 10:52
-
-
Save kmb385/9111118 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" | |
pageEncoding="ISO-8859-1"%> | |
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> | |
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %> | |
<!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>Insert title here</title> | |
</head> | |
<body> | |
<form:form action="envDetails" method="POST" commandName="environmentForm"> | |
<c:forEach items="${environmentForm.environments}" varStatus="i" var="env"> | |
Name of Environment<c:out value="${(i.index)+1}"/>: | |
<form:input path="environments[${i.index}].name" type="text"/> | |
<br> | |
Path of Environment<c:out value="${(i.index)+1}"/> : | |
<form:input path="environments[${i.index}].path" type="text"/> | |
<br><br> | |
</c:forEach> | |
<input class="submitStyle" type="submit" value="SUBMIT" /> | |
</form:form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.mvc.test; | |
public class Environment { | |
private String name; | |
private String path; | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public String getPath() { | |
return path; | |
} | |
public void setPath(String path) { | |
this.path = path; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.mvc.test; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class EnvironmentForm { | |
private String projectName; | |
private List<Environment> enivronments; | |
public EnvironmentForm() { | |
this.enivronments = new ArrayList<Environment>(); | |
} | |
public String getProjectName() { | |
return projectName; | |
} | |
public void setProjectName(String projectName) { | |
this.projectName = projectName; | |
} | |
public List<Environment> getEnvironments() { | |
return enivronments; | |
} | |
public void setEnvironments(List<Environment> enviroments) { | |
this.enivronments = enviroments; | |
} | |
public void add(Environment env) { | |
this.enivronments.add(env); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.mvc.test; | |
import java.text.DateFormat; | |
import java.util.Date; | |
import java.util.Locale; | |
import javax.servlet.http.HttpServletRequest; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.stereotype.Controller; | |
import org.springframework.ui.Model; | |
import org.springframework.validation.BindingResult; | |
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.bind.support.SessionStatus; | |
import org.springframework.web.context.request.WebRequest; | |
import org.springframework.web.servlet.ModelAndView; | |
/** | |
* Handles requests for the application home page. | |
*/ | |
@Controller | |
public class HomeController { | |
@RequestMapping(value="envDetails",method=RequestMethod.GET) | |
public ModelAndView setBackingForm(HttpServletRequest request) | |
{ | |
EnvironmentForm envf=new EnvironmentForm(); | |
envf.setProjectName("Test"); | |
for(int i=0;i<2;i++){ | |
envf.add(new Environment()); | |
} | |
return new ModelAndView("envDetails","environmentForm",envf); | |
} | |
@RequestMapping(value = "envDetails", method = RequestMethod.POST) | |
public ModelAndView viewFolderInput( | |
@ModelAttribute("environmentForm") EnvironmentForm environmentForm,BindingResult binding,WebRequest request, SessionStatus status) { | |
for(Environment env:environmentForm.getEnvironments()){ | |
System.out.println(env.getName()); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment