Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Check boxes functionality in Struts

Posted on 2004-09-28
4
Medium Priority
?
999 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 1000 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

636 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