Re: How to initialize radiobuttons/checkboxes from a bean
At 06:31 AM 7/21/99 +, Craig R. McClanahan wrote: Bill O'Keefe wrote: I am using a bean to initialize the form fields of a JSP. I understand how to use jsp:getProperty... to initialize text fields, or to just include a string within the page. However I'm a bit unclear on the best way to initialize radio buttons and check boxes. The only thing I've come up with is the following (somewhat ugly) solution: jsp:useBean id="mbean" class="..." scope="session"/ ... input type="radio" name="choice" value="apparel" % if (mbean.getChoice() != null mbean.getChoice().equals("apparel")) out.println("checked"); % Apparel input type="radio" name="choice" value="computers" % if (mbean.getChoice() != null mbean.getChoice().equals("computers")) out.println("checked"); % Computers ... Is there a more elegant way to accomplish this? Thanks. For radio buttons, I haven't discovered anything that is significantly nicer than this. However, an approach I'm taking on SELECT elements might be of interest. The basic idea is to add a read-only property to the bean itself that returns a String containing the HTML to generate the select element. Inside the bean's "get" method you can hide all the messy logic required to build this, and then in your JSP page you just say: % out.println(mbean.getMySelectElement() % to render the entire thing. You might be able to apply the same principle by having a pseudo-property that rendered the HTML for all of your radio buttons and their options and prompts. Thanks for the suggestion. While this does indeed 'cleanup' the JSP, it requires that JSP authors work more closely with the Java programmers to coordinate the construction of the page. My ideal goal is to be able to construct JSP that contain just HTML, and JSP tags to provide the dynamic data (i.e., no Java scriptlets at all). This seems to be the recommended model as I understand it. Unfortunatly, the more I get into this, it appears that this is not possible (at least, with JSP 1.0). While I've come to accept the use of scriplets to provide the required 'looping' constructs (e.g., to iterate through the records of a database query), I was hoping that I could just use JSP tags to initialize the various form fields. The more that scriplets are REQUIRED in a JSP to do basic tasks like initializing form fields, the less desirable this programming model is to web page developers (at least to the ones I talked to about this). I think this is why they prefer template-based systems (like Cold Fusion, etc.). This is all just my opinion, of course. Also, since I'm not really a web page developer (just a programmer :-), I'm not speaking from personal experience, though their objection to including LOTS of scriptlets in a page does make sense to me. Comments are welcome. Thanks. -- Bill -- Bill O'Keefe [EMAIL PROTECTED] Open Market, Inc.http://www.openmarket.com/ One Wayside Road TEL: 781.359.7296 Burlington, MA 01803 FAX: 781.359.8200 === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JSP-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
How to initialize radiobuttons/checkboxes from a bean
I am using a bean to initialize the form fields of a JSP. I understand how to use jsp:getProperty... to initialize text fields, or to just include a string within the page. However I'm a bit unclear on the best way to initialize radio buttons and check boxes. The only thing I've come up with is the following (somewhat ugly) solution: jsp:useBean id="mbean" class="..." scope="session"/ ... input type="radio" name="choice" value="apparel" % if (mbean.getChoice() != null mbean.getChoice().equals("apparel")) out.println("checked"); % Apparel input type="radio" name="choice" value="computers" % if (mbean.getChoice() != null mbean.getChoice().equals("computers")) out.println("checked"); % Computers ... Is there a more elegant way to accomplish this? Thanks. -- Bill -- Bill O'Keefe [EMAIL PROTECTED] Open Market, Inc.http://www.openmarket.com/ One Wayside Road TEL: 781.359.7296 Burlington, MA 01803 FAX: 781.359.8200 === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JSP-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
Re: How to initialize radiobuttons/checkboxes from a bean
what about: adding an "equalsChoiceIgnoreCase(String s)" method to your bean (or a bean wrapper if you don't want to ?pollute? existing bean code) using the following jsp scriptlet: % out.println((mybean.equalsChoiceIgnoreCase("Apparel")) ? "checked" : ""); % i may be off a smidgen syntactically but i believe the idea has been conveyed. hope this helps, - james Bill O'Keefe wrote: I am using a bean to initialize the form fields of a JSP. I understand how to use jsp:getProperty... to initialize text fields, or to just include a string within the page. However I'm a bit unclear on the best way to initialize radio buttons and check boxes. The only thing I've come up with is the following (somewhat ugly) solution: jsp:useBean id="mbean" class="..." scope="session"/ ... input type="radio" name="choice" value="apparel" % if (mbean.getChoice() != null mbean.getChoice().equals("apparel")) out.println("checked"); % Apparel input type="radio" name="choice" value="computers" % if (mbean.getChoice() != null mbean.getChoice().equals("computers")) out.println("checked"); % Computers ... Is there a more elegant way to accomplish this? Thanks. -- Bill -- Bill O'Keefe [EMAIL PROTECTED] Open Market, Inc.http://www.openmarket.com/ One Wayside Road TEL: 781.359.7296 Burlington, MA 01803 FAX: 781.359.8200 === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JSP-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help". === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JSP-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
Re: How to initialize radiobuttons/checkboxes from a bean
At 10:27 PM 7/20/99 -0700, James Todd wrote: what about: adding an "equalsChoiceIgnoreCase(String s)" method to your bean (or a bean wrapper if you don't want to ?pollute? existing bean code) using the following jsp scriptlet: % out.println((mybean.equalsChoiceIgnoreCase("Apparel")) ? "checked" : ""); % i may be off a smidgen syntactically but i believe the idea has been conveyed. hope this helps, Thanks. That is definitly an improvement. However, what I'm really looking for is a way to avoid scriplets altogether, i.e., just use some jsp:xxx tag to do the trick. I understand JSP 1.1 may help in this regard, though I really haven't looked into that yet. Anyway, your code is much better than mine :-) Thanks again. - james Bill O'Keefe wrote: I am using a bean to initialize the form fields of a JSP. I understand how to use jsp:getProperty... to initialize text fields, or to just include a string within the page. However I'm a bit unclear on the best way to initialize radio buttons and check boxes. The only thing I've come up with is the following (somewhat ugly) solution: jsp:useBean id="mbean" class="..." scope="session"/ ... input type="radio" name="choice" value="apparel" % if (mbean.getChoice() != null mbean.getChoice().equals("apparel")) out.println("checked"); % Apparel input type="radio" name="choice" value="computers" % if (mbean.getChoice() != null mbean.getChoice().equals("computers")) out.println("checked"); % Computers ... Is there a more elegant way to accomplish this? Thanks. -- Bill -- Bill O'Keefe [EMAIL PROTECTED] Open Market, Inc.http://www.openmarket.com/ One Wayside Road TEL: 781.359.7296 Burlington, MA 01803 FAX: 781.359.8200 === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JSP-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".