voyent
Dynamically created MenuBar throws InvalidComponentTypeException  XML
Forum Index -> JBoss Seam Integration
Author Message
Newlukai

Joined: 29/Nov/2006 00:00:00
Messages: 125
Offline


Hi,

it's very strange. I don't know why this happens. But first some code I use.

Here I use the menubar:
Code:
<ui:define name="sidebar">
 	<ice:form>
 		<ice:menuBar orientation="vertical">
 			<ice:menuItems value="#{sideNavigationMenu.panelNavigationItems2}" />
 		</ice:menuBar>
 	 </ice:form>
 </ui:define>


And that's the bean method:
Code:
public List<MenuItem> getPanelNavigationItems2() {
 		List<MenuItem> menu = new ArrayList<MenuItem>();
 		
 		MenuItem create = createMenuItem("#{ares_messages.create}", "main");
 		MenuItem createTestaction = createMenuItem("#{ares_messages.create_testaction}", "createTestaction");
 		MenuItem createRequest = createMenuItem("#{ares_messages.create_request}", "createRequest");
 		create.getChildren().add(createTestaction);
 		create.getChildren().add(createRequest);
 		
 		MenuItem edit = createMenuItem("#{ares_messages.edit}", "main");
 		MenuItem editTester = createMenuItem("#{ares_messages.edit_tester}", "showListForTester");
 		MenuItem editDeveloper = createMenuItem("#{ares_messages.edit_developer}", "showListForDeveloper");
 		MenuItem editValidator = createMenuItem("#{ares_messages.edit_validator}", "showListForValidator");
 		edit.getChildren().add(editTester);
 		edit.getChildren().add(editDeveloper);
 		edit.getChildren().add(editValidator);
 		
 		MenuItem info = createMenuItem("#{ares_messages.info}", "main");
 		MenuItem infoRPA24 = createMenuItem("#{ares_messages.info_RPA24}", "showListRPA24");
 		info.getChildren().add(infoRPA24);
 
 		MenuItem search = createMenuItem("#{ares_messages.search}", "search");
         
         if(user.getIsAdmin().equals(new Integer(-1))) {
         	MenuItem infoStats = createMenuItem("#{ares_messages.info_stats}", "stats");
         	info.getChildren().add(infoStats);
         }
         
         menu.add(create);
         menu.add(edit);
         menu.add(info);
         menu.add(search);
         
         if(user.getIsAdmin().equals(new Integer(-1))) {
         	MenuItem projLeader = createMenuItem("#{ares_messages.projleader}", "main");
         	MenuItem projLeaderRequests = createMenuItem("#{ares_messages.projleader_request}", "showRequestListForProjLeader");
         	projLeader.getChildren().add(projLeaderRequests);
         	menu.add(projLeader);
         }
         
 		return menu;
 	}
 
 private MenuItem createMenuItem(String value, String link) {
 		MenuItem create = new MenuItem();
 		create.setValue(value);
 		create.setLink(link);
 		return create;
 	}


And here is the stacktrace:
Code:
15:50:34,968 ERROR [D2DFaceletViewHandler] Problem in renderResponse: null
 com.icesoft.faces.component.InvalidComponentTypeException
 	at com.icesoft.faces.component.menubar.MenuItemsRenderer.setParentsRecursive(MenuItemsRenderer.java:77)
 	at com.icesoft.faces.component.menubar.MenuItemsRenderer.encodeChildren(MenuItemsRenderer.java:59)
 	at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:524)
 	at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:341)
 	at com.icesoft.faces.component.menubar.MenuBarRenderer.encodeChildren(MenuBarRenderer.java:94)
 	at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:524)
 	at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:531)
 	at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:535)
 	at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:535)
 	at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:535)
 	at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:535)
 	at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:535)
 	at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:535)
 	at com.icesoft.faces.application.D2DViewHandler.renderResponse(D2DViewHandler.java:535)
 	at com.icesoft.faces.facelets.D2DFaceletViewHandler.renderResponse(D2DFaceletViewHandler.java:273)
 	at com.icesoft.faces.application.D2DViewHandler.renderView(D2DViewHandler.java:149)
 	at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:384)
 	at com.icesoft.faces.webapp.xmlhttp.BlockingServlet.renderCycle(BlockingServlet.java:436)
 	at com.icesoft.faces.webapp.xmlhttp.BlockingServlet.receiveUpdates(BlockingServlet.java:423)
 	at com.icesoft.faces.webapp.xmlhttp.BlockingServlet.service(BlockingServlet.java:277)
 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
 	at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
 	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
 	at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
 	at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
 	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
 	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
 	at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
 	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
 	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
 	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
 	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
 	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
 	at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
 	at java.lang.Thread.run(Thread.java:595)


