jsf render allways an xhtml page - jsf

Hi im testing my new app, and i have a problem when i click a button on my form, it has a table on it and im always check for a values, if it true it render if not it doesnt, and a button for register data . The problem is that im deleting some data of the table by a script and it give me a null pointer exception when i click the button. In the logs files it says it render the page again and then goes to the specific function of the button, and since i have already delete the data when it tried to render the page again give me a error 500.
here is me table :
<h:panelGroup id="tab1" rendered="#{DataControl.tabIndex == 1}">
<h:dataTable>
<h:column>
<h:commandButton disabled="#{DataControl.CheckDelete(item.intIdAddress)}" />
</h:column>
</h:dataTable>
<h:commandButton action="#{DataControl.AddAddress}" />
</h:panelGroup>
<h:panelGroup id="tab2" rendered="#{DataControl.tabIndex == 2}">
< Refister Form >
</h:panelGroup>
here is my checkDelete function :
public boolean CheckDelete() {
Util.getLog().info("CheckDelete for id : "+ id);
if (id.render)
return true;
else
return false;
}
here is my AddAddress function :
public String AddAddress(){
Util.getLog().info("Go to Register Div");
tabIndex = 2;
}
And the Logs File when im in the form and click the button :
Enter to filter : Has Session
CheckDelete for id : 1
CheckDelete for id : 2
CheckDelete for id : 3
CheckDelete for id : 4
Go to Register Div
And when i delete the data N° 2 the Logs file is (im in the form, delete the data and then i click the button):
Enter to filter : Has Session
CheckDelete for id : 1
javax.el.ELException: /pages/session/account_settings.xhtml #101,253 disabled="#{GeneralDataControl.VerificaEliminacion(item.intIdAddress)}": java.lang.NullPointerException
javax.faces.FacesException: javax.el.ELException: /pages/session/account_settings.xhtml #101,253 disabled="#{GeneralDataControl.VerificaEliminacion(item.intIdAddress)}": java.lang.NullPointerException
at javax.faces.component.UIComponentBase$AttributesMap.get(UIComponentBase.java:2214)
at com.sun.faces.util.Util.componentIsDisabledOrReadonly(Util.java:418)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.shouldDecode(HtmlBasicRenderer.java:739)
at com.sun.faces.renderkit.html_basic.ButtonRenderer.decode(ButtonRenderer.java:77)
at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:791)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1048)
at javax.faces.component.UIData.iterate(UIData.java:1477)
at javax.faces.component.UIData.processDecodes(UIData.java:980)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1043)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1043)
at javax.faces.component.UIForm.processDecodes(UIForm.java:212)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1043)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1043)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:920)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:74)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1213)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1154)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:145)
at com.alignet.wallet.cliente.filter.FiltroHibernate.doFilter(FiltroHibernate.java:90)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:87)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:848)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:691)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:654)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:526)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:90)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:764)
at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1478)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:133)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:457)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:515)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:300)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:102)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:196)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:751)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:881)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1593)
Caused by: javax.el.ELException: /pages/session/account_settings.xhtml #101,253 disabled="#{GeneralDataControl.VerificaEliminacion(item.intIdAddress)}": java.lang.NullPointerException
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:111)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:190)
at javax.faces.component.html.HtmlCommandButton.isDisabled(HtmlCommandButton.java:183)
at sun.reflect.GeneratedMethodAccessor489.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:619)
at javax.faces.component.UIComponentBase$AttributesMap.get(UIComponentBase.java:2206)
... 44 more
Caused by: java.lang.NullPointerException
at com.alignet.wallet.cliente.web.GeneralDataJSFAction.VerificaEliminacion(GeneralDataJSFAction.java:388)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:619)
at javax.el.BeanELResolver.invokeMethod(BeanELResolver.java:737)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:467)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:246)
at com.sun.el.parser.AstValue.getValue(AstValue.java:111)
at com.sun.el.parser.AstValue.getValue(AstValue.java:163)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:106)
... 50 more
its seems that jsf always render the page before to do the submit, i dont know how to solve this. I think is a configuration thing.
Im using a filter (the only filter ) to check for the session of the user and then a "doFilter" to let the response continue.
Thanks 4 ur time.

