2016-08-05 2 views
0

jsp 값을 contoller updateuser 메소드에 반환 할 때 commonMonth 값이 monthlyMemberSatus 목록의 null 값을 표시 할 때 다음 클래스를 사용 중입니다. 내가 도와 ... 내 코드에서 실수 모르는 나jsp에서 컨트롤러로 목록 값을 보내는 방법

컨트롤러 :

@RequestMapping(value = "/tempOpen",method = {RequestMethod.POST, RequestMethod.GET}) 
public ModelAndView monthMemberList(@ModelAttribute("commanMonth") CommanMonth commanMonth) { 
    commanMonth.setMonthlyMemberStatus(dataService.listMonthMember()); 
    return new ModelAndView("hlo","commanMonth",commanMonth); 
} 

@RequestMapping("/tempClose") 
public ModelAndView updateUser(@ModelAttribute("commanMonth") CommanMonth commanMonth) { 
    System.out.println(month.getMonthlyMemberStatus()); 

    dataService.updateRow(month); 
    return new ModelAndView("hlo","commanMonth",month); 
} 

모델 클래스 :

public class CommanMonth { 
private List<MonthlyMemberStatus> monthlyMemberStatus; 
public List<MonthlyMemberStatus> getMonthlyMemberStatus() { 
    return monthlyMemberStatus; 
} 

public void setMonthlyMemberStatus(List<MonthlyMemberStatus> monthlyMemberStatus) { 
    this.monthlyMemberStatus = monthlyMemberStatus; 
} 

JSP로 페이지 : hlo.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
pageEncoding="ISO-8859-1"%> 
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<!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> 
${commanMonth} 
<form:form modelAttribute="commanMonth" method="post" 
     action="tempClose.html"> 
     <table width="400px" height="150px"> 
      <c:forEach items="${commanMonth.monthlyMemberStatus}" var="list" varStatus="status"> 
       <tr> 
        <td><form:label path="monthlyMemberStatus[${status.index}].roomMembers.memberName" >${list.roomMembers.memberName}</form:label></td> 
        <td><form:input path="monthlyMemberStatus[${status.index}].noOffDays" value="31"/></td> 
        <%-- <td style="visibility:hidden"><form:input path="li[${status.index}].bookId" value="${list.bookId}" readonly="true"/></td> 
         <td><form:input path="temp[${status.index}].book" value="hloloo"/></td> 
        </tr> --%> 
        </c:forEach> 
        <tr> 
       <td></td> 
       <td><input type="submit" value="Update" /> 
       </td> 
      </tr> 
       </table> 
    </form:form> 
</body> 
</html> 

답변

0

당신은 어떤 getter 메소드에서 @ModelAttribute ("month")를 지정하지 않았다고 생각합니다. 그래서 스프링을 먼저 알아야합니다. 모델 속성이 컨트롤러는 '달'도

아래 대신 경로

<td><input name="monthlyMemberStatus[${status.index}].noOffDays" value="31"/></td> 

노트의 같은 입력 태그를 추가하려고 이름을 가진 : 컨트롤러 방법 또한 를 지정 RequestMethod.POST

@RequestMapping(value = "/tempOpen",method = {RequestMethod.POST, RequestMethod.GET}) 
public ModelAndView monthMemberList(@ModelAttribute("commanMonth") CommanMonth commanMonth) { 
    commanMonth.setMonthlyMemberStatus(dataService.listMonthMember()); 
    return new ModelAndView("hlo","commanMonth",commanMonth); 
} 

@RequestMapping(value="/tempClose", method = RequestMethod.POST) 
public ModelAndView updateUser(@ModelAttribute("commanMonth") CommanMonth commanMonth) { 
    System.out.println(month.getMonthlyMemberStatus()); 

    dataService.updateRow(month); 
    return new ModelAndView("hlo","commanMonth",month); 
} 
+0

내가 공공의 ModelAndView updateUser (@ModelAttribute ("commanMonth") CommanMonth commanMonth)하지만 여전히 목록 값이 – Manihtraa

+0

당신이 당신의 네트워크 호출을 확인하실 수 있습니다 null의 경우는, 때를 어떤 데이터를 통과 변경되었습니다 f12> 네트워크 탭> 요청 헤더 –

+0

을 눌러서 f12> 네트워크 탭> 요청 헤더에 어떤 데이터를 첨부했는지 묻습니다. – Manihtraa

0

요청 헤더 소스보기

POST /sdnext/tempClose.html HTTP/1.1 
    Host: localhost:8080 
    Connection: keep-alive 
    Content-Length: 135 
    Cache-Control: max-age=0 
    Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 
Origin: http://localhost:8080 
Upgrade-Insecure-Requests: 1 
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36(KHTML,like Gecko) Chrome/49.0.2623.112 Safari/537.36 
Content-Type: application/x-www-form-urlencoded 
Referer: http://localhost:8080/sdnext/tempOpen.html 
Accept-Encoding: gzip, deflate 
Accept-Language: en-US,en;q=0.8 
Cookie: JSESSIONID=B9D81D17E3B18B75494CBF8517B15995 
Form Data 
view source 
view URL encoded 
monthlyMemberStatus0.noOffDays:24 
monthlyMemberStatus1.noOffDays:31 
monthlyMemberStatus2.noOffDays:31 
monthlyMemberStatus3.noOffDays:31 
+0

메소드가 기본적으로 GET이므로 컨트롤러에서 RequestMethod.POST를 지정해야합니다. 메서드 .. 내 대답을보십시오. (다른 답변 탭을 게시하는 대신 답변에 주석을 추가 할 수 있습니다) –

+0

나는 get 메서드를 사용해도 작동하지 않습니다. 답장을 위해 열심히 기다리고있는 해결책을 얻으십시오. – Manihtraa

+0

여기에 참고 자료가 있습니다. http://viralpatel.net/blogs/spring-mvc-multi-row-submit-java-list/ –

0

의견 필드에 업데이트 할 수 없어 답변 필드에 게시했습니다. 여기 내 servlet.xml에 간다

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xsi:schemaLocation=" 
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> 

    <context:property-placeholder location="classpath:resources/database.properties" /> 
    <context:component-scan base-package="com.room" /> 

    <tx:annotation-driven transaction-manager="hibernateTransactionManager"/> 
    <bean id="jspViewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="viewClass" 
      value="org.springframework.web.servlet.view.JstlView" /> 
     <property name="prefix" value="/WEB-INF/views/" /> 
     <property name="suffix" value=".jsp" /> 
    </bean> 

    <bean id="dataSource" 
     class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
     <property name="driverClassName" value="${database.driver}" /> 
     <property name="url" value="${database.url}" /> 
     <property name="username" value="${database.user}" /> 
     <property name="password" value="${database.password}" /> 
    </bean> 

    <bean id="sessionFactory" 
     class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
     <property name="dataSource" ref="dataSource" /> 
     <property name="annotatedClasses"> 
     <list> 
      <value>com.room.model.RoomMembers</value> 
      <value>com.room.model.DailyExpense</value> 
      <value>com.room.model.MonthlyExpense</value> 
      <value>com.room.model.FinalSettlement</value> 
      <value>com.room.model.MemberInOut</value> 
      <value>com.room.model.SpecialExpense</value> 
      <value>com.room.model.MonthlyMemberStatus</value> 


     </list> 
     </property> 
     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.dialect">${hibernate.dialect}</prop> 
       <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> 
       <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>    
      </props> 
     </property> 
    </bean> 

    <bean id="hibernateTransactionManager" 
     class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
     <property name="sessionFactory" ref="sessionFactory" /> 
    </bean> 
</beans> 
관련 문제