Re: id attribute of buttongroup tag

[email protected] Fri, 27 May 2005 09:49:03 +0200
Newsgroups gmane.comp.embedded.carlsbad-cubes
Organization http://freemail.web.de/
Message-ID <[email protected]>
List for Users of Carlsbad Cubes' Technologies and Products <[email protected]> schrieb am 26.05.05 23:00:07:
> 
> Hello,
> 
> thanks for the answer but
> 
> >List for Users of Carlsbad Cubes' Technologies and Products 
> ><[email protected]> schrieb am 13.05.05 00:55:41:
> >> 
> >> Hello,
> >> 
> >> it seems that id attribute of buttongroup tag is not handled 
> >> correctly.
> >> more precisely created ButtonGroup component is not assigned to
> >> correspondent field of client object.
> >
> >Vitali, just use 
> >bgroupSex = (ButtonGroup) swingEngine.find("bgroupSex");
>     
>     sorry this code won't work. swingEngine.find returns     
>     java.awt.Component while ButtonGroup is not a subclass of 
> Component.

You are correct, sorry for the wrong answer. I do not see a way to get this button group easily. If you really require this functionality, you have to tweak the Parser class around line 485. But then, allthough I did work with radiobuttons and also grouped them I did not miss the access to a concrete button group. Perhaps you do not need this at all and its not worth the trouble?


> 
> >I do not know of such a functionality to assign fields of the client 
> >in respect to the ids of xml elements.
> 
>    maybe I was using the wrong terminology. if you look into my test 
> case
>    again, after execution of new 
> SwingEngine(client).render("frame.xml");
>    radioMale and radioFemale fields of client object reference 
>    created RadioButton objects. While bgroupSex is null. 

Correct again, shame on me. Public fields *are* assigned through the Parser if it finds a identical named id in the xml parsed. This is apparently not done for a button group, correct. IMHO it is a matter of these lines at the location mentioned above, a la
        // start of old code
        ButtonGroup btnGroup = new ButtonGroup();
        while (k < n) {
          putIntoBtnGrp( JMenu.class.isAssignableFrom( obj.getClass() ) ? ( (JMenu) obj ).getItem( k++ ) : ( (Container) obj ).getComponent( k++ ), btnGroup );
        }
        // end of old code
        Object client = engine.getClient();
        Field clientButtonField = client.getClass().getField(child.getAttributeValue("id"));
        if (child.getAttribute("id") != null && clientButtonField != null) {
            if (Modifier.isPublic(clientButtonField.getModifiers()) && ButtonGroup.class.isAssignableFrom(clientButtonField.getType())) {
                clientButtonField.set(client, btnGroup);
            }
        }

Note: maybe the code is wrong, maybe it crushes your system. It is to illustrate the things that may assign the group to your public field only.

Frank