Solved

Check boxes functionality in Struts

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java / Linux and Regular Expressions 11 71
thymeleaf natural templating vs JSP 2 68
map related example 6 38
MySqlDump not dumping triggers 1 19
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now