FW: [Httpunit-develop] Setting checkboxes when using Struts html:multibox
Brought to you by:
russgold
From: Jonathan J. <jon...@pl...> - 2004-03-08 21:29:58
|
Hi Rick, Thanks for looking into that. I'm away from my development machine for the next couple of days, so I would need to look at the source then. I guess, from my perspective, it would be preferable to have this functionality in a new release of httpunit but I really could do with testing the pages reliant on this in the interim. Is there channels I should go through to raise this as a feature worthy of inclusion? What timescales do we look to? If you wanted to help look at a solution in the interim, no pressure, I would be grateful. I would hope that this would be quite simple in that we get the checkbox whose name is "order", for example, and whose value=, say 1. Then we could toggle the checkbox. This one method:- toggleCheckBox(String name, String value); would be very useful for testing. And I guess the full implementation would be a method such as:- setCheckboxes(String name, Boolean []) I guess with testing we would supply the data to create the rows so we would always know how many checkboxes will be rendered. I did spend considerable time searching the Internet, etc. but no-one seems to have had the same problem? Apologies about the Boolean object - I think Outlook likes to auto capitalise my primitives! Kindest Regards JJ _____ From: htt...@li... [mailto:htt...@li...] On Behalf Of Rick Berman Sent: 08 March 2004 20:17 To: htt...@li... Subject: RE: [Httpunit-develop] Setting checkboxes when using Struts html:multibox JJ, You're right that calling setParameter(String, String[]) doesn't solve the problem. It sets values. You've already got values. You want to set the CHECKED option. When I face an issue like this, I'm pretty quick to look at the code (HttpUnit doesn't even require a separate download to have the source). To get an idea of whether you're asking for something easy or hard, I looked at the code in WebForm.toggleCheckbox(String). Various relevant mechanism pieces are in private methods and on a class with default (aka package private) visibility (the FormParameter class). In order to preserve the visibility and yet give the functionality you need, I'd look at adding two new methods to WebForm. These two methods would be overloads of toggleCheckbox and setCheckbox but which accept a "String value" argument as well that allows the caller to be more specific about which checkbox. As you suggest, a setCheckboxes(order, Boolean[] state) method could also work (note, it could be boolean[] as well). There is an implementation hurdle to overcome in that there is a HashMap, keyed by the name field, used to speed lookups to "parameters". This clearly won't work for anything in a form that can have a redundant name (not just your checkboxes). The brute force approach of iterating through the List holding the form controls looking for the one you're after would work. I'd have to look at the code more deeply before I could assess whether I thought it was worth changing the HashMap usage (for all uses) just to accelerate this situation. It may eventually be appropriate anyway for other reasons though. If you'd like help assembling a patch of this nature, I may be able to spend some time on it. Would you be comfortable building and then using a patched HttpUnit in your environment or would you need to wait for Russ to accept the patch and release a new HttpUnit? Rick Berman Ancilla SF LLC Scalable Systems Consulting 415-819-4865 _____ From: htt...@li... [mailto:htt...@li...] On Behalf Of Jonathan Jones Sent: Monday, March 08, 2004 11:57 AM To: htt...@li... Subject: RE: [Httpunit-develop] Setting checkboxes when using Struts html:multibox Hi, Thanks for the quick response. I did try that but when using the setParameter method, I think, it is actually setting the value of the checkbox e.g. I think I could go:- String values[] = {"0", "1", "2"}; form.setParameter("order", values); Where my html looks something like:- <input type="checkbox" name="order" value="0"> <input type="checkbox" name="order" value="1"> <input type="checkbox" name="order" value="2"> However what I am wanting is to just check, say one of the checkboxes, e.g. check just the one with value="0". Would I be able to do this with the string array (does that set them to selected? - giving the same affect as setCheckBox(true) ?) If so how do I not select one of the checkboxes? I was thinking something was needed like setCheckboxes(order, Boolean[] state); Thanks again - Jon _____ From: htt...@li... [mailto:htt...@li...] On Behalf Of Eric West Sent: 08 March 2004 19:35 To: htt...@li... Subject: Re: [Httpunit-develop] Setting checkboxes when using Struts html:multibox Hi Jonathan- I believe this is as simple as form.setParameter("order", checkBoxes); where "checkBoxes" is a String[ ] of the selected values. Hope this helps, Eric ----- Original Message ----- From: Jonathan Jones <mailto:jon...@pl...> To: htt...@li... Sent: Monday, March 08, 2004 10:51 AM Subject: [Httpunit-develop] Setting checkboxes when using Struts html:multibox Hi all, I have am having problems writing a http test method to try out my form. In my JSP page I generate a column of checkboxes using the Struts html:multibox property. Each multibox is on another row and there are as many rows as items in the my DataList:- <html:multibox property="order" value="<%=((DataListEntry)userProfile).getId()%>"> This produces HTML that looks like:- <input type="checkbox" name="order" value="0"> <input type="checkbox" name="order" value="1"> <input type="checkbox" name="order" value="2"> When my form is submitted I get a nice String[] order. So if the user had ticked the checkbox with value 0 and value 2 the String[] would be length 2 and contain {"0", "2"} However the problem comes when using httpunit. How do I select one or many of the check boxes? (They are all not selected by default) . I can't use the toggleCheckBox or setCheckBox methods as the only String name I know to give is "order", which sums up all of the checkboxes. Is there any way of doing this i.e. saying I want to select the checkbox whose value is 1? Any help will be very warmly received Kind Regards - JJ |