Solved

Check boxes functionality in Struts

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

707 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

12 Experts available now in Live!

Get 1:1 Help Now