简体   繁体   English

JBoss接缝:在ScopeType.PAGE中,我得到:java.lang.IllegalStateException:没有对话上下文处于活动状态

[英]JBoss Seam: In ScopeType.PAGE I get: java.lang.IllegalStateException: No conversation context active

I have a page-scoped component, which has an instance variable List with data, which I display in a datatable. 我有一个页面范围的组件,该组件具有一个实例变量List和数据,该变量显示在数据表中。 This datatable has pagination, sorting and filtering. 该数据表具有分页,排序和过滤。

The first time gate into the page, I get this appended in my URL: ?conversationId=97 . 第一次进入页面时,我将其添加到URL: ?conversationId = 97中 The page works correctly, and when I change datatable pages no now component is created. 该页面正常工作,并且当我更改数据表页面时,现在不创建任何组件。

After a minute or two, and at seamingly random time, I get an exception saying that there is no context. 一两分钟之后,而且在随机的时间,我得到一个例外,说没有上下文。 I have not used @Create in my code or my navigation files. 我没有在代码或导航文件中使用@Create。

So, I have two questions: 因此,我有两个问题:

  • Why do I get this suffix in my URL? 为什么我的URL中有这个后缀? Why did a conversation start? 为什么开始对话?
  • Why the exception? 为什么例外? The component is scoped to PAGE. 该组件的作用域为PAGE。 If I received an exception, it should not be related to a conversation. 如果我收到异常,则该异常不应与对话有关。 Right? 对? Or is the conversation the exception is referring a temporary conversation? 还是该对话是指临时对话的例外?

Cheers! 干杯!

UPDATE I: 更新一:

The project is an Ear. 该项目是一个耳朵。

This is the page: 这是页面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">

<body>
<ui:composition template="/WEB-INF/facelets/templates/template.xhtml">


<ui:define name="content">

    <!--  This method returns focus on the filter -->
    <script type="text/javascript">

    function submitByEnter(event){
        if (event.keyCode == 13) {
            if (event.preventDefault) {
                // Firefox
                event.preventDefault(); 
            } else {
                // IE 
                event.returnValue = false; 
            }
            document.getElementById("refreshButton").click();
        } 
    }

    </script>

    <h:form prependId="false">

        <h:commandButton action="Back" value="Back to home page" />
        <br />

        <p><h:outputText
            value="Applicants and Products (experimentation page)"
            class="page_title" /></p>


        <h:commandButton
            action="#{applicantProductListBean.showCreateApplicant}"
            value="Create Applicant" id="createApplicantButton">
        </h:commandButton>

        <a4j:commandButton value="Refresh" id="refreshButton"
            action="#{applicantProductListBean.refreshData}"
            image="/images/icons/refresh48x48.gif"
            reRender="compositeTable, compositeScroller">
<!--                <f:setPropertyActionListener-->
<!--                    target="# {pageScrollerBean.applicantProductListPage}" value="1" />-->
        </a4j:commandButton>

        <rich:toolTip for="createApplicantButton" value="Create Applicant" />

        <rich:dataTable styleClass="composite2DataTable" id="compositeTable"
            rows="1" columnClasses="col"
            value="#{applicantProductListBean.dataModel}" var="pageAppList">
            <f:facet name="header">
                <rich:columnGroup>
                    <rich:column colspan="3">
                        <h:outputText styleClass="headerText" value="Applicants" />
                    </rich:column>
                    <rich:column colspan="3">
                        <h:outputText styleClass="headerText" value="Products" />
                    </rich:column>
                    <rich:column breakBefore="true">
                        <h:outputText styleClass="headerText" value="Applicant Name" />



                        <a4j:commandButton id="sortingApplicantNameButton"
                            action="#{applicantProductListBean.toggleSorting('applicantName')}"
                            image="/images/icons/sorting/#{sortingFilteringBean.applicantProductListSorting.sortingValues['applicantName']}.gif"
                            reRender="sortingApplicantNameButton, sortingApplicantEmailButton, compositeTable, compositeScroller">
<!--                                    <f:setPropertyActionListener-->
<!--                                    target="#{pageScrollerBean.applicantProductListPage}" value="1" />-->
                        </a4j:commandButton>




                        <br />
                        <h:inputText
                            value="#{sortingFilteringBean.applicantProductListFiltering.filteringValues['applicantName']}"
                            id="applicantNameFilterValue"
                            onkeypress="return submitByEnter(event)">
                        </h:inputText>
                    </rich:column>
                    <rich:column>
                        <h:outputText styleClass="headerText" value="Applicant Email" />
                        <a4j:commandButton id="sortingApplicantEmailButton"
                            action="#{applicantProductListBean.toggleSorting('applicantEmail')}"
                            image="/images/icons/sorting/#{sortingFilteringBean.applicantProductListSorting.sortingValues['applicantEmail']}.gif"
                            reRender="sortingApplicantNameButton, sortingApplicantEmailButton, compositeTable, compositeScroller">
