Link to home
Start Free TrialLog in
Avatar of rusco
rusco

asked on

STRUTS: Getting values of the checked 'checkboxes' using <html:multibox>

Hi,

I seem to be having problems trying to get the values of the selected checkboxes I have. I have a page (in a frame) that iterates over some results taken from a db (using a hashmap).

my configItem.jsp:

    <html:form action="/ConfigItemListAction"
               name="configItemsListForm"
               type="com.hp.adm.workOrder.ConfigItemsListForm" >
               
<logic:iterate id="configItem" name="configItems" scope="session">

<tr>
    <td width=20 height=18 valign=top align="left"  bgcolor="#E7E7E7" class="bold" scope="row"><div style="width:20px;overflow:hidden">
        <html:multibox property="selectedItems">
            <bean:write name="configItem" property="key" />
        </html:multibox>
            <bean:write name="configItem" property="key" />
      </td>
      <td width=80 height=18 valign=top align="left"  bgcolor="#E7E7E7" scope="row">
        <bean:write name="configItem" property="value.searchCode"/>
      </td>
      <td valign=center width="1"  height=18  nowrap bgcolor="#333366"><html:img src="/ADM/images/s.gif" /></td>
      <td width=156 height=18 valign=top align="left"  bgcolor="#E7E7E7" scope="row">
        <bean:write name="configItem" property="value.ciName2"/>
        <input type="textbox" name="databaseCheck" value="<bean:write name="configItem" property="value.inDatabaseAlready"/>">        
      </td>
</tr>

</logic:iterate>

</html:form>

As you could see, I use the hashmap's key as the value for the <html:multibox> that is iterated. Unfortunately, when I click on a submit button (that is located from another frame) I can't seem to get the values to show. I either get a NULL or a NullPointerException when I try to get the length of the array.

Here's my jsp that has the submit button: (take note it doesn't have a <html:form> tag anymore)

<A href="/ADM/RemoveConfigItem.do"><html:img src="/ADM/images/delete_button.gif" border="0"/></A>

Here's my actionform:

public class ConfigItemsListForm extends ActionForm {
   
    protected String[] selectedItems = null;
   
    public String[] getSelectedItems() {
        return this.selectedItems;
    }
       
    public void setSelectedItems(String[] selectedItems) {
       this.selectedItems = selectedItems;
    }
   
    public void reset(ActionMapping mapping, HttpServletRequest request)
    {
        this.selectedItems = null;
    }    

}

Finally, my Action (which is where the /RemoveConfigItem.do points to):

ConfigItemsListForm configItemsListForm = (ConfigItemsListForm)form;
               
 //Get the list of selected checkboxes
 String[] removeConfigList = configItemsListForm.getSelectedItems();

System.out.println(removeConfigList); //gives me NULL
System.out.println(removeConfigList.length); //gives me a NullPointerException

...other codes that manipulate the removeConfigList...

What am I doing wrong? Thanks in advance!
Avatar of kennethxu
kennethxu

>> Here's my jsp that has the submit button: (take note it doesn't have a <html:form> tag anymore)
how can a submit button in one jsp page to submit checkbox in another jsp page? is this what u r trying to do?
Avatar of rusco

ASKER

Technically yes. The design of the page is to have an iframe that will have two pages in it. One is the page that has values that are iterated on the screen (along with the checkbox) and the submit button (as well as two other buttons) will be placed in another screen. I'm quite not sure how to explain this properly though, jsut that it will end up looking like a little panel that of a screen that has buttons and the values in the center of that 'panel'. The two pages are name configItem.jsp and configItemFrame.jsp.

Anyway, I thought that when in the execute method you can get the 'values' of a given form (whatever form that is) by using the getNameOfMethod of that given form? Kinda new in struts so I'm not quite sure I understand this well.

Thanks :-)
ASKER CERTIFIED SOLUTION
Avatar of kennethxu
kennethxu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
glad to know you probem is resolved.
is there anything wrong in my comments lead to a B grade?
Avatar of rusco

ASKER

Hi Kennethxu,

Sorry about that, it was suppose to be a grade A. I think I clicked on grade B when I submitted. I'll be asking the moderators if they could possibly get this changed. :-)

Thanks!
No prolem, that happends. Thank you too :-)