Related

ADF popup cancel listener not invoked on closing dialog with error values

The issue is when I enter some negative value in the inputBox within the dialog component and the validator throws error something like "Negative numbers not allowed". The dialog now has an error input box marked with red border and I decide to click outside the dialog to close it and reset the input box, but the inputBox is not reset and if I press Esc key or Ok button then only the popupCanceledListener is called and the inputBox is reset. Below is the code which contains a popup with dialog and inputBox within it.
JSF code:
<af:popup contentDelivery="lazyUncached" autoCancel="enabled"
popupCanceledListener="#{pageFlowScope.testBean.handleResetPopup}"
childCreation="deferred" id="testPopup">
<af:dialog type="none" modal="false"
id="Dlg1">
<af:inputText label="DECIMAL PLACES"
columns="2"
validator="#{pageFlowScope.testBean.validateDecimalPlaceValue}"
value="#{pageFlowScope.testBean.decimalPlace}"
id="input1" autoSubmit="true"></af:inputText>
<f:facet name="acceptNFChange">
<af:commandButton text="OK" id="cb1"
actionListener="#{pageFlowScope.testBean.handleOkFromPopup}"
partialSubmit="true"></af:commandButton>
</f:facet>
</af:dialog>
</af:popup>
Bean code:
public void handleResetPopup(PopupCanceledEvent popupCanceledEvent) {
try {
UIComponent component = popupCanceledEvent.getComponent();
RichInputText inputText = (RichInputText)JSFUtil.findComponent(component, "input1");
inputText.resetValue();
} catch (Throwable th) {
this.handleException(th);
}
}
Problem: When clicking outside the dialog to close it and reset the inputbox, the popupCanceledListener is not invoked.
The best way is to use client listener with type popupClosed. Here is example for your code:
<af:popup contentDelivery="lazyUncached" autoCancel="enabled"
popupCanceledListener="#{pageFlowScope.testBean.handleResetPopup}"
childCreation="deferred" id="testPopup">
<af:dialog type="none" modal="false"
id="Dlg1">
<af:inputText label="DECIMAL PLACES"
columns="2"
validator="#{pageFlowScope.testBean.validateDecimalPlaceValue}"
value="#{pageFlowScope.testBean.decimalPlace}"
id="input1" autoSubmit="true"></af:inputText>
<f:facet name="acceptNFChange">
<af:commandButton text="OK" id="cb1"
actionListener="#{pageFlowScope.testBean.handleOkFromPopup}"
partialSubmit="true"></af:commandButton>
</f:facet>
</af:dialog>
<af:clientListener type="popupClosed" method="popupCloseClientListener"/>
<af:serverListener type="popupClosedEvent" method="#{pageFlowScope.testBean.handlePopupClosed}"/>
</af:popup>
then you need to write somewhere in JSF script:
<script>
function popupCloseClientListener(event) {
component = event.getSource();
AdfCustomEvent.queue(component,
"popupClosedEvent",
{payload:component.getSubmittedValue()},
true);
event.cancel();
}
</script> ]]>
In this way you can always correctly handle popup closed event from client. And implement all server logic you need.
The solution provided in this link https://community.oracle.com/thread/4112016 works fine for my scenario.

Alternative to f:verbatim in JSF 2.1

