NOTE: The Info object is nothing more than a wrapper class for Map that contains all the parameters from the request. Also, I stuff the Info object in the user's sesison using the session id as the key, and prefix it with some key phrase so that I don't have collisions with other objects I put in the session.
-ernie
/**
* Given the "name" of a checkbox group, and the "value"
of the checkbox
* input, returns the word "checked" if the value is
contained within
* the list of values returned by the form.
*
* If the checkbox is stand-alone (with the intent
of being a true/false mechanism),
* then this method must work in conjunction with a
hidden field that has the same name
* but the opposite boolean value as the checkbox.
This is necessary in order to detect
* an un-checked checkbox, as an unchecked checkbox
returns nothing in the http request.
* A typical implementation in a JSP would look like
the following:
*
* <% Info info = (Info) session.getValue ("my_form."
+ session.getId()); %>
* ...
* ...
* <input type="hidden" name="show_page" value="false">
* <input type="checkbox" name="show_page" value="true"
<%= info.getCheckBox("show_page", "true") %>>
*
* @param name The selection list name
* @param value The option value.
* @return Returns either the word "checked" or an
empty string ""
*/
public String getCheckbox (String name, String value)
{
String s = "", list = "";
int testLoc = 0;
try {
list = ((String)info.get(name));
testLoc = list.indexOf(value);
} catch (NullPointerException npe) {
list = "";
}
if (testLoc >= 0)
{
if (list.regionMatches(testLoc,
value, 0, 4))
s = "checked";
}
return s;
}
Nic Ferrier wrote:
>>> Peter Tierney <[EMAIL PROTECTED]> 24-Jan-00 7:17:25 AM
>>>>If the radio wasn't checked at all the first line of output will be
>null, but if I test against that I get a NullPointerException.> If I use:
> out.println(req.getParameterValues("radio1"));
>I get something like:
>[Ljava.lang.String;@7310a09a>I don't need the memory address, I need the string in the memory
>address.It's not giving you the memory address - it's really giving you an
array object. If you check the API you will see that the result of
getParameterValues() is a String[] of however many multiple values
were returned.You might be able to achieve what you want by simply:
String radio=req.getParameterValue("radio_button_id");
if(radio==null || radio.length()<1)
{
//radio didn't come back so set it to "no" or something
}
else
//radio did come back so carry on...>This is something that should be simple and it's making me want to
stay
>with Perl, if Servlet development is this peculiar.Trouble is they come at it from completly different ends of the
field. I've used both and can honestly say that servlets are better
than any Perl solution currently available (until multi-threaded Perl
gets into mod_perl).>Thanks for ANY help given.
Our pleasure.
Nic Ferrier
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
begin:vcard n:Varitimos;Ernie tel;cell:781-929-3856 tel;home:781-784-1997 tel;work:781-784-3900 x-mozilla-html:TRUE url:http://www.skyserver.com org:Skyserver Consulting, Inc. adr:;;144 Upland Rd;Sharon;MA;02067; version:2.1 email;internet:[EMAIL PROTECTED] title:President fn:Ernie Varitimos end:vcard