The MenuItemsRenderer throws this exception because the casting of the MenuItems fails.

Does somebody know what's my mistake?

Greets
Newlukai
philip.breau


Joined: 08/May/2006 00:00:00
Messages: 2989
Offline


Hi Newkukai,

That's puzzling. I'm not sure why you're getting the InvalidComponentTypeException. A few things you'll need to do though:

- set the id of every MenuItem you create
- use ValueBindings for the values, and set the valueBinding on the component (by setting the value for el strings you're just passing in the string which won't be evaluated)
- you're setting the link attribute, aren't these actually action strings? If so, you'll want to use setAction(string)

Thanks,
Philip

.
Newlukai

Joined: 29/Nov/2006 00:00:00
Messages: 125
Offline


Setting the ID and changing the value to a ValueBinding didn't work.

I can't use setAction(String) because it isn't defined. I've to use setAction(MethodBinding) instead but this doesn't work neither since the action isn't an EL expression.

But I don't think that changing those method calls would help because the problem is that my MenuItems aren't "instanceof MenuItemBase". It's very strange. There is a cast to UIComponent before the instanceof test, but that shouldn't be a problem.
philip.breau


Joined: 08/May/2006 00:00:00
Messages: 2989
Offline


Hi,

Are you using Seam? We've been seeing a lot of strange classloading issues with Seam, especially with dynamically created components. If you are, try setting the following JBoss configuration.

jboss-4.0.5.GA\server\default\deploy\jbossweb-tomcat55.sar\META-INF\jboss-service.xml


<attribute name="UseJBossWebLoader">true</attribute>

Thanks,
Philip

.
Newlukai

Joined: 29/Nov/2006 00:00:00
Messages: 125
Offline


Erm. Yeah, I use seam. I'll try.
Newlukai

Joined: 29/Nov/2006 00:00:00
Messages: 125
Offline


Hi,

I think i finished migrating from Tomahawk. And I set the configuration as you said. The exception is gone and the menu is shown.
But, it's very ugly. I'm sure I do anything wrong, but I don't know what. I'll attach an image so you can see what I try to explain now.

The menu is dynamically created with the code in my first post. With .setValue(String) I try to specify the text that is shown on the buttons. Those texts are i18nized, i. e. defined in a message bundle. With .setLink(String) I try to specify the action string that is broadcasted when the user clicks a menu item. Usually JSF looks for this string in the faces-config.xml for a matching navigation rule and redirects the user to this page. At the moment the "link" attribute is attached on the applications "root directory", that means e. g. that a menuItem with "link" property "search" points on http://localhost:8080/ares/search.

Do you have any suggestions?

Greets
Newlukai
[Thumb - menubar.jpg]
 Filename menubar.jpg [Disk] Download
 Description The rendered menuBar.
 Filesize 15 Kbytes
 Downloaded:  493 time(s)

philip.breau


Joined: 08/May/2006 00:00:00
Messages: 2989
Offline


Hi Newlukai,

Glad to hear you got those things sorted out. I think you're just missing the ICEfaces CSS declaration. Add the following to your header:

<link href="./xmlhttp/css/xp/xp.css" rel="stylesheet" type="text/css" />


Thanks,
Philip

.
Newlukai

Joined: 29/Nov/2006 00:00:00
Messages: 125
Offline


Yeah thank you. Now it looks better.
But still the menu items are useless since they don't show the right text and redirect to pages that don't exist.
philip.breau


Joined: 08/May/2006 00:00:00
Messages: 2989
Offline


Hi,

In your createMenuItem() method why don't you try this:

