You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Volker Weber <us...@weber-oldenburg.de> on 2005/10/13 16:54:46 UTC

Re: ClassCastException in HtmlCommandLink

Hallo,

you should post a litle more of your code, the exception occures in a
verbatim tag, i can't see a verbatim tag in your posted code.

so just a guess:

could be a problem with ids: you should assign an id to every created
component.

if on one request one of your commandlinks became a automatic assigned
id '_id<xy>' and in a second request this id is assigned to an verbatim
tag then this can occur.

If this is the problem you should found a warning in your log files.

Regards
  Volker

Marius Kreis wrote:
> hello!
> i'm still working on generating a _simple_ list of hyperlinks.
> but when i click on one of them a ClassCastException is thrown.
> 
> at first i thought about an error with the ActionListener, but in fact
> the exception is thrown even if there was no actionlistener assigned at
> all.
> 
> i just can't figure out whats going wrong......
> 
> my jsp looks like this:
> 
> <h:commandLink value="#{test.name}">
> <f:actionListener type="my.domain.Test" />
> </h:commandLink>
> 
> <h:panelGrid id="panel" rowClasses="oddRow, evenRow">
> </h:panelGrid>
> 
> 
> 
> whereas the Test bean looks like this:
> 
> ...
> public void action(ActionEvent e) {
>     System.out.println("Action triggered");
> }
> 
> public void processAction(ActionEvent actionEvent)
>     throws AbortProcessingException {
>         UIComponent   component = actionEvent.getComponent();
>         FacesContext  facesContext = FacesContext.getCurrentInstance();
>         UIViewRoot    root = facesContext.getViewRoot();
>         Application   application = facesContext.getApplication();
> 
>         HtmlPanelGrid panel = (HtmlPanelGrid) root.findComponent("panel");
> 
>         for(int i = 1; i <= 10; i++)
>         {
>             HtmlCommandLink instanceLink = new HtmlCommandLink();
>             instanceLink.setValue("Link #" + i);
> 
>     // doesn matter if this part is included or not...
>             Class[] param = new Class[] { ActionEvent.class };
>             MethodBinding actionListener =
> application.createMethodBinding("#{test.action}", param);
>             instanceLink.setActionListener(actionListener);
>     // ....
> 
>             panel.getChildren().add(instanceLink);
>         }
>     }
> 
>     public String getName() { return "click it"; }
> ...
> 
> 
> and that's what the exception trace looks like:
> 
> java.lang.ClassCastException: javax.faces.component.html.HtmlCommandLink
>     at
> org.apache.myfaces.taglib.core.VerbatimTag.doAfterBody(VerbatimTag.java:76)
>     at
> org.apache.jsp.test_jsp._jspx_meth_f_verbatim_1(org.apache.jsp.test_jsp:256)
> 
> ...
> 
> seems as if a UICommand component is casted to an UIOutput component....
>   but why?!
> 

-- 
Don't answer to From: address!
Mail to this account are droped if not recieved via mailinglist.
To contact me direct create the mail address by
concatenating my forename to my senders domain.

Re: ClassCastException in HtmlCommandLink

Posted by Andrew robinson <an...@gmail.com>.
If you are in a subview, you will always have to put all non-JSF components
inside of verbatim tags unless you use Facelets. That is one major reason
for using verbatim tags.

On 10/13/05, Marius Kreis <ma...@nulldevice.org> wrote:
>
>
> >> [...]
> >>When I remove the verbatim tag (by putting the f:view tags only around
> >>the commandLink and panelGrid) everything seems to work fine.
> >>
> >
> >
> > I don't know the reason to put those html tags inside of verbatim, but i
> > often see this.
> > if i use html i wrote it directly into the jsp.
> >
> > @all: Is there a advantage for puting html into verbatim instead of
> direct?
>
> Well I think can answer this question:
> If you want to print HTML inside of an JSF Tag (eg. PanelGrid) you
> should use the Verbatim tag because the HTML tags are (as far as i know)
> according to the TLD not allowed to be subelements. And a JSF element
> might have a problem rendering a HTML tag...? There's also a warning
> message if you have HTML elements inside of JSF tags.
> Please correct me if I'm wrong.
>

Re: ClassCastException in HtmlCommandLink

Posted by Volker Weber <us...@weber-oldenburg.de>.

Marius Kreis wrote:
> 
>>> [...]
>>> When I remove the verbatim tag (by putting the f:view tags only around
>>> the commandLink and panelGrid) everything seems to work fine.
>>>
>>
>>
>> I don't know the reason to put those html tags inside of verbatim, but i
>> often see this.
>> if i use html i wrote it directly into the jsp.
>>
>> @all: Is there a advantage for puting html into verbatim instead of
>> direct?
> 
> 
> Well I think can answer this question:
> If you want to print HTML inside of an JSF Tag (eg. PanelGrid) you
> should use the Verbatim tag because the HTML tags are (as far as i know)
> according to the TLD not allowed to be subelements. And a JSF element
> might have a problem rendering a HTML tag...? There's also a warning
> message if you have HTML elements inside of JSF tags.
> Please correct me if I'm wrong.
> 

