Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4913

when using an custom array as a filed in struts 2 action form textfiled data from jsp page in not populating into custom array but populating in String array or array list

    XMLWordPrintableJSON

Details

    • Task
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • None
    • 2.5.16
    • None
    • None

    Description

      1> SampleAction.java

      public class SampleAction{
          private ValueHolderExt[] name = new ValueHolderExt[17];
          private String[] age = new String[17]; 
              public ValueHolderExt[] getName() {
      		return name;
      	}
      
      	public void setName(ValueHolderExt[] name) {
      		this.name = name;
      	}
      
      	public String[] getAge() {
      		return age;
      	}
      
      	public void setAge(String[] age) {
      		this.age = age;
      	} 
      public String execute() throws Exception { 
      return "success";
      }
      }
      

      2> ValueHolderExt.java

      import java.io.Serializable;
      
      public class ValueHolderExt implements Serializable {
      
          private static final long serialVersionUID = 7813961312803493438L;
      
          private String data = "";
      
      public String getData() {
      return data;
      }
      
      public void setData(String data) {
      this.data = data;
      }   
      
      }
      

      3> sample.jsp

      <%@ include file="/WEB-INF/jsp/includes/include.jsp"%>
      
      
      <s:form onsubmit="return doFormSubmit();" method="post"
      action="/membersPersonalDetailsSubmit">
      
      <fieldset>
      <legend>
      <fmt:message key="membersPersonalDetails.title" />
      <fmt:message key="general.required.instruction" />
      </legend>
      
      <table id="zebra" border="0" cellspacing="0" width="100%">
      <thead>
      <tr>
      <th><s:text name="Name" /></th>
      <th>
      <!--  <display:fieldLabel styleClass="borderlesslabel" key="membersPersonalDetails.field.gender" property="gender" errors="gender|gendertitle" required="true"/> -->
      <s:text name="Age" />
      </th>
      
      </tr>
      </thead>
      <s:iterator begin="0" end="5" var="idx">
      <c:set var="zebraClass" value="odd" scope="page" />
      <c:if test="{idx % 2 eq 0}">
      <c:set var="zebraClass" value="even" scope="page" />
      </c:if>
      
      <tr class='<c:out value="${zebraClass}" />'>
      <td><c:out value='${idx+1}' /> <s:textfield
      name="name[%{#idx}].data" id="name[%{#idx}].data" size="15" /></td>
      
      <td><s:textfield name="age[%{#idx}]" id="age[%{#idx}]"
      size="15" /></td>
      </tr>
      </s:iterator>
      
      </table>
      </fieldset>
      <br />
      <br />
      
      <div id="navRight">
      <s:submit cssClass="button yellow buttonClick"
      key="membersPersonalDetails.button.continue.tooltip" value="continue" />
      </div>
      </div>
      </s:form>
      

      Attachments

        1. Source.txt
          4 kB
          amol

        Activity

          People

            Unassigned Unassigned
            amolbd amol
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: