Solved

Check boxes functionality in Struts

Posted on 2004-09-28
4
987 Views
Last Modified: 2010-10-05
Description of the problem:
I have a form which will display rows (Eg 100) with two columns (C1, C2). This form should display empty (unchecked) boxes for all the 100 rows on left  side. This form also has a "Delete" button. Whenever a user wants to delete some displayed rows, user selects check boxes associated with that rows.  When the user clicks the Delete button, only those rows with checked boxes, should be retrieved in action class to be passed to delete method.



This is what I have in jsp page
<logic:iterate id = "vehicleLeaseListrowid"  name="vehicleLeaseList"
                         scope = "request" type ="com.lvm.vehicle.server.data.VehiclesLeaseValueBean">
             <tr>
             <td><html:multibox property="selections"><bean:write name="vehicleLeaseListrowid" property="vehicleId"/></html:multibox></td>      
             <td class="lblBlk1"><bean:write name = "vehicleLeaseListrowid" property = "vehicleDescription"/></td>
             <td class="lblBlk1"><bean:write name = "vehicleLeaseListrowid" property = "leaseAmount"/></td>
            </tr>



This is what I have in actionform
private String[] selections = {};
      
      public void setSelections(String[] selections){
            this.selections = selections;
      }

      public String[] getSelections(){
            return this.selections;
      }



This is what I have in reset method
      selections = null;



This is the exception error I am facing:
SRVE0026E: [Servlet Error]-[BeanUtils.populate]: java.lang.IllegalArgumentException: argument type mismatch
      at java.lang.reflect.Method.invoke(Native Method)
      at org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(PropertyUtils.java:1650)
      at org.apache.commons.beanutils.PropertyUtils.setNestedProperty(PropertyUtils.java:1545)
      at org.apache.commons.beanutils.PropertyUtils.setProperty(PropertyUtils.java:1574)
      at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:919)
      at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:726)


Please let me know if any more information is needed??
Can some body please help me??

Thank You
0
Comment
Question by:prasadp69
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Author Comment

by:prasadp69
ID: 12172100
The actual column names are "vehicleDescription"  and "leaseAmount" not c1 and c2.

Thank You
0
 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 250 total points
ID: 12172529


In this example,

    <logic:iterate id="item" property="items">
      <html:multibox property="selectedItems">
       <bean:write name="item"/>
      </html:multibox>
       <bean:write name="item"/>
    </logic:iterate>

The labels for the individual checkboxes is in the items property. The list of selected items is in an array named selectedItems. Items that are not selected are not present in the selectedItems array. The multibox checks the selectedItems array for the current item. If it is present, it writes a checked checkbox. If not, it writes an unchecked checkbox.

Given an ActionForm setup like this

    private String[] selectedItems = {};
    private String[] items = {"UPS","FedEx","Airborne"};
    public String[] getSelectedItems() {
      return this.selectedItems;
    }
    public void setSelectedItems(String[] selectedItems) {
      this.selectedItems = selectedItems;
    }

The markup in the example would generate three checkboxes, labeled UPS, FedEx, and Airborne.

    <input type="checkbox" name="selectedItems" value="UPS">UPS
    <input type="checkbox" name="selectedItems" value="FedEx">FedEx
    <input type="checkbox" name="selectedItems" value="AirBorne">AirBorne

Initially, the selectedItems array would be empty. If UPS were checked and submitted, it would become the equivalent of

    private String[] selectedItems = {"UPS"};

If UPS and Airborne were both checked, it would become the equivalent of

    private String[] selectedItems = {"UPS","Airborne"};

And when the checkboxes are rendered, the appropriate elements are automagically checked by the multibox tag.

    <input type="checkbox" name="selectedItems" value="UPS" checked="checked">UPS
    <input type="checkbox" name="selectedItems" value="FedEx">FedEx
    <input type="checkbox" name="selectedItems" value="AirBorne" checked="checked">AirBorne

To provide different sets of labels and values, the standard LabelValueBean class [org.apache.struts.util.LabelValueBean] (since 1.1) can be used with the multibox control.

    <logic:iterate id="item" property="items">
      <html:multibox property="selectedItems">
        <bean:write name="item" property="value"/>
      </html:multibox>
        <bean:write name="item" property="label"/>
    </logic:iterate>
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
login form jsp example 2 50
ejb entity bean example 2 37
jmeter usage 4 37
Java pass by reference 3 21
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This video teaches viewers about errors in exception handling.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question