Solved

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

Posted on 2003-11-03
7
2,692 Views
Last Modified: 2010-08-05
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!
0
Comment
Question by:rusco
  • 4
  • 2
7 Comments
 
LVL 14

Expert Comment

by:kennethxu
ID: 9682569
>> 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?
0
 

Author Comment

by:rusco
ID: 9683746
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 :-)
0
 
LVL 14

Accepted Solution

by:
kennethxu earned 100 total points
ID: 9684323
iframe is logically another page. a submit button usually only submit a form it belongs to, unless you use javascript to submit another form.  but no matter how you cannot submit 2 forms, not metion of 2 pages. that's the limitation of browser and has nothing to do with struts. thers is nothing that struts can do while browser didn't supply the informaiton in the first place.

if you intend to submit all the information, then why not put everything in one page instrea  of using iframe?
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 14

Expert Comment

by:kennethxu
ID: 9831234
glad to know you probem is resolved.
is there anything wrong in my comments lead to a B grade?
0
 

Author Comment

by:rusco
ID: 9834600
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!
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9834642
No prolem, that happends. Thank you too :-)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

A safe way to clean winsxs folder from your windows server 2008 R2 editions
Use of TCL script on Cisco devices:  - create file and merge it with running configuration to apply configuration changes
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

19 Experts available now in Live!

Get 1:1 Help Now