Yes, your right, i just looked into the source and realized that html
etc. needs to be enclosed by verbatim tags. An i'm wondering.
But i don't have realy used jsf tags, in tobago it was possible, until
we decided to don't support such client specific coding (HTML) in pages.


-- 
Don't answer to From: address!
Mail to this account are droped if not recieved via mailinglist.
To contact me direct create the mail address by
concatenating my forename to my senders domain.

Re: ClassCastException in HtmlCommandLink

Posted by Marius Kreis <ma...@nulldevice.org>.
>> [...]
>>When I remove the verbatim tag (by putting the f:view tags only around
>>the commandLink and panelGrid) everything seems to work fine.
>>
> 
> 
> I don't know the reason to put those html tags inside of verbatim, but i
> often see this.
> if i use html i wrote it directly into the jsp.
> 
> @all: Is there a advantage for puting html into verbatim instead of direct?

Well I think can answer this question:
If you want to print HTML inside of an JSF Tag (eg. PanelGrid) you 
should use the Verbatim tag because the HTML tags are (as far as i know) 
according to the TLD not allowed to be subelements. And a JSF element 
might have a problem rendering a HTML tag...? There's also a warning 
message if you have HTML elements inside of JSF tags.
Please correct me if I'm wrong.

Re: ClassCastException in HtmlCommandLink

Posted by Marius Kreis <ma...@nulldevice.org>.
Hi, it's me again...
Well I still get an error about duplicate Ids -- but only when I 
generate them on my own. If I don't do anything about them (and ignore 
the warnings) everything's fine...

Thats the code snippet:

...
HtmlCommandLink instanceLink = new HtmlCommandLink();

////
instanceLink.setId(PROPERTIES_PANEL_ID + "m" + root.createUniqueId());
////

instanceLink.setValue(subnode.getCaption());

PropertyPageController ppcontroller = new PropertyPageController(subnode);
instanceLink.addActionListener(ppcontroller);
panel.getChildren().add(instanceLink);
...

The exception thrown is:
javax.servlet.ServletException: cannot add component with id '_id357' 
and path : {Component-Path : [Class: javax.faces.component.UIOutput,Id: 
_id357]} to its parent component. This might be a problem due to 
duplicate ids.


So, what's going wrong here?

- Marius


Volker Weber wrote:
> Hi,
> 
> 
> 
> Marius Kreis wrote:
> 
>>Hi!
>>You're right, the cause of this exception is a verbatim tag, I was not
>>aware that the verbatim tag is getting an id aswell and this might cause
>>the exception...
>>the complete jsp is:
>>
>><%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
>><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
>><%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles"
>>prefix="tiles" %>
>><f:view>
>><f:verbatim>
>><html>
>><head>
>><link href="styles/main.css" rel="stylesheet" type="text/css">
>></head>
>><body>
>></f:verbatim>
>><h:commandLink value="#{test.name}">
>><f:actionListener type="my.domain.Test" />
>></h:commandLink>
>>
>><h:panelGrid id="panel" rowClasses="oddRow, evenRow">
>></h:panelGrid>
>><f:verbatim>
>></body>
>></html>
>></f:verbatim>
>></f:view>
>>
>>When I remove the verbatim tag (by putting the f:view tags only around
>>the commandLink and panelGrid) everything seems to work fine.
>>
> 
> 
> I don't know the reason to put those html tags inside of verbatim, but i
> often see this.
> if i use html i wrote it directly into the jsp.
> 
> @all: Is there a advantage for puting html into verbatim instead of direct?
> 
> 
> 
>>In fact there are warnings that the id's were generated automatically
>>and that the should be generated using root.createUniqueId() -- but only
>>when I use this function, I end up with duplicate ids -- perhaps I have
>>to concatenate the generated id and the id of my parent element (the
>>panelGrid)?
> 
> 
> I prefer concatenating parendsId + '_' + index as the id.
> 
> 


Re: ClassCastException in HtmlCommandLink

Posted by Volker Weber <us...@weber-oldenburg.de>.
Hi,



Marius Kreis wrote:
> Hi!
> You're right, the cause of this exception is a verbatim tag, I was not
> aware that the verbatim tag is getting an id aswell and this might cause
> the exception...
> the complete jsp is:
> 
> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
> <%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles"
> prefix="tiles" %>
> <f:view>
> <f:verbatim>
> <html>
> <head>
> <link href="styles/main.css" rel="stylesheet" type="text/css">
> </head>
> <body>
> </f:verbatim>
> <h:commandLink value="#{test.name}">
> <f:actionListener type="my.domain.Test" />
> </h:commandLink>
> 
> <h:panelGrid id="panel" rowClasses="oddRow, evenRow">
> </h:panelGrid>
> <f:verbatim>
> </body>
> </html>
> </f:verbatim>
> </f:view>
> 
> When I remove the verbatim tag (by putting the f:view tags only around
> the commandLink and panelGrid) everything seems to work fine.
> 

