Table row data submit in struts 1.2

1.5k views Asked by At

I have a table with each rows contain checkbox (Like gmail inbox). I want to select few checkboxes and submit data in one go to action class. Please let me know how can i submit form using checkboxes.

1

There are 1 answers

1
Anand On BEST ANSWER

First of all you must ensure that your form bean and your form action class are already working otherwise even if you prepare your jsp file you will not be able to check its correctness (Struts 1.2 drawback)

Here goes your jsp code

<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<html:html>
    <html:form action="/formAction" method="GET">
        <table>
            <tr>
                <td>Data 1</td>
                <td>
                    <html:checkbox property="chk" value="value1"></html:checkbox>dln</td>
            </tr>
            <tr>
                <td>Data 2</td>
                <td>
                    <html:checkbox property="chk" value="value2"></html:checkbox>dln</td>
            </tr>
            <tr>
                <td>Data 3</td>
                <td>
                    <html:checkbox property="chk" value="value3"></html:checkbox>dln</td>
            </tr>
            <tr>
                <td>Data 4</td>
                <td>
                    <html:checkbox property="chk" value="value4"></html:checkbox>dln</td>
            </tr>
            <tr>
                <td>
                    <html:submit value="Register"></html:submit>
                </td>
            </tr>
        </table>
    </html:form>

Form Bean

public class MyFormBean extends ActionForm {
private String chk;
[...]//other fields
public String getChk() {
    return chk;
}

public void setChkString chk) {
    this.chk= chk;
}

[....] // other getters and setters }

Action class's execute method

[...]
MyFormBean myForm = (MyFormBean) form;
String chkVal = myForm.getChk();
[...]

Form Bean Entry in struts-config.xml

[...]
<form-bean name="myBean" type="pkg.MyFormBean"/>
[...]

Form Action Entry in struts-config.xml

[...]
<action path="/formAction" type="pkg.formAction" name="myBean" scope="request">
[...]