0

我正在使用 JSF (Mojarra 2.2.6) 和 Primefaces 5.13 构建一个 Java EE 7 webapp,在 Glassfish 4.1 网络服务器上运行。

现在我遇到了 conversationScoped bean (CDI) 的问题。

我想做的是:使用 primefaces autoCompleteText 选择客户并显示他/她的详细信息。此外,我想停止旧对话(以便彻底重置所有 bean)并立即开始新的对话。

只要我先使用 ap:commandButton 结束旧对话,然后通过 autocompleteText 中的 p:ajax itemSelect 事件开始新对话,它就可以正常工作。

但它不起作用,当我结束旧对话并通过一个 itemSelect 事件开始新对话时。在这种情况下,我得到 NonExistantConversationException:

2015-03-26T14:23:24.834+0100|Warnung: StandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet threw exception
org.jboss.weld.context.NonexistentConversationException: WELD-000321: No conversation found to restore for id 1
    at org.jboss.weld.context.AbstractConversationContext.initialize(AbstractConversationContext.java:259)
    at org.jboss.weld.context.http.LazyHttpConversationContextImpl.initialize(LazyHttpConversationContextImpl.java:68)
    at org.jboss.weld.context.http.LazyHttpConversationContextImpl.checkContextInitialized(LazyHttpConversationContextImpl.java:93)
    at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:74)
    at org.jboss.weld.context.PassivatingContextWrapper$AbstractPassivatingContextWrapper.get(PassivatingContextWrapper.java:76)
    at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:740)
    at org.jboss.weld.el.AbstractWeldELResolver.lookup(AbstractWeldELResolver.java:107)
    at org.jboss.weld.el.AbstractWeldELResolver.getValue(AbstractWeldELResolver.java:90)
    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:151)
    at com.sun.el.parser.AstValue.getTarget(AstValue.java:170)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:272)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
    at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
    at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at com.sun.faces.facelets.tag.jsf.core.DeclarativeSystemEventListener.processEvent(EventHandler.java:128)
    at javax.faces.component.UIComponent$ComponentSystemEventListenerAdapter.processEvent(UIComponent.java:2585)
    at javax.faces.event.SystemEvent.processListener(SystemEvent.java:108)
    at javax.faces.event.ComponentSystemEvent.processListener(ComponentSystemEvent.java:118)
    at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2187)
    at com.sun.faces.application.ApplicationImpl.invokeComponentListenersFor(ApplicationImpl.java:2135)
    at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:289)
    at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:247)
    at javax.faces.application.ApplicationWrapper.publishEvent(ApplicationWrapper.java:726)
    at javax.faces.application.ApplicationWrapper.publishEvent(ApplicationWrapper.java:726)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:107)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:724)

2015-03-26T14:23:24.837+0100|Schwerwiegend: FullAjaxExceptionHandler: An exception occurred during processing JSF ajax request. Error page '/error/NonexistentConversationException.xhtml?nocid=true' will be shown.
org.jboss.weld.context.NonexistentConversationException: WELD-000321: No conversation found to restore for id 1
    at org.jboss.weld.context.AbstractConversationContext.initialize(AbstractConversationContext.java:259)
    at org.jboss.weld.context.http.LazyHttpConversationContextImpl.initialize(LazyHttpConversationContextImpl.java:68)
    at org.jboss.weld.context.http.LazyHttpConversationContextImpl.checkContextInitialized(LazyHttpConversationContextImpl.java:93)
    at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:74)
    at org.jboss.weld.context.PassivatingContextWrapper$AbstractPassivatingContextWrapper.get(PassivatingContextWrapper.java:76)
    at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:740)
    at org.jboss.weld.el.AbstractWeldELResolver.lookup(AbstractWeldELResolver.java:107)
    at org.jboss.weld.el.AbstractWeldELResolver.getValue(AbstractWeldELResolver.java:90)
    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:151)
    at com.sun.el.parser.AstValue.getValue(AstValue.java:200)
    at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
    at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
    at org.primefaces.component.datatable.DataTable.getFilteredValue(DataTable.java:360)
    at org.primefaces.component.datatable.DataTable.processEvent(DataTable.java:1621)
    at com.sun.faces.lifecycle.RestoreViewPhase$1.visit(RestoreViewPhase.java:440)
    at com.sun.faces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:151)
    at org.primefaces.component.api.UIData.visitTree(UIData.java:821)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1701)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1701)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1701)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1701)
    at org.primefaces.component.api.UITabPanel.visitTree(UITabPanel.java:920)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1701)
    at javax.faces.component.UIForm.visitTree(UIForm.java:371)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1701)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1701)
    at com.sun.faces.lifecycle.RestoreViewPhase.deliverPostRestoreStateEvent(RestoreViewPhase.java:436)
    at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:273)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:121)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:724)

这里是 XHTML 代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:ui="http://java.sun.com/jsf/facelets">
    <p:focus id="patSuchfeldFocus" for="patientenSuchFeld" />

    <p:remoteCommand name="rc"  
                actionListener="#{patContDesk.setCurrentPatientUndKillView()}" />

    <h:panelGrid columns="5"
        columnClasses="patSuche_label, d_span5, patSucheNach_label, span2, patSuche_label"
        style="margin-top:4px;">
        <h:outputText value="Suche:" style="position:relative;top:-4px;" />
        <p:autoComplete disabled="#{!patContDesk.isRenderMenuBar()}"
            style=" padding-bottom: 8px;" label="Suche:" autocomplete="true"
            id="patientenSuchFeld" onclick="this.select();"
            emptyMessage="#{stringKonstanten.keineSuchergebnisse}"
            minQueryLength="1" queryDelay="400"
            value="#{patSuchContDesk.aktPatSuchErgebnis}" var="pat"
            itemLabel="#{patSuchContDesk.suchPatToString(pat)}"
            itemValue="#{pat}" converter="patient"
            completeMethod="#{patSuchContDesk.complete}" size="40">         
        <p:ajax event="itemSelect" process="@form"
                listener="#{patContDesk.setCurrentPatientUndKillView()}" />

            <p:ajax event="itemSelect" process="@all"
                listener="#{patSuchContDesk.goToNextPagedsk()}" />
        </p:autoComplete>
        <h:outputText value="Suchen nach:" style="position:relative;top:-4px;" />
        <p:selectOneMenu disabled="#{!patContDesk.isRenderMenuBar()}"
            id="aktuellerSuchModus" value="#{patSuchContDesk.aktSuchModus}"
            style="position:relative;top:-5px; height:34px;">
            <f:selectItems value="#{patSuchContDesk.getPatientenSuchModi()}" />
            <p:ajax event="change" update=":content" process="@this" />
        </p:selectOneMenu>
        <h:panelGroup layout="block" styleClass="d_menubar"
            style="width:110% !important;position:relative;top:-3px;">
            <div style="height: 8px;"></div>
            <h:commandLink style="padding-left:10px;"
                actionListener="#{patContDesk.resetAndSwitchToTabX(0)}"
                disabled="#{(!permCheck.darfAnlegenUndAendern('PAT')) or  !(patContDesk.isRenderMenuBar())}"
                immediate="true" update=":content"
                action="#{patContDesk.initConversation('', '')}"
                tabindex="#{nav.indexForAccesKey}">
                <i class="icon-user-2 hardblue"><h:outputText
                        value="Patient neu anlegen"
                        style="padding-left:5px; font-style:normal; color: #303030;" /></i>
            </h:commandLink>

            <p:commandButton value="Navtest" update=":content"
                action="#{patSuchContDesk.endConv()}" 
                actionListener="#{patContDesk.setCurrentPatientUndKillView()}"      />

                <p:commandButton value="Navtest Raoul2"
                actionListener="#{patSuchContDesk.endConv()}"
                action="/pages/desktop/test/TestRaoul2.xhtml?faces-redirect=true" />
        </h:panelGroup>
    </h:panelGrid>
</ui:composition>

这是支持bean的(相关)代码:

@ViewScoped
@ManagedBean(name = "patSuchController")
public class PatientSuchController extends MMController implements Serializable {
//Fields + getters + setters

public void setCurrentPatientUndKillView() {
        currentPatient = null;
        updateView("content");
        endConv();
    }

    public void endConv() {
        if (!conv.isTransient()) {
            System.out.println("patContDesk wird beendet...");
            conv.end();
        }
    }

public void updateView(String viewToUpdate) {
        RequestContext ctx = RequestContext.getCurrentInstance();
        ctx.update(viewToUpdate);
    }

    public void goToNextPagedsk() {     
        String ziel = "";
        ziel = "/pages/desktop/adressen/pat/Patient2.xhtml?faces-redirect=true";

        String param = "patId=" + aktPatSuchErgebnis[0];
        String from = pK.getPatSuche();
        nav.goToXYNeu(ziel, from, param);
    }

@Named("nav")
@ConversationScoped
public class Navigation extends MMController implements Serializable {
//Fields + getters + setters
    public void goToXYNeu(String ziel, String from, String param) {
        FacesContext fctx = FacesContext.getCurrentInstance();
        Application application = fctx.getApplication();
        NavigationHandler navHandler = application.getNavigationHandler();

        StringBuilder sb = new StringBuilder();
        sb.append(ziel);
        sb.append("&");
        sb.append(param);

        String zielUrlKomplett = baueNavPfad(sb.toString(), true);

        System.out.println("goToXY: " + zielUrlKomplett);
        navHandler.handleNavigation(fctx, null, zielUrlKomplett);
    }

所以,问题是:在用户从 primefaces autoCompleteText 中选择客户的那一刻,通常是否有可能停止一个 cdi 对话并立即开始一个新的对话?

非常感谢您的帮助!

编辑:新对话由目标页面上的此 preRenderView 事件启动:

<f:event listener="#{patContDesk.initConversation(nav.getParam('patId'), nav.getPfadParameter())}"
type="preRenderView" />

...在我的支持 bean 中使用此方法:

@Named
@ConversationScoped
public class PatientController extends MMController {
// Fields, getters + setters...
 public void initConversation(String neuPatId, String from) {
    if (!FacesContext.getCurrentInstance().isPostback()
    && conv.isTransient()) {
        conv.begin();
        nav.pushPfad(pK.getPatient(), true);

        // 30 Minuten Timeout.
        conv.setTimeout(1800000);

        System.out.println("aktPatId: " + neuPatId);
        System.out.println("beginConv PatControl: " + conv.getId());
    }
}

唯一需要做的就是删除 autoCompleteText 的第一个 itemSelect 事件并使用 rc() 在 onclick-client-side callbackhandler 中调用 p:remoteCommand;

4

0 回答 0