Alternative to f:verbatim in JSF 2.1 for rendering purpose is needed. In my application I am using ui:fragment rendered instead of f:verbatim but it is not working in jsf 2.1.
Here i am providing my code
<f:verbatim rendered="#{not empty focusField}">
<script type="text/javascript">
$(document).ready(function(){
// If the class is not set, do so now
$("#menuContainer > ul:first:not(.sf-menu)").addClass("sf-menu");
$("ul.sf-menu").supersubs({
minWidth: 12, // minimum width of sub-menus in em units
maxWidth: 27, // maximum width of sub-menus in em units
extraWidth: 1 // extra width can ensure lines don't sometimes turn over
// due to slight rounding differences and font-family
}).superfish({
delay: 300
});
});
</script>
</f:verbatim>
<ui:component>
<ui:fragment rendered="#{not empty focusField}">
<script type="text/javascript">
$(document).ready(function(){
// If the class is not set, do so now
$("#menuContainer > ul:first:not(.sf-menu)").addClass("sf-menu");
$("ul.sf-menu").supersubs({
minWidth: 12, // minimum width of sub-menus in em units
maxWidth: 27, // maximum width of sub-menus in em units
extraWidth: 1 // extra width can ensure lines don't sometimes turn over
// due to slight rounding differences and font-family
}).superfish({
delay: 300
});
});
</script> </ui:fragment>
</ui:component>
I am getting this error
Root cause of ServletException.
org.springframework.webflow.execution.FlowExecutionException: Exception thrown in state 'demo' of flow 'demo'
at org.springframework.webflow.engine.impl.FlowExecutionImpl.wrap(FlowExecutionImpl.java:571)
at org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:262)
at org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:169)
at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:183)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3592)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2202)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2108)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1432)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
Caused By: javax.faces.FacesException: Component ID demo has already been found in the view.
at com.sun.faces.context.ExceptionHandlerImpl.handle(ExceptionHandlerImpl.java:142)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at org.springframework.faces.webflow.FlowLifecycle.render(FlowLifecycle.java:80)
at org.springframework.faces.webflow.JsfView.render(JsfView.java:89)
at org.springframework.webflow.engine.ViewState.render(ViewState.java:296)
at org.springframework.webflow.engine.ViewState.refresh(ViewState.java:243)
at org.springframework.webflow.engine.ViewState.resume(ViewState.java:221)
at org.springframework.webflow.engine.Flow.resume(Flow.java:545)
at org.springframework.webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:258)
at org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:169)
at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:183)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
Caused By: java.lang.IllegalStateException: Component ID demo has already been found in the view.
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:910)
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:894)
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:894)

how to stop calling onclick function while refreshing a page?

I have a page with a p:Menuitem using OnClick function.
My problem is that when i refresh the page, the event onclick is still running, how can i stop it?
Client-side code:
<p:submenu label="Ordres de Fabrication" styleClass="submenustyle" >
<p:submenu label="Ordre non Réalisé">
<p:menuitem value="Afficher" outcome="/admin/gestionduplanning/ofnonrealiseAfficher.xhtml" onclick="#{ofrealiser.getofnonrealiser()}" />
<p:menuitem value="Ajouter" outcome="/admin/gestionduplanning/ofnorealiseAjouter.xhtml" />
</p:submenu> ...
UPDATE 1 :
<p:menuitem value="Afficher" outcome="/admin/gestionduplanning/ofnonrealiseAfficher.xhtml" onclick="#{ofrealiser.getofnonrealiser()}" actionListener="#{exporterPlanningGlobal.refreshfromjsfdateplanning()}" />
the managed bean methode :
public void refreshfromjsfdateplanning()
{
System.out.println("Test actionlistener");
}
but the methode isnt called because in my IDE glassfish it didnt print anything .
how to get the actionlistner working ??
UPDATE 2 :
i found that when i remove the outcome from the menu the action listner is working .. but when i use outcome or url to go to a page didnt work how to solve that ?
Both onclick and oncomplete should only be used to call a javascript event handler.
If you want to call something on server when clicking a menu item then use actionListener.
As a side line, of course the code inside the onclick will trigger when refreshing the page because the jsf expressions are evaluated on the page rendering phase.
You can find a working example on the Primefaces Demo
I found the solution for my problem : do a treatment before navigating with p:menuitem :
<p:menuitem value="Exporter tous les plannings" styleClass="submenustyle" action="#{exporterPlanningGlobal.refreshfromjsfdateplanning}" update="#form"/>
and managed bean methode :
public String refreshfromjsfdateplanning()
{
System.out.println("treatment done");
return "/espaceZP01/gestionduplanning/exporterTousPlanning.xhtml?faces-redirect=true";
}

Using core liferay permission helper classes in custom portlets

