문제

현재 2 개의 버튼이 포함 된 하나의 양식으로 작업 중입니다. 1 버튼을 클릭하면 아래와 같이 HTML 필드 블록이 발생합니다.

`

<table width="100%">
    <tbody><tr>

      <td class="style4" width="12%" align="center">CODE<span class="style3"> </span></td>
      <td width="18%"><input name="c_code[]" value="" id="c_code__" class="box_border" style="width: 120px;" type="text"></td>
      <td class="style3" width="15%" align="right">Price</td>
      <td width="7%"><input name="c_price[]" value="" id="c_price__" class="box_border" style="width: 40px;" type="text"></td>
      <td class="style3" width="4%" align="right">Qty</td>
      <td width="7%"><input name="c_qty[]" value="" id="c_qty__" class="box_border" style="width: 40px;" type="text"></td>
      <td class="style3" width="9%" align="right">On Sale </td>

      <td width="3%"><input name="c_onsale[]" id="c_onsale__" value="" type="radio">    
<label for="c_onsale"></label>
</td>
      <td class="style3" width="10%" align="center">Exposition</td>
      <td width="15%"><input name="c_exposition[]" size="15" value="" id="c_exposition__" class="box_border" type="text"></td>
    </tr>
  </tbody></table>

`

이제 사용자가 버튼을 클릭 할 때마다 위에 주어진 전체 블록이 AJAX 메소드 호출을 사용하여 HTML 양식에 포함됩니다.

  1. 이제 내 문제는 struts2 액션 클래스에서 모든 요소의 값을 배열로 얻을 수있는 방법입니다. 또는이 배열에 대한 세터 및 getter 메소드를 작성하는 방법.

다른 방식으로 위를 더 쉽게 수행 할 수있는 더 좋은 방법이 있습니까?

  1. 이와 같은 배열 필드에 대한 struts2 검증 파일을 작성하는 방법은 무엇입니까?

이 문제에서 누구든지 나를 도울 수 있습니까?

감사.

도움이 되었습니까?

해결책

자, 각 반복에 대한 배열의 색인을 사용하여 필드 이름을 바꿀 수 있으므로 C_Name [0], C_Name [1] 등으로 명명됩니다. 매핑은 문제없이 수행됩니다. 유효성 검사와 관련하여 귀하의 작업에 대한 서버 측 유효성 검사를 제안합니다.

문안 인사,

다른 팁

서버 측의 배열 대신 목록을 사용하고 Struts는 새 섹션 (UI의 새로운 요소 블록)을 자동으로 매핑합니다.

배열로 정의하면 크기가 동적으로 증가 할 수 없으므로 매번 새 섹션을 초기화 할 수 없습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top