Cannot inject path parameter in @ViewScoped Bean

Splash Forums Rewrite Users Cannot inject path parameter in @ViewScoped Bean

This topic contains 1 reply, has 2 voices, and was last updated by  Christian Kaltepoth 2 years, 9 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #25218

    homer
    Participant

    Hello,

    I’m using JSF 2.2, rewrite 2.0.7 and CDI (Weld). Using the following bean:

    @Named
    @Getter
    @Setter
    @ViewScoped
    @Join(path = "/tags/edit/{id}", to = "/pages/tags/tagedit.xhtml")
    public class TagEditPage {
    
    	@Parameter
    	@Matches("[0-9]+")
    	private Long id;
    }
    

    I get the following exception:

    javax.el.ELException: Error writing 'id' on type net.package.web.pages.TagEditPage$Proxy$_$$_WeldClientProxy
    	at javax.el.BeanELResolver.setValue(BeanELResolver.java:153)
    	at javax.el.CompositeELResolver.setValue(CompositeELResolver.java:83)
    	at org.apache.el.parser.AstValue.setValue(AstValue.java:218)
    	at org.apache.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:253)
    	at org.jboss.weld.el.WeldValueExpression.setValue(WeldValueExpression.java:64)
    	at org.ocpsoft.rewrite.cdi.CdiExpressionLanguageProvider.setValue(CdiExpressionLanguageProvider.java:128)
    	at org.ocpsoft.rewrite.cdi.CdiExpressionLanguageProvider.submitValue(CdiExpressionLanguageProvider.java:79)
    	at org.ocpsoft.rewrite.el.El$ElProperty$2.call(El.java:285)
    	at org.ocpsoft.rewrite.el.El.executeProviderCallable(El.java:151)
    	at org.ocpsoft.rewrite.el.El.access$100(El.java:40)
    	at org.ocpsoft.rewrite.el.El$ElProperty.submit(El.java:280)
    	at org.ocpsoft.rewrite.util.ParameterUtils$BindingOperation.perform(ParameterUtils.java:160)
    	at org.ocpsoft.rewrite.servlet.impl.DefaultHttpRewriteProvider.rewriteHttp(DefaultHttpRewriteProvider.java:174)
    	at org.ocpsoft.rewrite.servlet.http.HttpRewriteProvider.rewrite(HttpRewriteProvider.java:43)
    	at org.ocpsoft.rewrite.servlet.RewriteFilter.rewrite(RewriteFilter.java:241)
    	at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:187)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    	at java.lang.Thread.run(Thread.java:724)
    Caused by: org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.faces.view.ViewScoped
    	at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:689)
    	at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:74)
    	at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79)
    	at net.package.web.pages.TagEditPage$Proxy$_$$_WeldClientProxy.setId(Unknown Source)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:606)
    	at javax.el.BeanELResolver.setValue(BeanELResolver.java:142)
    	... 31 more
    

    Is it really not possible to inject parameters into ViewScoped beans as it was in Prettyfaces?

    #25219

    You have to defer the binding of the parameter to get it to work correctly. That’s because by default Rewrite processes bindings very early during request processing, even before the JSF lifecycle starts. But if you defer the binding, it will be submitted after the JSF lifecycle started. Just add the @Deferred annotation to your parameter like this:

    @Parameter
    @Deferred
    @Matches("[0-9]+")
    private Long id;
    

    I’m currently thinking about adding some kind of auto detection mechanism that automatically adds the deferral if the injection happens on a JSF bean (or a CDI bean with a JSF view scope) But that is still WIP. So for now you have to add the annotation manually.

    BTW: You have to add rewrite-integration-faces for this to work correctly.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

Comments are closed.