The Liferay developer documentation recommends writing and user permission helper classes such as BlogsPermission.
When I try to use it in a portlet class, I get a 'java.lang.ClassNotFoundException. Hence the question: how can I user permission helpers in a custom portlet ?
Thanks,
Alain
Edit
I tried the following code in my controller:
public boolean getCanUpdate(){
PermissionChecker permissionChecker = getThemeDisplay().getPermissionChecker();
try {
return DLFileEntryPermission.contains(permissionChecker, _fileEntry, ActionKeys.UPDATE);
} catch (Exception e) {
if (_log.isWarnEnabled()) {
_log.warn(String.format("could not check update permission for fileEntry[%d]", _fileEntry.getFileEntryId()));
e.printStackTrace();
}
return false;
}
}
In my jsp, I have the following:
<c:if test="${fileEntryDisplayBean.canUpdate}">
<li class="right">
<span class="toolbar-button standalone-button icon-pencil"
title="<liferay-ui:message key="edit"/>">
</span>
</li>
</c:if>
and I get the runtime error
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.ClassNotFoundException: com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at org.bamboost.portlet.transversal.documents.FileEntryDisplayBean.getCanUpdate(FileEntryDisplayBean.java:95)
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:87)
at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104)
...
You can use this code to check permission on a File :
_fileEntry.containsPermission(permissionChecker, ActionKeys.UPDATE);
Else for some entities like Group you can find a PermissionUtil class that is located in the portal-service.jar and then available from your portlet.
Example :
GroupPermissionUtil

Weld 1.0.1-Final: Conversation Scope bean keeps recreated even after beginning conversation?

