Re: Extra row appear in my jsp page after the Submit button is pressed
Problem is fixed. Thanks! On Mon, Mar 12, 2018 at 1:36 AM, Yasser Zamani wrote: > > > On 3/12/2018 6:03 AM, albert kao wrote: > >> name="persons[%{#stat.count}].name"/> > > I guess using #stat.index (instead of #stat.count) solves this issue. > Count will be 1,2 and 3 but Index will be 0,1 and 2 which is same as > that index that java uses. > > Regards. >
Re: Extra row appear in my jsp page after the Submit button is pressed
On 3/12/2018 6:03 AM, albert kao wrote: >name="persons[%{#stat.count}].name"/> I guess using #stat.index (instead of #stat.count) solves this issue. Count will be 1,2 and 3 but Index will be 0,1 and 2 which is same as that index that java uses. Regards.
Extra row appear in my jsp page after the Submit button is pressed
I am debugging my test program. When my test page http://localhost:8080/Struts2Example/updatePerson appeared in the browser, it displayed A B C in its own textfield and a Submit button, which is expected. However, after I edited the textfields and pressed the Submit button. The following appeared in the browser. Name :A Name :Aa Name :Bb Name :Cc I do not understand why an extra row (Name :A) appeared in the top with the rest of the names which I just entered. The following source codes is my test program. updatePerson.jsp: <%@page contentType="text/html" pageEncoding="UTF-8"%> http://www.w3.org/TR/html4/loose.dtd";> <%@taglib uri="/struts-tags" prefix="s" %> Update Person PersonAction updatePersonResult.jsp: <%@page contentType="text/html" pageEncoding="UTF-8"%> http://www.w3.org/TR/html4/loose.dtd";> <%@taglib uri="/struts-tags" prefix="s" %> Update Person Result Name : Person.java: public class Person { private int id; private String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } PersonAction.java: import java.util.ArrayList; import java.util.List; import com.opensymphony.xwork2.ActionSupport; public class PersonAction extends ActionSupport { private List persons; public PersonAction () { persons = new ArrayList(); int alpha = 65; for (int i = 0; i < 3 ; i++) { Person person = new Person(); person.setId(i); person.setName(String.valueOf((char)alpha++)); persons.add(person); } } public List getPersons() { return persons; } public void setPersons(List persons) { this.persons = persons; } //Initial Load method @Override public String execute() { return SUCCESS; } //Function that handles the form submit public String updatePerson() { for(Person person : persons) { System.out.println(person.getId() + ":" + person.getName()); } return SUCCESS; } } struts.xml: pages/updatePerson.jsp pages/updatePersonResult.jsp