Solved

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

Posted on 2003-11-03
7
2,708 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
[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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
trouble with PDF encryption using itext-1.3.1 17 88
best tutorial on log4j and logging for servlets/jsp codes 1 65
servlet example 17 59
eclipse buid path vs tomcat lib path 10 38
Enabling the Skype for Business Meeting Scheduler in Hybrid OWA
Read our guide on how to survive being on-call.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦

749 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