RE: BSelect and <input> elements of type radio and checkbox?

"Christian Cryder" <[email protected]>
Newsgroups gmane.comp.java.enhydra.barracuda.general
Message-ID <[email protected]>
Hi Jake,

> I guess my question is, why doesn't the BSelect component work
> when applied to <input> elements of type "radio" or "checkbox"?

Ok, this is a good question, so I'm actually going to respond back to the
Barracuda list as well, since others may want to chime in on the discussion.

I definitely see what you're saying, but I'm not certain if BSelect is the
solution (I'm not certain its NOT the solution either). I've never actually
thought of using a BSelect this way, so I'm kind of thinking out loud as I
ponder it.

I think its a novel idea, and there's nothing that would prevent you from
trying to implement it (ie. we're not already rendering BSelect for these
elements)...so the good news is that this would be new/additional
functionality - you wouldn't have to worry about breaking existing code.

That said, I think the difficulty arises in that the "grouping" of the
elements is loose, based solely on name, whereas with a <select> element you
are dealing with a well defined structure that can be easily
traversed/modified by the component rendering code. The biggest question I
would have is "how are you going to find all the input elements with that
particular name?" Maybe Elements.getElementByTagName(String tagName) would
do the trick...but I wonder what kind of performance impact it would have?
ie. would it require a complete traversal of the tree, or is the XMLC
implementation smart enough to create references to it so it could return a
NodeList without actually expanding everything else.

The other issue which would need to be considered is how you are going to
handle those items in the DOM when they don't have a name (ie. in our
mockups, we generally DON'T name the elements - we prefer to let the
Barracuda components set the name). Not sure if that's a big issue or not,
but its something that would have to be explored.

> If this does not seem like a good idea to you, how would you deal with,
> say, a set of 10 checkboxes where the instructions are "check all that
> apply to this question" or a set of 4 radio buttons where the instructions
> are "select whichever applies to you".

I would probably embed a Get_Data directive in each of them, like this:
(Get_Data.FooModel.SomeOption.1, Get_Data.FooModel.SomeOption.2, etc).
Notice the additional data parameters that I am adding on (.1, .2, etc).

This allows me to implement the getItem(TemplateDirective td) method in my
model, which can then do something like this:

    String key = td.getKeyName();
    if (key.equals("SomeOption")) {
        String data = td.getData();
        BToggleButton btg = new BToggleButton();
        btg.setName("GroupName");
        btg.setValue(...set the value based on the data...);
        return btg;
    } else {
    ...

What I am doing here is
a) handling all the checkboxes in one spot within the code
b) setting different values based on the data parameter in the directive

So in my mind, this is probably still the way I'd do it even BSelect did
work the way you've suggested (although I'm not diametrically opposed to
adding that support there - I just always find myself thinking of BSelect as
a component primarily aimed at manipulating <select> elements, rather than
groups of check bozes or radio buttons)

Does that help at all? There are a lot of different ways to skin a cat, and
this is certainly just one of them. But I think its pretty clean and
straightforward...

> You know, it would be really great if we created a FAQ where we
> detail how one uses Barracuda components to deal with common
> situations with form elements.

I agree. I keep hoping to be able to sit down and really upgrade all the
documentation, but I don't expect it to happen before this fall, given where
we are in our project cylce right now. :-( It IS on my list of things to get
to though, along with a sample project that would make it easy for people to
get up and running quickly and provide some examples of everything.

Comments and feedback welcome...

Christian
----------------------------------------------
Christian Cryder
Internet Architect, ATMReports.com
Project Chair, BarracudaMVC - http://barracudamvc.org
----------------------------------------------
"Coffee? I could quit anytime, just not today"


> -----Original Message-----
> From: Jacob Kjome [mailto:[email protected]]
> Sent: Wednesday, June 18, 2003 10:05 AM
> To: Christian Cryder
> Subject: BSelect and <input> elements of type radio and checkbox?
>
>
>
> Hi Christian,
>
> Can you comment on the thread "preselect a radio button based on a value"
> which I commented on a couple of times on the list?
>
> http://barracudamvc.org/lists/archives/barracuda/2003-June/006485.html
> http://barracudamvc.org/lists/archives/barracuda/2003-June/006486.html
>
> I guess my question is, why doesn't the BSelect component work
> when applied
> to <input> elements of type "radio" or "checkbox"?   Besides the
> structural
> difference between a <select> box with multiple nested option
> elements and
> <input> elements which are separate entities, they can act in almost
> exactly the same way.  When said <input> elements are given the
> same value
> for the "name" attribute, they work together in almost exactly
> the same way
> as a <select> box.  The benefit of this would be to allow for defining a
> single component to deal with creating a list of <input> elements
> and would
> also allow for using the DefaultListSelectionModel for defining which
> elements are pre-selected.
>
> If this does not seem like a good idea to you, how would you deal with,
> say, a set of 10 checkboxes where the instructions are "check all that
> apply to this question" or a set of 4 radio buttons where the
> instructions
> are "select whichever applies to you".  The checkbox case is, for all
> intents and purposes, exactly like a <select> box with multiple
> selections
> enabled and the radio button case is just like the a single selection
> <select> box.  BToggleButton really doesn't work for this, does it?  You
> have to return that to each individual <input> element you want to make
> checked or not checked.  That isn't the list behavior that is required.
>
> You know, it would be really great if we created a FAQ where we
> detail how
> one uses Barracuda components to deal with common situations with form
> elements.
>
> Jake
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.