• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Can we send multiple textfield of same type in struts

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

<form name="myMultipleForm" action="multipleNameAction.do">
<tr><td><html:text name="myMultipleForm" property="names[0]"/></td></tr>
<tr><td><html:text name="myMultipleForm" property="names[1]"/></td></tr>
<tr><td><html:text name="myMultipleForm" property="names[2]"/></td></tr>
<tr><td><html:text name="myMultipleForm" property="names[3]"/></td></tr>
</form>

these text boxes are static here and we will enter different names in these fields

How i can submit these values without using javascript.

public MyMultiForm extends ActionForm{



private String [] names;

....getters & setters
}
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why would you need to use JavaScript?

(I don't remember much about Struts 1, but isn't there an indexed property flag or something like that?)
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You do not need to use javascript.



Just change the code to the above form. Struts will automatically find multiple text boxes of the same name and feed into your array.

If you want to use the indexed property then you need to have it within some form of an iterator. (<logic:iterate or ><c:for)..

The above change will make your code work (the only problem is theoretically it cannot be guranteed that the order in which the data will be sent will be preserved).

>
 
Vijendra Kulhade
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah you are right I have written the code something like this..

public class MyMultipleForm extends ActionForm
{

private List resultList; // list of employee objects

public void setResultList(List resultList)
{
this.resultList= resultList;
}

public List geResultList()
{
return this.resultList;
}


public Employee getEmployee(int index)
{

if(this.resultList== null)
{
this.resultList= new ArrayList();
}

// indexes do not come in order, populate empty spots
while(index >= this.resultList.size())
{
this.resultList.add(new Employee());
}

// return the requested item
return (Employee) resultList.get(index);
}

}


Employee bean is like this.............

public class Employee
{
private String name;
private String surName;
private String employeeNo;

<constructors plus get and set methods here>
}



I made the jsp like this....................


<html:form action="/SaveEmployeeIndexed" >
<table width="100%" border="1">
<tr>
<th width="25%" >Product ID</th>
<th width="60%" >Name</th>
<th width="15%">Quantity</th>
</tr>
<logic:iterate id="employee" name="MyMultipleForm " property="resultList">
<html:hidden name="employee" property="employeeId" indexed="true" />
<tr>
<td><bean:write name="employee" property="name" /></td>
<td><bean:write name="employee" property="surName" /></td>
<td><html:text name="employee" property="employeeId" size="30" indexed="true" /></td>
</tr>
</logic:iterate>
</table>
<html:submit>Save</html:submit>
</html:form>


Here I have one text field which I want to edit. for writing the bean:write I am using this Action Class..........................



public class DisplayOrderIndexedAction extends Action
{

public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception
{
MyMultipleForm indexedForm = (MyMultipleForm ) form;

// get the list of orders from our business layer
List resultList = Some backend proc call to get the employee data;

// save the list of order on our form
indexedForm.setResultList(resultList);

return mapping.findForward("success");
}


the problem is when I am submitting the for it is not saving the value of text field into the myMultipleForm....

can any one help me out...this thing is not working at all when our formbean is in request scope but when we keep this in session scope we are getting the same list which we are using to pupulate the page while we want the edited value also....

Please Help..
}
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.
 
Aditya Keyal
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I wonder is how is your form submission working in the first place.



and



In the jsp you are setting a property called employeeId while that property is just not available in the Employee object at all. The approach of using your List is correct. From the front of it the only apparent mistake is that a mismatch between the property "employeeId" and also I have one concern . Why are you using employeeId twice in 2 fields (one hidden and one text). That approach is not recommended in any situation.

 
Vijendra Kulhade
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no that hidden field is not there and in form employeeId should be the correct variable. I have written it by mistake. second thing I have only written the code to display my page. for saving the text field I have writen different action.
 
reply
    Bookmark Topic Watch Topic
  • New Topic