Solved

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

Posted on 2003-11-03
7
2,699 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

An article on effective troubleshooting
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

803 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