Solved

Check boxes functionality in Struts

Posted on 2004-09-28
4
984 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
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

776 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