Deprecated RequestContext not working in Primefaces 6.2 - SNAPSHOT

UI Components for JSF
stefan.sibitz
Posts: 38
Joined: 11 Nov 2016, 09:44

09 Nov 2017, 09:32

When i am using the RequestContext in Primefaces 6.2-SNAPSHOT is say's that this is now deprecated:

This is working without any problems:

Code: Select all

RequestContext context = RequestContext.getCurrentInstance();
context.update("masterDetail");
but now when i am using it like described in the @deprecated comment i only got an exception by now:

Code: Select all

PrimeFaces.current().ajax().update("masterDetail");
The error i got
Root message: ajax() can only be used in AJAX requests!
Root class: class javax.faces.FacesException
Ajax Exception? false

The stacktrace i got:
javax.faces.FacesException: WELD-000049: Unable to invoke public void com.skf.gui.controllers.calc.CalculationController.Init()@4578ab34
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:84)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
at com.skf.filters.DoCacheFilter.doFilter(DoCacheFilter.java:50)</span>
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at com.skf.filters.CompressResponseFilter.doFilter(CompressResponseFilter.java:70)</span>
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at com.skf.filters.AuthorizationFilter.doFilter(AuthorizationFilter.java:89)</span>
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:53)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:59)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:326)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:812)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.jboss.weld.exceptions.WeldException: WELD-000049: Unable to invoke public void com.skf.gui.controllers.general.GenericController.Init() on com.skf.gui.controllers.calc.CalculationController@4578ab34</span>
at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:99)
at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.postConstruct(DefaultLifecycleCallbackInvoker.java:80)
at org.jboss.weld.injection.producer.BasicInjectionTarget.postConstruct(BasicInjectionTarget.java:122)
at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:162)
at org.jboss.weld.util.bean.IsolatedForwardingBean.create(IsolatedForwardingBean.java:45)
at org.omnifaces.cdi.BeanStorage.createBean(BeanStorage.java:62)
at org.omnifaces.cdi.viewscope.ViewScopeManager.createBean(ViewScopeManager.java:115)
at org.omnifaces.cdi.viewscope.ViewScopeManager$Proxy$_$$_WeldClientProxy.createBean(Unknown Source)
at org.omnifaces.cdi.viewscope.ViewScopeContext.get(ViewScopeContext.java:73)
at org.jboss.weld.context.PassivatingContextWrapper$AbstractPassivatingContextWrapper.get(PassivatingContextWrapper.java:76)
at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:100)
at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:758)
at org.jboss.weld.el.AbstractWeldELResolver.lookup(AbstractWeldELResolver.java:107)
at org.jboss.weld.el.AbstractWeldELResolver.getValue(AbstractWeldELResolver.java:90)
at org.jboss.as.jsf.injection.weld.ForwardingELResolver.getValue(ForwardingELResolver.java:46)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:188)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:116)
at com.sun.el.parser.AstValue.getBase(AstValue.java:150)
at com.sun.el.parser.AstValue.getTarget(AstValue.java:169)
at com.sun.el.parser.AstValue.getType(AstValue.java:85)
at com.sun.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:201)
at org.jboss.weld.el.WeldValueExpression.getType(WeldValueExpression.java:93)
at org.jboss.weld.el.WeldValueExpression.getType(WeldValueExpression.java:93)
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)
at javax.faces.component.UIViewParameter.getConvertedValue(UIViewParameter.java:437)
at javax.faces.component.UIInput.validate(UIInput.java:975)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1248)
at javax.faces.component.UIInput.processValidators(UIInput.java:712)
at javax.faces.component.UIViewParameter.processValidators(UIViewParameter.java:278)
at org.omnifaces.component.input.ViewParam.processValidators(ViewParam.java:120)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
... 55 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:97)
... 92 more
Caused by: javax.faces.FacesException: ajax() can only be used in AJAX requests!
at org.primefaces.PrimeFaces.ajax(PrimeFaces.java:230)
at com.skf.gui.controllers.calc.CalculationController.InitPage1(CalculationController.java:114)</span>
at com.skf.gui.controllers.calc.CalculationController.OnPostConstruct(CalculationController.java:96)</span>
at com.skf.gui.controllers.general.GenericController.Init(GenericController.java:69)</span>
... 97 more

Here is the code-snipped that raises the current exception with the new method:

Code: Select all

@ViewScoped
@Named(value="calc")
public class CalculationController implements Serializable  
{
	private static final long serialVersionUID = 7040550658218725378L;

	@Override
    public void OnPostConstruct()
    {
        InitPage1();
    }
    private void InitPage1()
    {
        // Update Master Detail Controller:
        //
        // Working right:
        // RequestContext context = RequestContext.getCurrentInstance();
        // context.update("masterDetail");
        //
        // Raising an exception:
        PrimeFaces.current().ajax().update("masterDetail");
    }
}
------------
Using Wildfly 11.0.0,
Mojarra 2.2.13.SP4