Code:
private MenuItem createMenuItem(String valueVBString, String link) {
     String value = null;
     ValueBinding vb = FacesContext.getCurrentInstance().getApplication().createValueBinding(vbString);
     if( vb != null ){
         value = (String)vb.getValue(FacesContext.getCurrentInstance());
     }
     MenuItem create = new MenuItem();
     create.setValue(value);
     ...
 

Thanks,
Phillip

.
Newlukai

Joined: 29/Nov/2006 00:00:00
Messages: 125
Offline


I've to thank you again ;)

And I think that all good things come by threes. So perhaps you have an idea how to set the action attribute of a menu item. I know the method MenuItem.setAction(MethodBinding) sets the action property. The problem is that I want to use a normal string that matches a navigation rule and not an EL expression. So I can't use a MethodBinding as JSF tells me that the "search" in
Code:
MethodBinding mb = FacesContext.getCurrentInstance().getApplication().createMethodBinding("search", null);
 menuItem.setAction(mb);

is not an EL expression.

I found a "workaround" for this. I created an inner class like this:

Code:
private MenuItem createMenuItem(String id, String value, String link) {
 		MenuItem menuItem = new MenuItem();
 		menuItem.setId(id);
 		menuItem.setValue(FacesUtil.getMessageString(value));
 		menuItem.setAction(new ActionMethodBinding(link));
 		return menuItem;
 	}
 	
 	private static class ActionMethodBinding extends MethodBinding implements Serializable {
 		private String outcome;
 		
 		public ActionMethodBinding(String outcome) {
 			this.outcome = outcome;
 		}
 		
 		public Object invoke(FacesContext context, Object params[]) {
 			return outcome;
 		}
 		
 		public String getExpressionString() {
 			return outcome;
 		}
 		
 		public Class getType(FacesContext context) {
 			return String.class;
 		}
 	}

I got this from a book about JSF (core JSF from Sun) so I think this should work. The application starts and the menuBar is shown, but when I click on a menu item the ICEfaces dialog pops up and tells me that the user session is expired.
I tried to find the error and set breakpoints for all the methods in ActionMethodBinding, but only the constructor is invoked when the menuBar is generated. When I click a menu item in the application there isn't any method invoked.

Thanks in advance
Newlukai
philip.breau


Joined: 08/May/2006 00:00:00
Messages: 2989
Offline


Hi Newlukai,

As far as I know you have to use the Application object to create MethodBindings. And as "search" is an action string, rather than an Action method, I think you're going to have to create an Action Bean to hold your Action methods, make sure that that bean is referenced on the page and your faces-config, so that it's instantiated, and then have a 'public String search(){ return "search"; }" method in that bean to route back to your navigation action.

Also when you get those puzzling 'connection lost' screens check the server logs for messages about JSF not finding a method or being able to create a bean etc. That's often the case. If you're not already doing this, it's also a good idea to use these Sun RI settings that can catch more errors:

Code:
<context-param>
     <param-name>com.sun.faces.validateXml</param-name>
     <param-value>true</param-value>
 </context-param>
 
 <context-param>
     <param-name>com.sun.faces.verifyObjects</param-name>
     <param-value>true</param-value>
 </context-param> 
 

Thanks,
Philip

.
Newlukai

Joined: 29/Nov/2006 00:00:00
Messages: 125
Offline


Hi Philip,

that's the log after clicking a menu item:

Code:
2006-12-15 14:24:35,765 DEBUG [com.icesoft.faces.webapp.xmlhttp.BlockingServlet] request.pathInfo /receive-send-updates
 2006-12-15 14:24:35,765 DEBUG [com.icesoft.faces.webapp.xmlhttp.BlockingServlet] request.focus_hidden_field = 
 2006-12-15 14:24:35,765 DEBUG [com.icesoft.faces.webapp.xmlhttp.BlockingServlet] request._id17:_ideventModel = type:click;keyCode:undefined;ctrlKey:false;shiftKey:false;altKey:false;componentId:_id17:_id18:_id19:search:link;
 2006-12-15 14:24:35,765 DEBUG [com.icesoft.faces.webapp.xmlhttp.BlockingServlet] request.viewNumber = 1
 2006-12-15 14:24:35,765 DEBUG [com.icesoft.faces.webapp.xmlhttp.BlockingServlet] request._id17:_idcl = _id17:_id18:_id19:search:link
 2006-12-15 14:24:35,765 DEBUG [com.icesoft.faces.webapp.xmlhttp.BlockingServlet] request.icefacesID = MGwtdq_xumJ8iE0JWnyHxg
 2006-12-15 14:24:35,765 DEBUG [com.icesoft.faces.webapp.xmlhttp.BlockingServlet] request.rand = 0.5561682994896113
 
 
 2006-12-15 14:24:35,765 DEBUG [com.icesoft.faces.webapp.xmlhttp.BlockingServlet] request._id17 = _id17
 2006-12-15 14:24:35,765 DEBUG [com.icesoft.faces.webapp.xmlhttp.BlockingServlet] request.icefacesCssUpdates = 
 2006-12-15 14:24:35,765 DEBUG [com.icesoft.faces.webapp.xmlhttp.BlockingServlet] request.focus = _id17:_id18:_id19:search:link
 2006-12-15 14:24:35,765 DEBUG [com.icesoft.faces.context.BridgeExternalContext] Removing named element: org.jboss.seam.core.manager from Reused ExternalContext
 2006-12-15 14:24:35,765 DEBUG [org.jboss.seam.contexts.Lifecycle] >>> Begin web request
 2006-12-15 14:24:35,765 DEBUG [org.jboss.seam.core.Events] Processing event:org.jboss.seam.beforePhase
 2006-12-15 14:24:35,765 DEBUG [org.jboss.seam.core.Events] Processing event:org.jboss.seam.afterPhase
 2006-12-15 14:24:35,765 DEBUG [org.jboss.seam.Component] instantiating Seam component: org.jboss.seam.core.manager
 2006-12-15 14:24:35,765 DEBUG [org.jboss.seam.Component] initializing new instance of: org.jboss.seam.core.manager
 2006-12-15 14:24:35,765 DEBUG [org.jboss.seam.Component] done initializing: org.jboss.seam.core.manager
 2006-12-15 14:24:35,765 DEBUG [org.jboss.seam.core.Events] Processing event:org.jboss.seam.preSetVariable.org.jboss.seam.core.manager
 2006-12-15 14:24:35,765 DEBUG [org.jboss.seam.core.Events] Processing event:org.jboss.seam.postSetVariable.org.jboss.seam.core.manager
 2006-12-15 14:24:35,765 DEBUG [org.jboss.seam.core.Events] Processing event:org.jboss.seam.postCreate.org.jboss.seam.core.manager
 2006-12-15 14:24:35,765 DEBUG [org.jboss.seam.core.Manager] No stored conversation, or concurrent call to the stored conversation
 2006-12-15 14:24:35,765 DEBUG [org.jboss.seam.jsf.AbstractSeamPhaseListener] After restoring conversation context: ClientConversationContext
 2006-12-15 14:24:35,765 DEBUG [org.jboss.seam.core.Events] Processing event:org.jboss.seam.beforePhase
 2006-12-15 14:24:35,765 DEBUG [org.jboss.seam.jsf.SeamVariableResolver] resolving name: sideNavigationMenu
 2006-12-15 14:24:35,765 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: sideNavigationMenu
 2006-12-15 14:24:35,765 DEBUG [org.jboss.seam.jsf.SeamVariableResolver] resolved name to Seam component
 2006-12-15 14:24:35,781 DEBUG [org.jboss.seam.core.Events] Processing event:org.jboss.seam.preSetVariable.org.jboss.seam.outermostExceptionInterceptor
 2006-12-15 14:24:35,781 DEBUG [org.jboss.seam.core.Events] Processing event:org.jboss.seam.postSetVariable.org.jboss.seam.outermostExceptionInterceptor
 2006-12-15 14:24:35,781 DEBUG [org.jboss.seam.Component] initializing new instance of: sideNavigationMenu
 2006-12-15 14:24:35,781 DEBUG [org.jboss.seam.Component] done initializing: sideNavigationMenu
 2006-12-15 14:24:35,781 DEBUG [org.jboss.seam.Component] trying to inject with hierarchical context search: user
 2006-12-15 14:24:35,781 DEBUG [org.jboss.seam.contexts.Contexts] found in session context: user
 2006-12-15 14:24:35,781 DEBUG [org.jboss.seam.Component] trying to inject with hierarchical context search: facesContext
 2006-12-15 14:24:35,781 DEBUG [org.jboss.seam.jsf.SeamVariableResolver] resolving name: org
 2006-12-15 14:24:35,781 DEBUG [org.jboss.seam.Component] seam component not found: org
 2006-12-15 14:24:35,781 DEBUG [org.jboss.seam.jsf.SeamVariableResolver] could not resolve name
 2006-12-15 14:24:35,781 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss
 2006-12-15 14:24:35,781 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam
 2006-12-15 14:24:35,781 DEBUG [org.jboss.seam.Component] seam component not found: org.jboss.seam.core
 2006-12-15 14:24:35,781 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: org.jboss.seam.core.facesContext
 2006-12-15 14:24:35,781 DEBUG [org.jboss.seam.core.Events] Processing event:org.jboss.seam.preRemoveVariable.org.jboss.seam.outermostExceptionInterceptor
 2006-12-15 14:24:35,781 DEBUG [org.jboss.seam.core.Events] Processing event:org.jboss.seam.postRemoveVariable.org.jboss.seam.outermostExceptionInterceptor
 2006-12-15 14:24:35,781 DEBUG [org.jboss.seam.core.Events] Processing event:org.jboss.seam.afterPhase


It seems to be a problem with Seam. If you think so, I'll post it in the Seam forum, perhaps they know what's going wrong?!?
 
Forum Index -> JBoss Seam Integration
Go to:   
Powered by JForum 2.1.7ice © JForum Team