<!--                                 <f:setPropertyActionListener-->
<!--                                    target="#{pageScrollerBean.applicantProductListPage}" value="1" />-->
                        </a4j:commandButton>
                        <br />
                        <h:inputText
                            value="#{sortingFilteringBean.applicantProductListFiltering.filteringValues['applicantEmail']}"
                            id="applicantEmailFilterValue"
                            onkeypress="return submitByEnter(event)">
                        </h:inputText>
                    </rich:column>
                    <rich:column>
                        <h:outputText styleClass="headerText" value="Applicant Actions" />
                    </rich:column>
                    <rich:column>
                        <h:outputText styleClass="headerText" value="Product Name" />

                        <a4j:commandButton id="sortingProductNameButton"
                            action="#{applicantProductListBean.toggleSorting('productName')}"
                            immediate="true"
                            image="/images/icons/sorting/#{sortingFilteringBean.applicantProductListSorting.sortingValues['productName']}.gif"
                            reRender="sortingProductNameButton, compositeTable, compositeScroller">
                        </a4j:commandButton>



                        <br />
                        <h:inputText
                            value="#{sortingFilteringBean.applicantProductListFiltering.filteringValues['productName']}"
                            id="productNameFilterValue"
                            onkeypress="return submitByEnter(event)">
                        </h:inputText>
                    </rich:column>
                    <rich:column>
                        <h:outputText styleClass="headerText" value="Product Email" />
                        <br />
                        <h:inputText
                            value="#{sortingFilteringBean.applicantProductListFiltering.filteringValues['productEmail']}"
                            id="productEmailFilterValue"
                            onkeypress="return submitByEnter(event)">
                        </h:inputText>
                    </rich:column>
                    <rich:column>
                        <h:outputText styleClass="headerText" value="Product Actions" />
                    </rich:column>
                </rich:columnGroup>
            </f:facet>
            <rich:subTable rowClasses="odd_applicant_row, even_applicant_row"
                value="#{pageAppList}" var="app">
                <rich:column
                    styleClass=" internal_cell
                    composite2TextContainingColumn"
                    valign="top">
                    <h:outputText value="#{app.name}" />
                </rich:column>

                <rich:column
                    styleClass="internal_cell composite2TextContainingColumn"
                    valign="top">
                    <h:outputText value="#{app.receiptEmail}" />
                </rich:column>

                <rich:column valign="top" styleClass="buttonsColumn">
                    <h:commandButton
                        action="#{applicantProductListBean.showUpdateApplicant(app)}"
                        image="/images/icons/edit.jpg">
                    </h:commandButton>
                    <!--                    <rich:toolTip for="editApplicantButton" value="Edit Applicant" />-->
                    <h:commandButton
                        action="#{applicantProductListBean.showDeleteApplicant(app)}"
                        image="/images/icons/delete.png">
                    </h:commandButton>
                    <!--                    <rich:toolTip for="deleteApplicantButton" value="Delete Applicant" />-->
                </rich:column>



                <rich:column colspan="3">
                    <table class="productsTableTable">
                        <tbody>
                            <tr>
                                <td class="createProductButtonTableCell"><h:commandButton
                                    action="#{applicantProductListBean.showCreateProduct(app)}"
                                    value="Create Product">
                                </h:commandButton>     