stefan.sibitz
Posts: 38
Joined: 11 Nov 2016, 09:44

09 Nov 2017, 09:34

So i see that the error is raised from Primefaces

"ajax() can only be used in AJAX requests!"

but i don't get it in Primefaces 6.1.8 in combination with the RequestContext.


So what's the alternative ?
------------
Using Wildfly 11.0.0,
Mojarra 2.2.13.SP4

tandraschko
PrimeFaces Core Developer
Posts: 3529
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

09 Nov 2017, 10:18

Only use it in ajax requests - if you use it in non-ajax requests, i will currently also do NOTHING ;)

Code: Select all

PrimeFaces pf = PrimeFaces.current();
if (pf.isAjaxRequest()) {
    pf.ajax().update("...");
}
Always Bet On Prime (+ Extensions)!

Thomas Andraschko
PrimeFaces Developer | PrimeFaces Extensions Founder
Apache OpenWebBeans PMC | Apache DeltaSpike PMC | Apache MyFaces PMC

Personal Blog: http://tandraschko.blogspot.de/

chrishj
Posts: 171
Joined: 11 Jul 2011, 21:58

09 Nov 2017, 12:02

What is RequestContext replaced by?
J2EE 6 Glassfish 4.1 Mojarra 2.2.7 primefaces 6.2.7
Netbeans 8.1
database postgresql-9.4
Theme - Barcelona

User avatar
Melloware
Posts: 908
Joined: 22 Apr 2013, 15:48

09 Nov 2017, 14:09

RequestContext = PrimeFaces.current();
PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 6.2.10 / PF Extensions 6.2.9

stefan.sibitz
Posts: 38
Joined: 11 Nov 2016, 09:44

09 Nov 2017, 16:43

I don't understand what do you mean with "use it in Ajax-Request's" ?

I want to update a MasterDetail-Component on @PostConstruct and also on Ajax-Request's
by updating the component via the RequestContext / update function
and now i am getting an Fatal Weld Exception which kills my application when i am not in an Ajax-Request ?!

That's not a good practice because no one knows that it's now a problem which raises an exception if he only update the primefaces library !

Take a look at the primefaces-showcase by now:
You execute a JavaScript on PostConstruct which show's the user an alert -
does this also not work anymore in the next version :

https://www.primefaces.org/showcase/ui/ ... text.xhtml
Last edited by stefan.sibitz on 09 Nov 2017, 16:49, edited 3 times in total.
------------
Using Wildfly 11.0.0,
Mojarra 2.2.13.SP4

tandraschko
PrimeFaces Core Developer
Posts: 3529
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

09 Nov 2017, 16:46

@PostConstruct can be called in non-ajax requests too (like the initial page request). There is no ajax-update possible, that only works in ajax-requests. To overcome this, you can must only use update() in an ajax-request, like i mentioned in my last post.

Therefore the update() method is now below the ajax() method, to make it clear that it belongs to an ajax-request and will NEVER work in non-ajax requests.
I'm sure many users in the past called the update() method without any effect.
Always Bet On Prime (+ Extensions)!

Thomas Andraschko
PrimeFaces Developer | PrimeFaces Extensions Founder
Apache OpenWebBeans PMC | Apache DeltaSpike PMC | Apache MyFaces PMC

Personal Blog: http://tandraschko.blogspot.de/

stefan.sibitz
Posts: 38
Joined: 11 Nov 2016, 09:44

09 Nov 2017, 16:54

But raising an Exception which kill's any application
if they is using the "new function" in the @PostConstruct of the Application
seems to be a little bit hard to solve for the user instead of "ignoring" it...
------------
Using Wildfly 11.0.0,
Mojarra 2.2.13.SP4

tandraschko
PrimeFaces Core Developer
Posts: 3529
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

09 Nov 2017, 17:03

It has absoluty nothing todo with PostConstruct and works still fine if you wrap it with the IF statement.

It just helps you to not execute code, which should not be executed now and does not have ANY effect. It's actually a shame that we didn't add this years ago ;)

I will switch to log a warning for now and probably reintroduce the exeption again in the next release.
Always Bet On Prime (+ Extensions)!

Thomas Andraschko
PrimeFaces Developer | PrimeFaces Extensions Founder
Apache OpenWebBeans PMC | Apache DeltaSpike PMC | Apache MyFaces PMC

Personal Blog: http://tandraschko.blogspot.de/

stefan.sibitz
Posts: 38
Joined: 11 Nov 2016, 09:44

10 Nov 2017, 08:51

Yes, you are right that it shouldn't be used in a non Ajax-Request - that's right.
But first warn the user and after re-introducing that an exception will be raised is the better way i think ;-)

What i (and i think the other user's will do) is that i am wrapping it in a library/function
and do the Ajax-Test before it raises me an exception.
So i got the same result as before (ignoring the exception),
but it also work's for the update because there is no difference if i do the Update via Ajax or do a full re-rendering...
------------
Using Wildfly 11.0.0,
Mojarra 2.2.13.SP4

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 3 guests