You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Curtney Jacobs <c....@comcast.net> on 2005/07/28 10:18:51 UTC
ClassCastException calling encodeBegin
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
RE: ClassCastException calling encodeBegin
Posted by Curtney Jacobs <c....@comcast.net>.
Ok, I decided to extend HtmlCommandLink directly instead of UICommand
for my UITabLabel. It appears this works. No more ClassCastException.
Everything displays correctly.
However, I am still puzzle as to why this works. Because HtmlCommandLink
subclasses UICommand, thus I should be able to do this:
(HtmlCommandLink)component).getOnclick();
Assumming the above is what was causing the ClassCastException.
On Thu, 2005-07-28 at 11:12 -0700, Curtney Jacobs wrote:
> I might have narrowed down the ClassCastException to the following
> method in
> "org.apache.myfaces.renderkit.html.HtmlLinkRenderBase.renderJavaScriptAnchorStart"
>
> I am not to sure, but the ClassCastException could be comming from
>
> ((HtmlCommandLink)component).getOnclick();
>
> I am viewing the source code via browser, unfortunately no line number
> comes with it, so I cannot narrow to which cast is causing the error. It
> says line 323. Perhaps someone can? I have included the function below
>
> Hmm?
>
> protected void renderJavaScriptAnchorStart(FacesContext facesContext,
> ResponseWriter writer,
> UIComponent component,
> String clientId)
> throws IOException
> {
> //Find form
> UIComponent parent = component.getParent();
> while (parent != null && !(parent instanceof UIForm))
> {
> parent = parent.getParent();
> }
>
> UIForm nestingForm = null;
> String formName;
> DummyFormResponseWriter dummyFormResponseWriter;
> if (parent != null)
> {
> //link is nested inside a form
> nestingForm = (UIForm)parent;
> formName = nestingForm.getClientId(facesContext);
> dummyFormResponseWriter = null;
> }
> else
> {
> //not nested in form, we must add a dummy form at the end of the document
> formName = DummyFormUtils.DUMMY_FORM_NAME;
> dummyFormResponseWriter = DummyFormUtils.getDummyFormResponseWriter(facesContext);
> dummyFormResponseWriter.setWriteDummyForm(true);
> }
>
> StringBuffer onClick = new StringBuffer();
>
> String commandOnclick;
> if (component instanceof HtmlCommandLink)
> {
> commandOnclick = ((HtmlCommandLink)component).getOnclick();
> }
> else
> {
> commandOnclick = (String)component.getAttributes().get(HTML.ONCLICK_ATTR);
> }
> if (commandOnclick != null)
> {
> onClick.append(commandOnclick);
> onClick.append(';');
> }
>
> //call the clear_<formName> method
> onClick.append(HtmlRendererUtils.getClearHiddenCommandFormParamsFunctionName(formName)).append("();");
>
> String jsForm = "document.forms['" + formName + "']";
>
> if (MyfacesConfig.getCurrentInstance(facesContext.getExternalContext()).isAutoScroll())
> {
> JavascriptUtils.appendAutoScrollAssignment(onClick, formName);
> }
>
> //add id parameter for decode
> String hiddenFieldName = HtmlRendererUtils.getHiddenCommandLinkFieldName(formName);
> onClick.append(jsForm);
> onClick.append(".elements['").append(hiddenFieldName).append("']");
> onClick.append(".value='").append(clientId).append("';");
> if (nestingForm != null)
> {
> HtmlFormRendererBase.addHiddenCommandParameter(nestingForm, hiddenFieldName);
> }
> else
> {
> dummyFormResponseWriter.addDummyFormParameter(hiddenFieldName);
> }
>
> //add child parameters
> for (Iterator it = component.getChildren().iterator(); it.hasNext(); )
> {
> UIComponent child = (UIComponent)it.next();
> if (child instanceof UIParameter)
> {
> String name = ((UIParameter)child).getName();
> Object value = ((UIParameter)child).getValue();
>
> renderLinkParameter(dummyFormResponseWriter, name, value, onClick, jsForm, nestingForm);
> }
> }
>
> // target
> // todo: can we eliminate the if and rely on the second call only ?
> // see MYFACES-310, specifically the comment by Emond Papegaaij. Will try
> // after testing framework is in place & tests are written.
> String target = null;
> if (component instanceof HtmlCommandLink)
> {
> target = ((HtmlCommandLink)component).getTarget();
> }
> else
> {
> target = (String)component.getAttributes().get(HTML.TARGET_ATTR);
> }
> if (target != null && target.trim().length() > 0) {
> onClick.append(jsForm);
> onClick.append(".target='");
> onClick.append(target);
> onClick.append("';");
> }
>
> // onSubmit
> onClick.append("if("+jsForm+".onsubmit){"+jsForm+".onsubmit();}");
>
> //submit
> onClick.append(jsForm);
> onClick.append(".submit();return false;"); //return false, so that browser does not handle the click
>
> writer.startElement(HTML.ANCHOR_ELEM, component);
> writer.writeURIAttribute(HTML.HREF_ATTR, "#", null);
> writer.writeAttribute(HTML.ONCLICK_ATTR, onClick.toString(), null);
> }
> On Thu, 2005-07-28 at 09:57 -0700, Curtney Jacobs wrote:
> > Greetings Eric,
> >
> > what you have listed would just recursively call my encodeBegin() method
> > in my renderer class, since this is where I am calling encodeRecursive
> > () method in the first place. However, I did tried it and got errors, as
> > expected. From what I have read and understood the UITabLabel suppose to
> > use its own renderer to display itself.
> >
> > Has anyone else ran into this problem before?
> >
> > Curtney
> >
> > On Thu, 2005-07-28 at 08:22 -0500, Eric Kelm wrote:
> > > I had problems when I tried to use this example as well. Look at the method
> > > signatures. If I remember correctly the functions are not being called
> > > correctly. E.G.
> > >
> > > Method signature:
> > > public void encodeBegin(FacesContext context, UIComponent component)....
> > >
> > > Method Usage in the example:
> > > {...
> > > component.encodeBegin(context);
> > > ...}
> > >
> > > Method should be:
> > > {...
> > > encodeBegin(context, component)
> > > ...}
> > >
> > > I believe this is correct. There are other places in the code like this as
> > > well. I believe this is a correct solution/
> > >
> > > ---------
> > > Eric Kelm
> > > Developer, VSG Worldwide LLC
> > > Longview, TX 75601
> > >
> > > ->-----Original Message-----
> > > ->From: Curtney Jacobs [mailto:c.curtneyjacobs@comcast.net]
> > > ->Sent: Thursday, July 28, 2005 3:46 AM
> > > ->To: martin@marinschek.com
> > > ->Cc: MyFaces Discussion
> > > ->Subject: Re: ClassCastException calling encodeBegin
> > > ->
> > > ->The following is an abbreviated (My stacktrace is really long) version
> > > ->of my stacktrace:
> > > ->
> > > ->java.lang.ClassCastException: com.oim.faces.custom.tabbedpane.UITabLabel
> > > -> at
> > > ->org.apache.myfaces.renderkit.html.HtmlLinkRendererBase.renderJavaScriptAnc
> > > ->horStart(HtmlLinkRendererBase.java:323)
> > > -> at
> > > ->org.apache.myfaces.renderkit.html.HtmlLinkRendererBase.renderCommandLinkSt
> > > ->art(HtmlLinkRendererBase.java:215)
> > > -> at
> > > ->org.apache.myfaces.renderkit.html.HtmlLinkRendererBase.encodeBegin
> > > ->(HtmlLinkRendererBase.java:146)
> > > -> at javax.faces.component.UIComponentBase.encodeBegin
> > > ->(UIComponentBase.java:317)
> > > ->at com.oim.faces.custom.tabbedpane.TabbedPaneRenderer.encodeRecursive
> > > ->(TabbedPaneRenderer.java:406)
> > > ->
> > > ->
> > > ->As you can see from the above, what triggers the exception is when I
> > > ->call encodeRecursive in my renderer, which calls encodeBegin() method on
> > > ->my component (UITabLabel). See previous post for implementation details.
> > > ->
> > > ->_Curtney
> > > ->
> > > ->
> > > ->On Thu, 2005-07-28 at 10:25 +0200, Martin Marinschek wrote:
> > > ->> Find out which classes are involved in the failed casting and then get
> > > ->> back to us.
> > > ->>
> > > ->> regards,
> > > ->>
> > > ->> Martin
> > > ->>
> > > ->> On 7/28/05, Curtney Jacobs <c....@comcast.net> wrote:
> > > ->> 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
> > > ->>
> > > ->>
> > >
> > >
> >
>
RE: ClassCastException calling encodeBegin
Posted by Curtney Jacobs <c....@comcast.net>.
I might have narrowed down the ClassCastException to the following
method in
"org.apache.myfaces.renderkit.html.HtmlLinkRenderBase.renderJavaScriptAnchorStart"
I am not to sure, but the ClassCastException could be comming from
((HtmlCommandLink)component).getOnclick();
I am viewing the source code via browser, unfortunately no line number
comes with it, so I cannot narrow to which cast is causing the error. It
says line 323. Perhaps someone can? I have included the function below
Hmm?
protected void renderJavaScriptAnchorStart(FacesContext facesContext,
ResponseWriter writer,
UIComponent component,
String clientId)
throws IOException
{
//Find form
UIComponent parent = component.getParent();
while (parent != null && !(parent instanceof UIForm))
{
parent = parent.getParent();
}
UIForm nestingForm = null;
String formName;
DummyFormResponseWriter dummyFormResponseWriter;
if (parent != null)
{
//link is nested inside a form
nestingForm = (UIForm)parent;
formName = nestingForm.getClientId(facesContext);
dummyFormResponseWriter = null;
}
else
{
//not nested in form, we must add a dummy form at the end of the document
formName = DummyFormUtils.DUMMY_FORM_NAME;
dummyFormResponseWriter = DummyFormUtils.getDummyFormResponseWriter(facesContext);
dummyFormResponseWriter.setWriteDummyForm(true);
}
StringBuffer onClick = new StringBuffer();
String commandOnclick;
if (component instanceof HtmlCommandLink)
{
commandOnclick = ((HtmlCommandLink)component).getOnclick();
}
else
{
commandOnclick = (String)component.getAttributes().get(HTML.ONCLICK_ATTR);
}
if (commandOnclick != null)
{
onClick.append(commandOnclick);
onClick.append(';');
}
//call the clear_<formName> method
onClick.append(HtmlRendererUtils.getClearHiddenCommandFormParamsFunctionName(formName)).append("();");
String jsForm = "document.forms['" + formName + "']";
if (MyfacesConfig.getCurrentInstance(facesContext.getExternalContext()).isAutoScroll())
{
JavascriptUtils.appendAutoScrollAssignment(onClick, formName);
}
//add id parameter for decode
String hiddenFieldName = HtmlRendererUtils.getHiddenCommandLinkFieldName(formName);
onClick.append(jsForm);
onClick.append(".elements['").append(hiddenFieldName).append("']");
onClick.append(".value='").append(clientId).append("';");
if (nestingForm != null)
{
HtmlFormRendererBase.addHiddenCommandParameter(nestingForm, hiddenFieldName);
}
else
{
dummyFormResponseWriter.addDummyFormParameter(hiddenFieldName);
}
//add child parameters
for (Iterator it = component.getChildren().iterator(); it.hasNext(); )
{
UIComponent child = (UIComponent)it.next();
if (child instanceof UIParameter)
{
String name = ((UIParameter)child).getName();
Object value = ((UIParameter)child).getValue();
renderLinkParameter(dummyFormResponseWriter, name, value, onClick, jsForm, nestingForm);
}
}
// target
// todo: can we eliminate the if and rely on the second call only ?
// see MYFACES-310, specifically the comment by Emond Papegaaij. Will try
// after testing framework is in place & tests are written.
String target = null;
if (component instanceof HtmlCommandLink)
{
target = ((HtmlCommandLink)component).getTarget();
}
else
{
target = (String)component.getAttributes().get(HTML.TARGET_ATTR);
}
if (target != null && target.trim().length() > 0) {
onClick.append(jsForm);
onClick.append(".target='");
onClick.append(target);
onClick.append("';");
}
// onSubmit
onClick.append("if("+jsForm+".onsubmit){"+jsForm+".onsubmit();}");
//submit
onClick.append(jsForm);
onClick.append(".submit();return false;"); //return false, so that browser does not handle the click
writer.startElement(HTML.ANCHOR_ELEM, component);
writer.writeURIAttribute(HTML.HREF_ATTR, "#", null);
writer.writeAttribute(HTML.ONCLICK_ATTR, onClick.toString(), null);
}
On Thu, 2005-07-28 at 09:57 -0700, Curtney Jacobs wrote:
> Greetings Eric,
>
> what you have listed would just recursively call my encodeBegin() method
> in my renderer class, since this is where I am calling encodeRecursive
> () method in the first place. However, I did tried it and got errors, as
> expected. From what I have read and understood the UITabLabel suppose to
> use its own renderer to display itself.
>
> Has anyone else ran into this problem before?
>
> Curtney
>
> On Thu, 2005-07-28 at 08:22 -0500, Eric Kelm wrote:
> > I had problems when I tried to use this example as well. Look at the method
> > signatures. If I remember correctly the functions are not being called
> > correctly. E.G.
> >
> > Method signature:
> > public void encodeBegin(FacesContext context, UIComponent component)....
> >
> > Method Usage in the example:
> > {...
> > component.encodeBegin(context);
> > ...}
> >
> > Method should be:
> > {...
> > encodeBegin(context, component)
> > ...}
> >
> > I believe this is correct. There are other places in the code like this as
> > well. I believe this is a correct solution/
> >
> > ---------
> > Eric Kelm
> > Developer, VSG Worldwide LLC
> > Longview, TX 75601
> >
> > ->-----Original Message-----
> > ->From: Curtney Jacobs [mailto:c.curtneyjacobs@comcast.net]
> > ->Sent: Thursday, July 28, 2005 3:46 AM
> > ->To: martin@marinschek.com
> > ->Cc: MyFaces Discussion
> > ->Subject: Re: ClassCastException calling encodeBegin
> > ->
> > ->The following is an abbreviated (My stacktrace is really long) version
> > ->of my stacktrace:
> > ->
> > ->java.lang.ClassCastException: com.oim.faces.custom.tabbedpane.UITabLabel
> > -> at
> > ->org.apache.myfaces.renderkit.html.HtmlLinkRendererBase.renderJavaScriptAnc
> > ->horStart(HtmlLinkRendererBase.java:323)
> > -> at
> > ->org.apache.myfaces.renderkit.html.HtmlLinkRendererBase.renderCommandLinkSt
> > ->art(HtmlLinkRendererBase.java:215)
> > -> at
> > ->org.apache.myfaces.renderkit.html.HtmlLinkRendererBase.encodeBegin
> > ->(HtmlLinkRendererBase.java:146)
> > -> at javax.faces.component.UIComponentBase.encodeBegin
> > ->(UIComponentBase.java:317)
> > ->at com.oim.faces.custom.tabbedpane.TabbedPaneRenderer.encodeRecursive
> > ->(TabbedPaneRenderer.java:406)
> > ->
> > ->
> > ->As you can see from the above, what triggers the exception is when I
> > ->call encodeRecursive in my renderer, which calls encodeBegin() method on
> > ->my component (UITabLabel). See previous post for implementation details.
> > ->
> > ->_Curtney
> > ->
> > ->
> > ->On Thu, 2005-07-28 at 10:25 +0200, Martin Marinschek wrote:
> > ->> Find out which classes are involved in the failed casting and then get
> > ->> back to us.
> > ->>
> > ->> regards,
> > ->>
> > ->> Martin
> > ->>
> > ->> On 7/28/05, Curtney Jacobs <c....@comcast.net> wrote:
> > ->> 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
> > ->>
> > ->>
> >
> >
>
RE: ClassCastException calling encodeBegin
Posted by Curtney Jacobs <c....@comcast.net>.
Greetings Eric,
what you have listed would just recursively call my encodeBegin() method
in my renderer class, since this is where I am calling encodeRecursive
() method in the first place. However, I did tried it and got errors, as
expected. From what I have read and understood the UITabLabel suppose to
use its own renderer to display itself.
Has anyone else ran into this problem before?
Curtney
On Thu, 2005-07-28 at 08:22 -0500, Eric Kelm wrote:
> I had problems when I tried to use this example as well. Look at the method
> signatures. If I remember correctly the functions are not being called
> correctly. E.G.
>
> Method signature:
> public void encodeBegin(FacesContext context, UIComponent component)....
>
> Method Usage in the example:
> {...
> component.encodeBegin(context);
> ...}
>
> Method should be:
> {...
> encodeBegin(context, component)
> ...}
>
> I believe this is correct. There are other places in the code like this as
> well. I believe this is a correct solution/
>
> ---------
> Eric Kelm
> Developer, VSG Worldwide LLC
> Longview, TX 75601
>
> ->-----Original Message-----
> ->From: Curtney Jacobs [mailto:c.curtneyjacobs@comcast.net]
> ->Sent: Thursday, July 28, 2005 3:46 AM
> ->To: martin@marinschek.com
> ->Cc: MyFaces Discussion
> ->Subject: Re: ClassCastException calling encodeBegin
> ->
> ->The following is an abbreviated (My stacktrace is really long) version
> ->of my stacktrace:
> ->
> ->java.lang.ClassCastException: com.oim.faces.custom.tabbedpane.UITabLabel
> -> at
> ->org.apache.myfaces.renderkit.html.HtmlLinkRendererBase.renderJavaScriptAnc
> ->horStart(HtmlLinkRendererBase.java:323)
> -> at
> ->org.apache.myfaces.renderkit.html.HtmlLinkRendererBase.renderCommandLinkSt
> ->art(HtmlLinkRendererBase.java:215)
> -> at
> ->org.apache.myfaces.renderkit.html.HtmlLinkRendererBase.encodeBegin
> ->(HtmlLinkRendererBase.java:146)
> -> at javax.faces.component.UIComponentBase.encodeBegin
> ->(UIComponentBase.java:317)
> ->at com.oim.faces.custom.tabbedpane.TabbedPaneRenderer.encodeRecursive
> ->(TabbedPaneRenderer.java:406)
> ->
> ->
> ->As you can see from the above, what triggers the exception is when I
> ->call encodeRecursive in my renderer, which calls encodeBegin() method on
> ->my component (UITabLabel). See previous post for implementation details.
> ->
> ->_Curtney
> ->
> ->
> ->On Thu, 2005-07-28 at 10:25 +0200, Martin Marinschek wrote:
> ->> Find out which classes are involved in the failed casting and then get
> ->> back to us.
> ->>
> ->> regards,
> ->>
> ->> Martin
> ->>
> ->> On 7/28/05, Curtney Jacobs <c....@comcast.net> wrote:
> ->> 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
> ->>
> ->>
>
>
RE: ClassCastException calling encodeBegin
Posted by Eric Kelm <er...@vsgadmin.com>.
I had problems when I tried to use this example as well. Look at the method
signatures. If I remember correctly the functions are not being called
correctly. E.G.
Method signature:
public void encodeBegin(FacesContext context, UIComponent component)....
Method Usage in the example:
{...
component.encodeBegin(context);
...}
Method should be:
{...
encodeBegin(context, component)
...}
I believe this is correct. There are other places in the code like this as
well. I believe this is a correct solution/
---------
Eric Kelm
Developer, VSG Worldwide LLC
Longview, TX 75601
->-----Original Message-----
->From: Curtney Jacobs [mailto:c.curtneyjacobs@comcast.net]
->Sent: Thursday, July 28, 2005 3:46 AM
->To: martin@marinschek.com
->Cc: MyFaces Discussion
->Subject: Re: ClassCastException calling encodeBegin
->
->The following is an abbreviated (My stacktrace is really long) version
->of my stacktrace:
->
->java.lang.ClassCastException: com.oim.faces.custom.tabbedpane.UITabLabel
-> at
->org.apache.myfaces.renderkit.html.HtmlLinkRendererBase.renderJavaScriptAnc
->horStart(HtmlLinkRendererBase.java:323)
-> at
->org.apache.myfaces.renderkit.html.HtmlLinkRendererBase.renderCommandLinkSt
->art(HtmlLinkRendererBase.java:215)
-> at
->org.apache.myfaces.renderkit.html.HtmlLinkRendererBase.encodeBegin
->(HtmlLinkRendererBase.java:146)
-> at javax.faces.component.UIComponentBase.encodeBegin
->(UIComponentBase.java:317)
->at com.oim.faces.custom.tabbedpane.TabbedPaneRenderer.encodeRecursive
->(TabbedPaneRenderer.java:406)
->
->
->As you can see from the above, what triggers the exception is when I
->call encodeRecursive in my renderer, which calls encodeBegin() method on
->my component (UITabLabel). See previous post for implementation details.
->
->_Curtney
->
->
->On Thu, 2005-07-28 at 10:25 +0200, Martin Marinschek wrote:
->> Find out which classes are involved in the failed casting and then get
->> back to us.
->>
->> regards,
->>
->> Martin
->>
->> On 7/28/05, Curtney Jacobs <c....@comcast.net> wrote:
->> 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
->>
->>
Re: ClassCastException calling encodeBegin
Posted by Curtney Jacobs <c....@comcast.net>.
The following is an abbreviated (My stacktrace is really long) version
of my stacktrace:
java.lang.ClassCastException: com.oim.faces.custom.tabbedpane.UITabLabel
at
org.apache.myfaces.renderkit.html.HtmlLinkRendererBase.renderJavaScriptAnchorStart(HtmlLinkRendererBase.java:323)
at
org.apache.myfaces.renderkit.html.HtmlLinkRendererBase.renderCommandLinkStart(HtmlLinkRendererBase.java:215)
at org.apache.myfaces.renderkit.html.HtmlLinkRendererBase.encodeBegin
(HtmlLinkRendererBase.java:146)
at javax.faces.component.UIComponentBase.encodeBegin
(UIComponentBase.java:317)
at com.oim.faces.custom.tabbedpane.TabbedPaneRenderer.encodeRecursive
(TabbedPaneRenderer.java:406)
As you can see from the above, what triggers the exception is when I
call encodeRecursive in my renderer, which calls encodeBegin() method on
my component (UITabLabel). See previous post for implementation details.
_Curtney
On Thu, 2005-07-28 at 10:25 +0200, Martin Marinschek wrote:
> Find out which classes are involved in the failed casting and then get
> back to us.
>
> regards,
>
> Martin
>
> On 7/28/05, Curtney Jacobs <c....@comcast.net> wrote:
> 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
>
>
Re: ClassCastException calling encodeBegin
Posted by Martin Marinschek <ma...@gmail.com>.
Find out which classes are involved in the failed casting and then get back
to us.
regards,
Martin
On 7/28/05, Curtney Jacobs <c....@comcast.net> wrote:
>
> 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
>
>