ClassCastException when using MenuElement with other tags

UI Components for JSF
Post Reply
henriquenn
Posts: 2
Joined: 14 Apr 2014, 16:12

14 Apr 2014, 16:39

Hi, i already saw some posts about this problem here in the forum (http://forum.primefaces.org/viewtopic.p ... enuelement) and found others posts in the google (http://www.wobblycogs.co.uk/index.php/c ... ot-be-cast)

When you use a <p:menuitem/> and/or <p:submenu> merged with other tags you get this error:
java.lang.ClassCastException: com.sun.faces.facelets.compiler.UIInstructions cannot be cast to org.primefaces.model.menu.MenuElement

One of the ideias to solve this problem is add this to your web.xml:

Code: Select all

<context-param>
 <param-name>facelets.SKIP_COMMENTS</param-name>
 <param-value>true</param-value>
</context-param>
But i have a different situation. In my project i merge spring security tags with menu itens, something like this:

Code: Select all

<sec:authorize ifAnyGranted="role">
<p:submenu label="menu1">
   <sec:authorize ifAllGranted="sub_role">
      <p:menuitem value="#{menu2}"/>
   </sec:authorize>
.
.
And these secs' tags trigger the exception.

There is an open issue here explaining the problem: https://code.google.com/p/primefaces/is ... %20Summary
but is has no answer.

So, any ideias of what i can do to solve this problem?
primefaces - v. 4.0
jboss - EAP - 6.1
Mojarra 2.1.19-jbossorg-1

User avatar
snooperman
Posts: 155
Joined: 06 Nov 2012, 18:43

15 Apr 2014, 08:25

Hm.. everytime I used spring security in my application, I used the "rendered" and "disabled" attributes based on my back-end logic. Something like

Code: Select all

<p:submenu label="menu1">
     <p:menuitem value="#{menu2}" rendered="#{securityBean.hasCertainRole}"/>
...
</p:submenu>
I know that it's not what you want, but this is how I did it, and never had problems.
var details = {
. . PF.version: "5.0.x",
. . JSF.version: "2.x",
. . Tomcat.version: "8.x"
}

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

15 Apr 2014, 08:51

I solved it with the rendered attribute to (only not with Spring Security, but with Apache Shiro)

henriquenn
Posts: 2
Joined: 14 Apr 2014, 16:12

15 Apr 2014, 17:58

Yeah guys, its a good ideia, i will try to do that. Ty.

But anyways, is this a primefaces bug??
primefaces - v. 4.0
jboss - EAP - 6.1
Mojarra 2.1.19-jbossorg-1

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

15 Apr 2014, 18:03

No, it is not a 'bug' but just the way how (some) components are implemented. Yes, it could be improved, but since it is not something that occurs very often and workarounds are available, it has no (or at least not a high) priority

User avatar
snooperman
Posts: 155
Joined: 06 Nov 2012, 18:43

16 Apr 2014, 15:26

As far as I know, these components have a DTD (document type definition) behind them. And maybe, in that DTD, submenu can only have menuitem components inside. If you put anything else, it will still see it as a menuitem, therefore a class cast exception.
var details = {
. . PF.version: "5.0.x",
. . JSF.version: "2.x",
. . Tomcat.version: "8.x"
}

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

16 Apr 2014, 16:21

snooperman wrote:As far as I know, these components have a DTD (document type definition) behind them. And maybe, in that DTD, submenu can only have menuitem components inside.
No they don't... not afaik...

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 46 guests