voyent
Using view scoped beans  XML
Forum Index -> Development Build Feedback
Author Message
jim.webguru

Joined: 26/Aug/2009 00:00:00
Messages: 15
Offline


How do you effectively use view scoped beans with Icefaces 2.0 beta 2? I have tried using a bean that is view scoped and the controls on the page will lose their values. It's ok if I make the beans session scoped. The regular faces controls retain the values from view scoped beans. I noticed that it's only the icefaces controls. I am using glassfish 3.1 that is from the netbeans 6.9 bundle.

This is my bean (I tried using the @ViewRetained annotation that is shown on the icefaces 2.0 wiki):

Code:
 
 @Named(value="contactUs")
 @ViewScoped
 @ViewRetained
 public class ContactUs
 {
 ....
 }
 
 


johi

Joined: 02/Jun/2007 00:00:00
Messages: 12
Offline


Hi,

Use
Code:
@ManagedBean(name="contactUs")
 @ViewScoped
 public class ContactUs
  {
  ....
  }


I found that blogpost usefull:
http://www.verborgh.be/articles/2010/01/06/porting-the-viewscoped-jsf-annotation-to-cdi/

hth
jim.webguru

Joined: 26/Aug/2009 00:00:00
Messages: 15
Offline


I have been trying to follow the example in the blog post but there must be something different with the newer version of glassfish. I am getting an error with weld. I have created my classes and interface classes just like the blog states. I have then added the extension class to the services/javax.enterprise.inject.spi.extension file. The ViewContext file returns true for is active. I wonder if my extension class is not being picked up some how.

Code:
 
 An Error Occurred:
 WELD-001303 No active contexts for scope type iberis.faces.ViewScoped
 
 org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type iberis.faces.ViewScoped
 	at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:679)
 	at org.jboss.weld.bean.proxy.ClientProxyMethodHandler.getProxiedInstance(ClientProxyMethodHandler.java:138)
 	at org.jboss.weld.bean.proxy.ClientProxyMethodHandler.invoke(ClientProxyMethodHandler.java:100)
 	at org.jboss.weld.util.CleanableMethodHandler.invoke(CleanableMethodHandler.java:43)
 	at com.bizznetworx.iberis.sites.BreadCrumbs_$$_javassist_53.getCategoryId(BreadCrumbs_$$_javassist_53.java)
 	at com.bizznetworx.iberis.sites.ProductUtil.getSubCategoryList(ProductUtil.java:52)
 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 	at java.lang.reflect.Method.invoke(Method.java:597)
 	at javax.el.BeanELResolver.getValue(BeanELResolver.java:302)
 	at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)
 	at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
 	at com.sun.el.parser.AstValue.getValue(AstValue.java:116)
 	at com.sun.el.parser.AstValue.getValue(AstValue.java:163)
 	at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)
 	at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:71)
 	at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:102)
 	at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:190)
 	at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:178)
 	at javax.faces.component.UIData.getValue(UIData.java:554)
 	at javax.faces.component.UIData.getDataModel(UIData.java:1248)
 	at javax.faces.component.UIData.setRowIndex(UIData.java:447)
 	at com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRenderer.java:81)
 	at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:823)
 	at javax.faces.component.UIData.encodeBegin(UIData.java:937)
 	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1611)
 	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
 	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
 	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
 	at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:380)
 	at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126)
 	at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:273)
 	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)
 	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
 	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
 	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
 	at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
 	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
 	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
 	at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
 	at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
 	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
 	at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
 	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
 	at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
 	at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
 	at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
 	at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
 	at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
 	at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
 	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
 	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
 	at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
 	at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
 	at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
 	at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
 	at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
 	at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
 	at java.lang.Thread.run(Thread.java:619)
 
 
 
johi

Joined: 02/Jun/2007 00:00:00
Messages: 12
Offline


The blog misses a small detail:
All that we now need to do is provide a file with the name "javax.enterprise.inject.spi.Extension" in the "META-INF/services" folder of you application in order to allow the java ServiceLoader that weld uses to load the extension. 


You have to write the fully-qualified binary name of the ViewContextExtension into that file.
jim.webguru

Joined: 26/Aug/2009 00:00:00
Messages: 15
Offline


I have the classes in a separate jar so that I can use them in multiple web apps. I already have the fully qualified name of the class in the extension file. Do I need to include the jar name as well? Can you give me an example? I think it's something like jarfilename.jar$fullclassname. Or should i forget it and just put the source files with my web application?
johi

Joined: 02/Jun/2007 00:00:00
Messages: 12
Offline


Hi

The classes can stay in the separate jar, make sure your classloader can find the extension file (i had that wrong in my first try ;-) ).
For details check the ServiceLoader javadoc

Here is my Netbeans Project:

 Filename ScopeTest.zip [Disk] Download
 Description
 Filesize 26 Kbytes
 Downloaded:  510 time(s)

jim.webguru

Joined: 26/Aug/2009 00:00:00
Messages: 15
Offline


Thank You very much. Your sample cleared the air. Netbeans compiles the configuration files such as the manifest under META-INF folder in the war. I was under the assumption that i had to add the services folder under the conf folder and then add a line in the build.xml so that the build copies the extension file and the services folder to the META-INF folder in the war. None of the blogs mentioned (at least i didn't catch it) that i needed to create a META-INF.services package that contained the extension file. uggghhh. Thank you again for your help and this now works in my application.
sushi_78

Joined: 05/Aug/2008 00:00:00
Messages: 5
Offline


Hi,

I have the same problem and I get the same Exception.

I am working with eclipse and maven. I added the fully qualified name inside the javax.enterprise.inject.spi.Extension file and I tried both possibilities: adding META-INF/services/javax.enterprise.inject.spi.Extension inside WEB-INF/classes and directly into META-INF within the war file.
Both do not work :-(

Does anyone has some ideas?

jim.webguru

Joined: 26/Aug/2009 00:00:00
Messages: 15
Offline


I am not sure if you are using the latest version of Glassfish (That is what I was using and the extension stopped working after I upgraded Icefaces and Glassfish)

I decided to drop the extension.

I added MyFaces CODI to my project. That library contains @ViewAccessScoped and other scopes. It works like a dream. No crazy configurations or extensions to mess with in your project.

Simply add the CODI bundle jar file to your project as a library. (it is important that use the bundle version and not the regular separate jar files from the download. The bundle version is one jar file that contains everything) Then add the scope to your beans.

Another benefit to the library is that injection works flawlessly. I was having injection problems with other beans like @ApplicationScoped beans. The issue went away when I use CODI. I believe the library is hard core in focusing on the CDI functionality.

It should work for you.
johi

Joined: 02/Jun/2007 00:00:00
Messages: 12
Offline


hi

you can give that jar a try.
It works for me in glassfish.

regards
 Filename CustomViewScope.jar [Disk] Download
 Description
 Filesize 5 Kbytes
 Downloaded:  321 time(s)

 
Forum Index -> Development Build Feedback
Go to:   
Powered by JForum 2.1.7ice © JForum Team