Hi Sashi,

Thanks very much for your answer.
But my jsp page is a little different from yours, I have multibox and
text fields in my jsp page:
My jsp page is as followings:
<logic:iterate id="element" name="projects" >    
<tr>  
  <td align="right">
          <html:multibox property="selectedItems" >
            <bean:write name="element" property="id"/> 
          </html:multibox>
  </td>
       <td align="right"><strong>project Title:</strong></td>
       <td><html:text name="element" property="name"/>         
       </td>
 </tr>
</logic:iterate>
In my form:
private String[] name = null;  
  
public String[] getName() {
        return name;
}
public void setName(String[] name) {
        this.name = name;
}
private String[] selectedItems = {};    
  
public String[] getSelectedItems() { 
    return this.selectedItems; 
}   
public void setSelectedItems(String[] selectedItems) { 
    this.selectedItems = selectedItems; 
}

In my action:
String selectedItems[]=((MyForm)form).getSelectedItems();
String nameArray[]=((MyForm)form).getName();
Long actId=null;            
for(int i=0;i<selectedItems.length;i++){
 actId=new Long(selectedItems[i]);
 String name= nameArray [i]; 
}

In my action, I want to get "name" which is corresponding to the
checkbox that checked. But I always get the name which is corresponding
to the first checkbox, even I checked the second or third checkbox. How
can I know which checkbox related to which text field.

Thanks a lot!

Sarah


-----Original Message-----
From: Sashi Ravipati [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 12, 2003 2:10 PM
To: [EMAIL PROTECTED]
Subject: Re: how to pass more than one value when a multibox ischecked?

I used the following code for two text boxes, u can change it to your
need

I am also learning so bear with my suggestions.

1. Action form code:

private ArrayList personList;
    
  public void reset(ActionMapping mapping, HttpServletRequest request){
     this.personList = new ArrayList();
   // String num = request.getParameter("personListLength");
     String num ="5";
        try {
            if (num != null) {
                int len = Integer.parseInt(num);
                for (int i = 0; i < len; i++)
                    this.personList.add(new PersonBean());
            }
        }catch (NumberFormatException e) {
           e.printStackTrace();
        }
    }
  public PersonBean getPerson(int ndx) {
        return (PersonBean) personList.get(ndx);
    }
  public void setPersonList(int ndx, PersonBean p) {
        personList.set(ndx, p);
    }
  public ArrayList getPersonList(){
    return this.personList;
  }

2. jsp

<TABLE id="mytable">
  <logic:present name="personList"> 
<logic:iterate id="person" name="dynaTableForm" property="personList" 
   type="com.learning.struts.PersonBean" >

  <tr>
    <td>
       <html:text name="person" property="firstName" indexed="true"/>
    </td>
    <td>
        <html:text name="person" property="phoneNo" indexed="true"/>
    </td>
  </tr>
</logic:iterate>
</logic:present>
  
</TABLE>

3.PersonBean:
public class PersonBean implements Serializable
{
  String firstName;
  String phoneNo;

  public PersonBean()
  {
    super();
  }

  public String getFirstName()
  {
    return firstName;
  }

  public void setFirstName(String newFirstName)
  {
    firstName = newFirstName;
  }

  public String getPhoneNo()
  {
    return phoneNo;
  }

  public void setPhoneNo(String newPhoneNo)
  {
    phoneNo = newPhoneNo;
  }
}

Let me know if u need any further info.

Thanks


>>> [EMAIL PROTECTED] 06/12/03 01:35PM >>>
Hi,

I am not able to pass more than one value when a multibox is checked. Is
there any 
possible (or alternate) way to do it?

I have a table in the JSP where each row contains a multibox, and a
text field. When I select a checkbox and then enter some value in the 
text field and Submit, I need to get text field value related to this
checkbox. Is there a possible way to achieve this? 
How can I know which checkbox connects to which text field?

My jsp page is as followings:
<logic:iterate id="element" name="projects" >    
<tr>  
  <td align="right">
          <html:multibox property="selectedItems" >
            <bean:write name="element" property="id"/> 
          </html:multibox>
  </td>
       <td align="right"><strong>project Title:</strong></td>
       <td><html:text name="element" property="name"/>         
       </td>
</tr>
</logic:iterate>

Thanks in advance!

Sarah 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to