【问题标题】:can't call methods from SEAM Component无法从 SEAM Component 调用方法
【发布时间】:2012-01-22 04:38:36
【问题描述】:

我有一个 SEAM 2 应用程序,但我遇到了一个奇怪的情况。我正在使用 Eclipse Indigo 进行开发,我需要创建一个带有网格的页面,其中每一行都有一个按钮,该按钮显示一个带有列表的弹出窗口,您可以选择带有链接的列表中的一项,并显示所选值在行中。

所以我有这个组件:

@Name("paramContHome")
@Scope(ScopeType.CONVERSATION)
public class ParamContHome extends KubeDAO<ParametroSistema>{

    private static final long serialVersionUID = 1L;

    @In
    private LoginUser loginUser;

    @In(required=false,create=true)
    private CuentaContHome cuentaContHome;

    public void load(){
        try{
            setInstance(getEntityManager().find(ParametroSistema.class, prctId));
        }catch (Exception e) {
            clearInstance();
            setInstance(new ParametroSistema());
        }
    }

    public void selCuentaParam(ParametroSistema par) {
        setSelParam(par);
        cuentaContHome.getCuentasList();
    }

    public void setCuentaParam(CuentaContable cta) {
        selParam.setValorNum(cta.getId().floatValue());
        selParam.setSelObj(cta);
    }

    ...

    }

这包含我试图从 xhtml 页面调用的方法。这是xhtml页面:

<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE composition 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:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:p="http://primefaces.prime.com.tr/ui"
    template="/layout/templateKu.xhtml">
    <ui:define name="body">
        <rich:panel>
            <f:facet name="header">#{app.paramact_head}</f:facet>
            <rich:spacer height="20" />
            <h:form id="formA">
                <p:growl globalOnly="true" sticky="false" life="3000" />
                <p:focus />
                <a:queue name="q1" />

                <rich:dataTable var="res" value="#{paramContHome.resultList}"
                    rendered="#{not empty paramContHome.resultList}" rows="10"
                    align="center" rowClasses="tableInfo1 tableInfo2"
                    headerClass="tablaHeader" footerClass="tableScroll">
                    <f:facet name="header">#{app.paramact_list}</f:facet>

                    <rich:column filterBy="#{res.nombre}" filterEvent="onkeyup">
                        <f:facet name="header">#{app.paramact_nombre}</f:facet>
                        <h:outputText value="#{res.nombre}" />
                    </rich:column>
                    <rich:column>
                        <f:facet name="header">#{app.transferencia_valornum}</f:facet>
                        <h:inputText value="#{res.selObj.nombre}" size="20" >
                            <a:support event="onblur" ajaxSingle="true" eventsQueue="q1" reRender="_table"/>
                        </h:inputText>
                        <a:commandButton ajaxSingle="true"   
                            action="#{paramContHome.selCuentaParam(res)}" reRender="sCta" 
                            onclick="#{rich:component('selCta')}.show();"
                            styleClass="modifyBtn" value=" " style="width:30px;">
                        </a:commandButton>
                    </rich:column>
                    <f:facet name="footer">
                        <rich:datascroller id="ds1" renderIfSinglePage="true" />
                    </f:facet>
                </rich:dataTable>
            </h:form>
        </rich:panel>
        <rich:modalPanel id="selCta" width="400" moveable="false" autosized="true" top="50px" 
            onbeforeshow="activeModal.setActiveModalPanel('selCta');">
            <f:facet name="header">#{app.general_lov}</f:facet>
            <f:facet name="controls">
                <h:panelGroup>
                    <h:graphicImage value="/kubeImg/close.png" styleClass="closeBtn" 
                        onclick="#{rich:component('selCta')}.hide();" />
                </h:panelGroup>
            </f:facet>
            <s:div id="sCta"><ui:include  src="selCta.xhtml" /></s:div>
        </rich:modalPanel>
    </ui:define>
</ui:composition>

这是我要调用组件 paramContHome 的方法 selCuentaParam 的按钮:

<rich:column>
    <f:facet name="header">#{app.transferencia_valornum}</f:facet>
    <h:inputText value="#{res.selObj.nombre}" size="20" >
        <a:support event="onblur" ajaxSingle="true" eventsQueue="q1" reRender="_table"/>
    </h:inputText>
    <a:commandButton ajaxSingle="true"   
        action="#{paramContHome.selCuentaParam(res)}" reRender="sCta" 
        onclick="#{rich:component('selCta')}.show();"
        styleClass="modifyBtn" value=" " style="width:30px;">
    </a:commandButton>
</rich:column>

在这个方法中,我从另一个组件 cuentaContHome 调用一个方法:

@In(required=false,create=true)
private CuentaContHome cuentaContHome;
...
public void selCuentaParam(ParametroSistema par) {
setSelParam(par);
cuentaContHome.getCuentasList();
}

但是当我运行应用程序并进入页面并按下按钮时,它不会调用方法 selCuentaParam。我已经检查过了,因为我在其中放置了断点并放置了 System.out.println 并且没有调用它。你知道为什么会这样吗,是不是和组件初始化有关?

问候。

【问题讨论】:

  • 这似乎不是组件初始化问题(否则你会得到 NullPointerExceptions)。当你按下按钮时会发生什么?是否显示任何错误页面,或控制台中的某些内容?
  • 不,没有任何反应。在输出中我得到这个:19:53:39,911 WARN [Component] Cannot create Seam component, scope is not active: entityManager(CONVERSATION) 但这是正常的,我在应用程序的其他屏幕或目录中得到这个,我没有问题。
  • 你试过启用Seam的debug mode吗?应用服务器的日志呢?如果没有更多信息,很难弄清楚发生了什么。请在此处发布您可以提出的任何进一步的调试信息。
  • ` 05:38:07,386 WARN [Component] 无法创建 Seam 组件,范围未激活:entityManager(CONVERSATION) 05:38:12,150 WARN [Component] 无法创建 Seam 组件,范围未激活:entityManager(CONVERSATION)05:39:26,245 WARN [Component]无法创建Seam组件,范围未激活:entityManager(CONVERSATION)05:39:47,306 WARN [Component]无法创建Seam组件,范围未激活:entityManager(CONVERSATION ) 05:39:47,421 WARN [Component] 无法创建 Seam 组件,范围未激活:entityManager(CONVERSATION)`

标签: methods components seam call seam2


【解决方案1】:

好吧,我想我找到了问题所在。在我的屏幕中,我遵循某种模式:首先,我有一个 xhtml,在其中我显示了一个数据库记录网格,其中有一个按钮可以转到第二个 xhtml,它有一个创建新记录的表单。此按钮开始对话,因此在具有表单(我称之为 detail.xhtml)的 xhtml 中,它开始对话或加入现有的对话。所以,我修改了第一个xhtml的pages.xml(我叫它list.xhtml)用下一种方式:

<?xml version="1.0" encoding="UTF-8"?>
<page xmlns="http://jboss.com/products/seam/pages"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd">
 <action execute="#{paramContHome.getParametrosContables()}" on-postback="false"/>

       <begin-conversation propagation="begin" join="true" />

</page>

我最初只使用了&lt;begin-conversation /&gt;,但它给了我这个例外begin() called from long-running conversation, try join=true,所以我将它添加到开始对话中并且它有效!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-20
    • 1970-01-01
    • 1970-01-01
    • 2019-06-16
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    相关资源
    最近更新 更多