Im currently using :
Apache tomcat 7
JBoss Weld servlet 1.0.1-Final
empty beans.xml
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class> in the web.xml
I'm currently testing a simple counter #ConversationScoped bean, and the intention is, after beginning the conversation scope, to keep incrementing the counter whenever the button is clicked ..
But it seems that after submit, the bean will always be recreated, even after i've begin the conversation in the 1st place.
Here's my simple bean :
package user.ui;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;
#Named
#ConversationScoped
public class CounterBean implements Serializable {
#Inject
private Conversation conversation;
#PostConstruct
public void init() {
System.out.println("beginning conversation : " + this.conversation);
this.conversation.begin();
}
private int counter;
public int getCounter() {
return counter;
}
public void setCounter(int counter) {
this.counter = counter;
}
public void increment() {
this.counter++;
}
}
Here's my simple jsf view :
<ui:composition template="/template/masterlayout.xhtml">
<ui:define name="windowTitle">Test Conversation Scope</ui:define>
<ui:define name="heading">Test Conversation Scope</ui:define>
<ui:define name="content">
<h:form>
<p:messages id="messages" globalOnly="true" />
<p:panel header="Test Conversation Scope">
<h:outputText value="counter : " /> #{counterBean.counter}
</p:panel>
<h:commandButton value="Submit Data to Server" action="#{counterBean.increment}" />
</h:form>
</ui:define>
</ui:composition>
Here's the log file for the 1st access :
INFO: Server startup in 12055 ms
beginning conversation : ID: 1, transient: true, timeout: 600000ms
And after the view is displayed, i clicked on the button, and there goes the exception throwing with this log in catalina.out :
beginning conversation : ID: 2, transient: true, timeout: 600000ms
unhandled exception : org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type #ConversationScoped
cause exception : org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type #ConversationScoped, cause exception is BE : false
Here's the exception trace from tomcat log :
Apr 4, 2011 3:56:27 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/primebert] threw exception [WELD-001303 No active contexts for scope type #ConversationScoped] with root cause
org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type #ConversationScoped
at org.jboss.weld.conversation.ConversationImpl.checkConversationActive(ConversationImpl.java:79)
at org.jboss.weld.conversation.ConversationImpl.isTransient(ConversationImpl.java:234)
at org.jboss.weld.conversation.ConversationImpl.toString(ConversationImpl.java:199)
at java.text.MessageFormat.subformat(MessageFormat.java:1246)
at java.text.MessageFormat.format(MessageFormat.java:836)
at java.text.Format.format(Format.java:140)
at java.text.MessageFormat.format(MessageFormat.java:812)
at ch.qos.cal10n.MessageConveyor.getMessage(MessageConveyor.java:89)
at org.jboss.weld.logging.WeldMessageConveyor.getMessage(WeldMessageConveyor.java:78)
at org.slf4j.cal10n.LocLogger.debug(LocLogger.java:95)
at org.jboss.weld.conversation.ConversationImpl.switchTo(ConversationImpl.java:190)
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 org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:304)
at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54)
at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163)
at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:298)
at org.jboss.weld.bean.proxy.ClientProxyMethodHandler.invoke(ClientProxyMethodHandler.java:113)
at org.jboss.weld.util.CleanableMethodHandler.invoke(CleanableMethodHandler.java:43)
at org.jboss.weld.conversation.ConversationImpl_$$_javassist_2.switchTo(ConversationImpl_$$_javassist_2.java)
at org.jboss.weld.conversation.AbstractConversationManager.beginOrRestoreConversation(AbstractConversationManager.java:137)
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 org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:304)
at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54)
at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163)
at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:298)
at org.jboss.weld.bean.proxy.ClientProxyMethodHandler.invoke(ClientProxyMethodHandler.java:113)
at org.jboss.weld.util.CleanableMethodHandler.invoke(CleanableMethodHandler.java:43)
at org.jboss.weld.conversation.ServletConversationManager_$$_javassist_0.beginOrRestoreConversation(ServletConversationManager_$$_javassist_0.java)
at org.jboss.weld.jsf.WeldPhaseListener.initiateSessionAndConversation(WeldPhaseListener.java:171)
at org.jboss.weld.jsf.WeldPhaseListener.beforeRestoreView(WeldPhaseListener.java:118)
at org.jboss.weld.jsf.WeldPhaseListener.beforePhase(WeldPhaseListener.java:87)
at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:111)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:383)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:288)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Any ideas what went wrong ?
Thank you !
To keep track of the long-running conversation Weld inserts the cid parameter in the action method of the HTML form.
In your case you start the long-running conversation in the PostConstruct method of the counterBean. But the counterBean gets referenced first inside the h:form, so by the time counterBean gets initialized the h:form's header was already rendered. You need to start the conversation earlier.
I'm not sure what's the best way to do that. Probably like that:
<f:metadata>
<f:event type="preRenderView" listener="#{someBean.init}"/>
</f:metadata>
You could start the conversation on GET request only:
public void init() {
if (!FacesContext.getCurrentInstance().isPostback()) {
conversation.begin();
}
}
JSF 2.2 has a <f:viewAction> tag (analogous to Seam page actions), that could be used to accomplish the same thing.
Alternatively you can just place this EL expression above the form:
#{javax.enterprise.context.conversation.begin()}
But then you have to be careful not to re-render this expression again.
As a side note, a conversation is often started on some JSF action, such as a button click. One needs to keep in mind, that for a proper conversation propagation forms need to be re-rendered.
From a CDI point of view, your code should work (it actually works on a JBoss AS 6). What seems to happen is that the conversation isn't propagated between two requests, but that should be implicit when using JSF form submits. I assume your setup is wrong and Tomcat isn't configured as it should be.
As a first step, try to propagate the conversation id manually, as described here.
We've seen the same so work around it we are performing a redirect back to the page as soon as we start a conversation. We know which parts of our app need conversations based on form id prefix, so can do this in an early phase listener. After Restore View works well. I'm having trouble performing redirects from Before Restore View which would be more ideal.
I've ended up using HttpServletRequest from FacesContext.getExternalContext().getRequest() which can give the full URL to redirect to. I do break it down in code and recombine it - the structure of our code and a reusable class to contain the concept of a form and parameters. The sendRedirect with exception handling removed is
ExternalContext external = faces.getExternalContext();
String baseUrl = external.getRequestContextPath() + m_formId;
String target = external.encodeRedirectURL(baseUrl, m_requestParameters);
external.redirect(target);

Resources