I don't know the reason to put those html tags inside of verbatim, but i
often see this.
if i use html i wrote it directly into the jsp.

@all: Is there a advantage for puting html into verbatim instead of direct?


> In fact there are warnings that the id's were generated automatically
> and that the should be generated using root.createUniqueId() -- but only
> when I use this function, I end up with duplicate ids -- perhaps I have
> to concatenate the generated id and the id of my parent element (the
> panelGrid)?

I prefer concatenating parendsId + '_' + index as the id.


-- 
Don't answer to From: address!
Mail to this account are droped if not recieved via mailinglist.
To contact me direct create the mail address by
concatenating my forename to my senders domain.

Re: ClassCastException in HtmlCommandLink

Posted by Marius Kreis <ma...@nulldevice.org>.
Hi!
You're right, the cause of this exception is a verbatim tag, I was not 
aware that the verbatim tag is getting an id aswell and this might cause 
the exception...
the complete jsp is:

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" 
prefix="tiles" %>
<f:view>
<f:verbatim>
<html>
<head>
<link href="styles/main.css" rel="stylesheet" type="text/css">
</head>
<body>
</f:verbatim>
<h:commandLink value="#{test.name}">
<f:actionListener type="my.domain.Test" />
</h:commandLink>

<h:panelGrid id="panel" rowClasses="oddRow, evenRow">
</h:panelGrid>
<f:verbatim>
</body>
</html>
</f:verbatim>
</f:view>

When I remove the verbatim tag (by putting the f:view tags only around 
the commandLink and panelGrid) everything seems to work fine.

In fact there are warnings that the id's were generated automatically 
and that the should be generated using root.createUniqueId() -- but only 
when I use this function, I end up with duplicate ids -- perhaps I have 
to concatenate the generated id and the id of my parent element (the 
panelGrid)?



Volker Weber wrote:
> Hallo,
> 
> you should post a litle more of your code, the exception occures in a
> verbatim tag, i can't see a verbatim tag in your posted code.
> 
> so just a guess:
> 
> could be a problem with ids: you should assign an id to every created
> component.
> 
> if on one request one of your commandlinks became a automatic assigned
> id '_id<xy>' and in a second request this id is assigned to an verbatim
> tag then this can occur.
> 
> If this is the problem you should found a warning in your log files.
> 
> Regards
>   Volker
> 
> Marius Kreis wrote:
> 
>>hello!
>>i'm still working on generating a _simple_ list of hyperlinks.
>>but when i click on one of them a ClassCastException is thrown.
>>
>>at first i thought about an error with the ActionListener, but in fact
>>the exception is thrown even if there was no actionlistener assigned at
>>all.
>>
>>i just can't figure out whats going wrong......
>>
>>my jsp looks like this:
>>
>><h:commandLink value="#{test.name}">
>><f:actionListener type="my.domain.Test" />
>></h:commandLink>
>>
>><h:panelGrid id="panel" rowClasses="oddRow, evenRow">
>></h:panelGrid>
>>
>>
>>
>>whereas the Test bean looks like this:
>>
>>...
>>public void action(ActionEvent e) {
>>    System.out.println("Action triggered");
>>}
>>
>>public void processAction(ActionEvent actionEvent)
>>    throws AbortProcessingException {
>>        UIComponent   component = actionEvent.getComponent();
>>        FacesContext  facesContext = FacesContext.getCurrentInstance();
>>        UIViewRoot    root = facesContext.getViewRoot();
>>        Application   application = facesContext.getApplication();
>>
>>        HtmlPanelGrid panel = (HtmlPanelGrid) root.findComponent("panel");
>>
>>        for(int i = 1; i <= 10; i++)
>>        {
>>            HtmlCommandLink instanceLink = new HtmlCommandLink();
>>            instanceLink.setValue("Link #" + i);
>>
>>    // doesn matter if this part is included or not...
>>            Class[] param = new Class[] { ActionEvent.class };
>>            MethodBinding actionListener =
>>application.createMethodBinding("#{test.action}", param);
>>            instanceLink.setActionListener(actionListener);
>>    // ....
>>
>>            panel.getChildren().add(instanceLink);
>>        }
>>    }
>>
>>    public String getName() { return "click it"; }
>>...
>>
>>
>>and that's what the exception trace looks like:
>>
>>java.lang.ClassCastException: javax.faces.component.html.HtmlCommandLink
>>    at
>>org.apache.myfaces.taglib.core.VerbatimTag.doAfterBody(VerbatimTag.java:76)
>>    at
>>org.apache.jsp.test_jsp._jspx_meth_f_verbatim_1(org.apache.jsp.test_jsp:256)
>>
>>...
>>
>>seems as if a UICommand component is casted to an UIOutput component....
>>  but why?!
>>
> 
>