Greetings!

 I have copied a custom component from "JavaServer Faces" by O'Reilly to
use in my myfaces application and I am getting ClassCastException
whenever I call "component.encodeBegin(context)": The following code is
what throws the ClassCastException:

Calling code:

UITabLabel tabLabel = (UITabLabel)child.getFacet("label");
encodeRecursive(context, tabLabel);

Called Method implementation:

private void encodeRecursive (FacesContext context, UIComponent
component) throws IOException {
                if (!component.isRendered()) {
                        return;
                }
                //throws ClassCastException
                component.encodeBegin (context);

                if (component.getRendersChildren()) {
                        component.encodeChildren(context);
                } else {
                        Iterator it = component.getChildren().iterator();
                        while (it.hasNext()) {
                                UIComponent child = (UIComponent)it.next();
                                encodeRecursive(context, child);
                        }
                }
                component.encodeEnd(context);
        }


The following is the custom component from the Book:

public class UITabLabel extends UICommand {
        
        public static final String COMPONENT_TYPE = "com.oim.faces.TabLabel";
        public static final String COMPONENT_FAMILY = "javax.faces.Command";

        public UITabLabel () {
                super();
                setRendererType ("javax.faces.Link");
        }
        
        public String getFamily () {
                return COMPONENT_FAMILY;
        }
        
        public void broadcast (FacesEvent event) {
                if (event instanceof ActionEvent) {
                        processAction((ActionEvent)event);
                }
        }
        

        private void processAction (ActionEvent event) {
                UIComponent panelTab = getParent();
                UIComponent panelTabbedPane = panelTab.getParent();
                Iterator it = panelTabbedPane.getChildren().iterator();
                while (it.hasNext()) {
                        UIComponent panel = (UIComponent)it.next();
                        if (panel.equals(panelTab)) {
                                panel.setRendered(true);
                        } else {
                                panel.setRendered(false);
                        }
                }
        }
        
        public MethodBinding getAction () {
                return null;
        }
        
        public void setAction (MethodBinding action) {
                throw new UnsupportedOperationException();
        }
        
        public MethodBinding getActionListener () {
                return null;
        }
        
        public void addActionListener (ActionListener listener) {
                throw new UnsupportedOperationException();
        }
        
        public ActionListener[] getActionListeners () {
                return new ActionListener[0];
        }
        
        public void removeActionListener (ActionListener listener) {
                throw new UnsupportedOperationException ();
        }
        
}

Any Ideas?

Curtney

Reply via email to