<!--                    <rich:toolTip for="createProductButton" value="Create Product" />-->
                                </td>
                            </tr>
                            <tr>
                                <td><rich:dataTable value="#{app.products}" var="prod"
                                    rowClasses="odd_product_row, even_product_row">
                                    <rich:column
                                        styleClass="internal_cell composite2TextContainingColumn">
                                        <h:outputText value="#{prod.inventedName}" />
                                    </rich:column>

                                    <rich:column
                                        styleClass="internal_cell composite2TextContainingColumn">
                                        <h:outputText value="#{prod.receiptEmail}" />
                                    </rich:column>

                                    <rich:column styleClass="buttonsColumn">
                                        <h:commandButton
                                            action="#{applicantProductListBean.showUpdateProduct(prod)}"
                                            image="/images/icons/edit.jpg">
                                        </h:commandButton>
                                           <!--                         <rich:toolTip for="editProductButton" value="Edit Product" />-->
                                        <h:commandButton
                                            action="#{applicantProductListBean.showDeleteProduct(prod)}"
                                            image="/images/icons/delete.png">
                                            <f:setPropertyActionListener target="#{productBean.product}"
                                                value="#{prod}" />
                                        </h:commandButton>
                                          <!--                          <rich:toolTip for="deleteProductButton" value="Delete Product" />-->
                                    </rich:column>
                                </rich:dataTable></td>
                            </tr>
                        </tbody>
                    </table>
                </rich:column>
            </rich:subTable>
            <f:facet name="footer">
                <h:panelGrid columns="1" styleClass="applicantProductListFooter">
                    <h:outputText value="#{msgs.no_results}" rendered="#{(empty applicantProductListBean.dataModel) || (applicantProductListBean.dataModel.rowCount==0)}"/>

                    <rich:datascroller align="center" for="compositeTable"
                        page="#{pageScrollerBean.applicantProductListPage}"
                        id="compositeScroller" reRender="compositeTable"
                        renderIfSinglePage="false" fastControls="hide">
                        <f:facet name="first">
                            <h:outputText value="#{msgs.first}" styleClass="scrollerCell" />
                        </f:facet>
                        <f:facet name="first_disabled">
                            <h:outputText value="#{msgs.first}" styleClass="scrollerCell" />
                        </f:facet>
                        <f:facet name="last">
                            <h:outputText value="#{msgs.last}" styleClass="scrollerCell" />
                        </f:facet>
                        <f:facet name="last_disabled">
                            <h:outputText value="#{msgs.last}" styleClass="scrollerCell" />
                        </f:facet>
                        <f:facet name="next">
                            <h:outputText value="#{msgs.next}" styleClass="scrollerCell" />
                        </f:facet>
                        <f:facet name="next_disabled">
                            <h:outputText value="#{msgs.next}" styleClass="scrollerCell" />
                        </f:facet>
                        <f:facet name="previous">
                            <h:outputText value="#{msgs.previous}" styleClass="scrollerCell" />
                        </f:facet>
                        <f:facet name="previous_disabled">
                            <h:outputText value="#{msgs.previous}" styleClass="scrollerCell" />
                        </f:facet>
                    </rich:datascroller>
                </h:panelGrid>

            </f:facet>
        </rich:dataTable>



    </h:form>
</ui:define>

This is the backing bean: 这是支持bean:

@Name("applicantProductListBean")
@Scope(ScopeType.PAGE)
public class ApplicantProductListBean extends
    BasePagedSortableFilterableListBean {

/**
 * Public field for ad-hoc injection to work.
 */
@EJB(name = "FacadeService")
public ApplicantFacadeService applicantFacadeService;
@Logger
private static Log logger;
private final int pageSize = 10;
@Out(scope = ScopeType.CONVERSATION, required = false)
Applicant currentApplicant;
@Out(scope = ScopeType.CONVERSATION, required = false)
Product product;

@Create
public void onCreate() {
    System.out.println("Create");
}

@Override
protected DataModel initDataModel(int pageSize) {

    // get filtering and sorting from session
    sorting = getSorting();
    filtering = getFiltering();
    // System.out.println("Initializing a Composite3DataModel");
    // System.out.println("Pagesize: " + pageSize);
    // System.out.println("Filtering: " + filtering.getFilteringValues());
    // System.out.println("Sorting: " + sorting.getSortingValues());
    return new Composite3DataModel(1, sorting, filtering);
}

// Navigation methods
/**
 * Navigation-returning method, returns the action to follow after pressing
 * the "Create Applicant" button
 * 
 * @return the action to be taken
 */
public Navigation.ApplicantProductList showCreateApplicant() {

    return Navigation.ApplicantProductList.SHOW_CREATE_APPLICANT;
}

/**
 * Navigation-returning method, returns the action to follow after pressing
 * the "Edit Applicant" button
 * 
 * @return the action to be taken
 */
public Navigation.ApplicantProductList showUpdateApplicant(
        Applicant applicant) {
    this.currentApplicant = applicant;
    return Navigation.ApplicantProductList.SHOW_UPDATE_APPLICANT;
}

/**
 * Navigation-returning method, returns the action to follow after pressing
 * the "Delete Applicant" button
 * 
 * @return the action to be taken
 */
public Navigation.ApplicantProductList showDeleteApplicant(
        Applicant applicant) {
    this.currentApplicant = applicant;
    return Navigation.ApplicantProductList.SHOW_DELETE_APPLICANT;
}

/**
 * Navigation-returning method, returns the action to follow after pressing
 * the "Create Product" button
 * 
 * @return the action to be taken
 */
public Navigation.ApplicantProductList showCreateProduct(Applicant app) {

    this.product = new Product();
    this.product.setApplicant(app);
    return Navigation.ApplicantProductList.SHOW_CREATE_PRODUCT;
}

/**
 * Navigation-returning method, returns the action to follow after pressing
 * the "Edit Product" button
 * 
 * @return the action to be taken
 */
public Navigation.ApplicantProductList showUpdateProduct(Product prod) {
    this.product = prod;
    return Navigation.ApplicantProductList.SHOW_UPDATE_PRODUCT;
}

/**
 * Navigation-returning method, returns the action to follow after pressing
 * the "Delete Product" button
 * 
 * @return the action to be taken
 */
public Navigation.ApplicantProductList showDeleteProduct(Product prod) {
    this.product = prod;
    return Navigation.ApplicantProductList.SHOW_DELETE_PRODUCT;
}

/**
 * */
@Override
public Sorting getSorting() {

    if (sorting == null) {
        return (getSortingFilteringBeanFromSession()
                .getApplicantProductListSorting());
    }
    return sorting;
}

/**
 * 
 */
@Override
public void setSorting(Sorting sorting) {

    getSortingFilteringBeanFromSession().setApplicantProductListSorting(
            sorting);
}

/**
 * 
 */
@Override
public Filtering getFiltering() {

    if (filtering == null) {
        return (getSortingFilteringBeanFromSession()
                .getApplicantProductListFiltering());
    }
    return filtering;
}

/**
 * 
 */
@Override
public void setFiltering(Filtering filtering) {

    getSortingFilteringBeanFromSession().setApplicantProductListFiltering(
            filtering);
}

/**
 * @return the currentApplicant
 */
public Applicant getCurrentApplicant() {
    return currentApplicant;
}

/**
 * @param currentApplicant
 *            the currentApplicant to set
 */
public void setCurrentApplicant(Applicant applicant) {
    this.currentApplicant = applicant;
}

/**
 * The model for this page
 * 
 */
private class Composite3DataModel extends
        PagedSortableFilterableDataModel<List<Applicant>> {

    public Composite3DataModel(int pageSize, Sorting sorting,
            Filtering filtering) {

        super(pageSize, sorting, filtering);
    }

    @Override
    protected DataPage<List<Applicant>> fetchPage(int fakeStartRow,
            int fakePageSize) {

//          if (logger.isTraceEnabled()) {
            System.out.println("Getting page with fakeStartRow: " + fakeStartRow
                    + " and fakePageSize " + fakePageSize);
//          }
        // to find the page size multiply the startRow and the fakePageSize
        // (which is 1) to the actual page size
        int startRow = fakeStartRow
                * ApplicantProductListBean.this.pageSize;
        int pageSize = fakePageSize
                * ApplicantProductListBean.this.pageSize;
//          if (logger.isTraceEnabled()) {
            System.out.println("Getting page with startRow: " + startRow
                    + " and pageSize " + pageSize);
//          }
        List<Applicant> pageApplicants = applicantFacadeService
                .findPagedWithCriteria(startRow, pageSize, filtering,
                        sorting);
        // List<Applicant> pageApplicants = applicantFacadeService
        // .findPagedWithDynamicQuery(startRow, pageSize, filtering,
        // sorting, true);
//          if (logger.isTraceEnabled()) {
            System.out.println("Set of applicants: " + pageApplicants.size());
//          }
        List<List<Applicant>> pageApplicantsListContainer = new ArrayList<List<Applicant>>();
        pageApplicantsListContainer.add(pageApplicants);
        DataPage<List<Applicant>> dataPage = new DataPage<List<Applicant>>(
                this.getRowCount(), fakeStartRow,
                pageApplicantsListContainer);
        return dataPage;
    }

    @Override
    protected int getDatasetSize() {

        // int size = getServiceFacade().countWithCriteria(filtering,
        // sorting);
        // int size =
        // applicantFacadeService.countWithDynamicQuery(filtering, sorting,
        // false);
        int size = (int) Math.ceil((double) applicantFacadeService
                .countWithCriteria(filtering, sorting, false)
                / pageSize);
        if (logger.isTraceEnabled()) {
            logger.trace("Got Dataset Size: " + size);
        }
        return size;
    }
}

/**
 * @return the product
 */
public Product getProduct() {
    return product;
}

/**
 * @param product
 *            the product to set
 */
public void setProduct(Product product) {
    this.product = product;
}
}

And this is the page file (Notice that as long as I don't leave the page no conversation is created): 这是页面文件(请注意,只要我不离开页面,就不会创建对话):

<?xml version="1.0" encoding="UTF-8"?>
<page>
<navigation>
    <rule if-outcome="Back">
        <redirect view-id="/index.xhtml" />
    </rule>
    <rule if-outcome="SHOW_CREATE_PRODUCT">
        <begin-conversation join="true" />
        <redirect view-id="/pages/product/createProduct.xhtml" />
    </rule>
    <rule if-outcome="SHOW_UPDATE_PRODUCT">
        <begin-conversation join="true" />
        <redirect view-id="/pages/product/editProduct.xhtml" />
    </rule>
    <rule if-outcome="SHOW_DELETE_PRODUCT">
        <begin-conversation join="true" />
        <redirect view-id="/pages/product/deleteProduct.xhtml" />
    </rule>
    <rule if-outcome="SHOW_CREATE_APPLICANT">
        <begin-conversation join="true" />
        <redirect view-id="/pages/applicant/createApplicant.xhtml" />
    </rule>
    <rule if-outcome="SHOW_UPDATE_APPLICANT">
        <begin-conversation join="true" />
        <redirect view-id="/pages/applicant/editApplicant.xhtml" />
    </rule>
    <rule if-outcome="SHOW_DELETE_APPLICANT">
        <begin-conversation join="true" />
        <redirect view-id="/pages/applicant/deleteApplicant.xhtml" />
    </rule>
</navigation>
</page>

UPDATE II: 更新二:

the stacktrace is here 堆栈跟踪在这里

Well, Let's see 好吧,走着瞧

The first time gate into the page, I get this appended in my URL: ?conversationId=97 第一次进入页面时,我将此附加到我的URL中: ?conversationId = 97

ok. 好。 As said by Seam in Action book 正如Seam in Action书中所说

Seam, by default, creates a Temporary conversation to serve the current request. 默认情况下,Seam创建一个临时对话来满足当前请求。 A Temporary conversation is initialized immediately following restore view phase of the JSF life cycle and is destroyed after the render response phase. 临时对话在JSF生命周期的还原视图阶段之后立即初始化 ,并在呈现响应阶段之后被销毁

And

After a minute or two, and at seamingly random time, I get an exception saying that there is no context. 一两分钟之后,而且在随机的时间,我得到一个例外,说没有上下文。

Each conversation can have its own Timeout period, which defaults to the global Timeout setting 每个对话可以有自己的超时时间, 默认为全局超时设置

/WEB-INF/components.xml

<core:manager conversation-timeout="1000000"/>

Or page-specific 或特定于页面

<page view-id="/app.xhtml" timeout="1000000"/>

Its value is specified in milliseconds . 其值以毫秒为单位指定 But it must exceed session Timeout defined in web.xml 但是它必须超过 web.xml中定义的会话超时

/WEB-INF/web.xml

<!--specified in minutes-->
<session-config>
    <session-timeout>30</session-timeout>
</session-config>

Maybe it explains why you get your exception. 也许它解释了为什么您会得到例外。

But if you really want to know whether you have long-running conversation, Seam stores a built-in conversation-scoped component named conversation . 但是,如果您真的想知道您是否有长期运行的对话,那么Seam会存储一个内置的对话范围的组件,名为session So inside your Managed bean , do as follows to know whether you have a long-running conversation 因此, 在您的Managed bean中 ,执行以下操作以了解您是否进行了长时间的对话

org.jboss.seam.core.Conversation conversation = (Conversation) Component.getInstance("conversation");

System.out.println(conversation.isLongRunning());

If you see true , someway you have started a long-running conversation. 如果您看到true ,那么您已经开始了长时间的对话。 You can even see inside your page 您甚至可以在页面内看到

#{conversation.longRunning}

I hope it can be useful to you. 希望对您有用。

Try making the component scoped conversation instead of page. 尝试进行组件范围的对话而不是页面。 It sounds like what you want to do is larger than page scoped, which holds the context for only a single request. 听起来您想要做的事情比页面作用域要大,页面作用域仅包含单个请求的上下文。

I'm not sure why you got that conversationId parameter appended to your url. 我不知道为什么将对话ID参数附加到网址中。 However, all communication in seam happens inside of a conversation. 但是,所有接缝中的通信都发生在对话内部。 If its page scoped, the conversation is a temporary conversation. 如果其页面范围限定,则该对话为临时对话。 To promote the conversation to a long running conversation, you need to a begin annotation or to start the conversation in pages.xml. 要将对话提升为长期对话,您需要在pages.xml中添加开始注释或开始对话。

I think the seamBooking example application has some sample code that should be similar to what you are trying to do. 我认为seamBooking示例应用程序具有一些示例代码,这些代码应与您尝试执行的代码相似。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM