JBoss Seam - @In 注释不能与不同属性的访问器方法同时使用吗?

发布于 2024-08-03 12:50:42 字数 3633 浏览 7 评论 0原文

我使用 Sean-gen (seam new-form) 生成了一个新表单,并使用 @In 注释向其中添加了另一个字段:

@Stateful
@Name("dummy")
public class DummyBean implements Dummy
{
    @Logger private Log log;

    @In StatusMessages statusMessages;

    @In private String bar;

    private String foo;

    public void doStuff()
    {
        String msg = "dummy.doStuff() action called with foo: #{dummy.foo} and bar: #{bar}. instance variable for bar:" + bar;
        log.info(msg);
        statusMessages.add(msg);
    }

    @Length(max = 10)
    public String getFoo()
    {
        return foo;
    }

    public void setFoo(String value)
    {
        this.foo = value;
    }

    @Remove
    public void destroy() {}

}

接口是这个:

@Local
public interface Dummy
{
    public void doStuff();
    public String getFoo();
    public void setFoo(String value);
    public void destroy();
}

问题是,当我尝试访问我得到的属性时:

javax.faces.FacesException: javax.el.ELException: /dummy.xhtml @22,52 value="#{dummy.foo}": Error reading 'foo' on type org.javassist.tmp.java.lang.Object_$$_javassist_seam_2
    at javax.faces.component.UIOutput.getValue(UIOutput.java:187)
    at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:201)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:284)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:154)
.
.
.
Caused by: javax.ejb.EJBTransactionRolledbackException: @In attribute requires non-null value: dummy.bar
    at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:115)
    at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)

我的视图是这是:

<!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:rich="http://richfaces.org/rich"
    xmlns:a="http://richfaces.org/a4j"
    template="layout/template.xhtml">

<ui:define name="body">

    <h:form id="dummyForm">

        <rich:panel>
            <f:facet name="header">dummy header</f:facet>

             <s:decorate id="fooField" template="layout/edit.xhtml">
                <ui:define name="label">Foo</ui:define>
                <h:inputText id="foo" required="true"
                             value="#{dummy.foo}"/>
            </s:decorate>               

             <s:decorate id="barField" template="layout/edit.xhtml">
                <ui:define name="label">Bar</ui:define>
                <h:inputText id="bar" required="true"
                             value="#{bar}"/>
            </s:decorate>            

            <div style="clear:both"/>

        </rich:panel>

        <div class="actionButtons">
            <h:commandButton id="doStuff" value="doStuff"
                    action="#{dummy.doStuff}"/>
        </div>

    </h:form>

</ui:define>

</ui:composition>

如果我删除“fooField”或“barField”,视图将呈现并正常工作,但如果我尝试同时使用两者,则会出现上述异常。

我还注意到,如果我只使用 @In 注释(从 bean 中删除访问器方法),页面就可以工作。

这是预期的事情吗?我应该在问之前做好功课吗?

我正在使用 JBoss 5.1.0.GA、Seam 2.2.0.GA 和 Java 6。

I generated a new form using sean-gen (seam new-form) and added another field to it using an @In annotation:

@Stateful
@Name("dummy")
public class DummyBean implements Dummy
{
    @Logger private Log log;

    @In StatusMessages statusMessages;

    @In private String bar;

    private String foo;

    public void doStuff()
    {
        String msg = "dummy.doStuff() action called with foo: #{dummy.foo} and bar: #{bar}. instance variable for bar:" + bar;
        log.info(msg);
        statusMessages.add(msg);
    }

    @Length(max = 10)
    public String getFoo()
    {
        return foo;
    }

    public void setFoo(String value)
    {
        this.foo = value;
    }

    @Remove
    public void destroy() {}

}

The interface is this one:

@Local
public interface Dummy
{
    public void doStuff();
    public String getFoo();
    public void setFoo(String value);
    public void destroy();
}

The problem is, when I try to access the properties I get:

javax.faces.FacesException: javax.el.ELException: /dummy.xhtml @22,52 value="#{dummy.foo}": Error reading 'foo' on type org.javassist.tmp.java.lang.Object_$_javassist_seam_2
    at javax.faces.component.UIOutput.getValue(UIOutput.java:187)
    at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:201)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:284)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:154)
.
.
.
Caused by: javax.ejb.EJBTransactionRolledbackException: @In attribute requires non-null value: dummy.bar
    at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:115)
    at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)

My view is this:

<!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:rich="http://richfaces.org/rich"
    xmlns:a="http://richfaces.org/a4j"
    template="layout/template.xhtml">

<ui:define name="body">

    <h:form id="dummyForm">

        <rich:panel>
            <f:facet name="header">dummy header</f:facet>

             <s:decorate id="fooField" template="layout/edit.xhtml">
                <ui:define name="label">Foo</ui:define>
                <h:inputText id="foo" required="true"
                             value="#{dummy.foo}"/>
            </s:decorate>               

             <s:decorate id="barField" template="layout/edit.xhtml">
                <ui:define name="label">Bar</ui:define>
                <h:inputText id="bar" required="true"
                             value="#{bar}"/>
            </s:decorate>            

            <div style="clear:both"/>

        </rich:panel>

        <div class="actionButtons">
            <h:commandButton id="doStuff" value="doStuff"
                    action="#{dummy.doStuff}"/>
        </div>

    </h:form>

</ui:define>

</ui:composition>

If I remove either 'fooField' or 'barField' the view renders and works correctly, but if I try to use both at the same time I get the above exception.

I also noticed that if I use only @In annotations (remove the accessor methods from the bean) the page works.

Is this something expected and I should be doing my homework before asking?

I'm using JBoss 5.1.0.GA, Seam 2.2.0.GA and Java 6.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一花一树开 2024-08-10 12:50:42

事实证明这是预期的行为,引用 seam 论坛的答案:

如果您要注入的 Seam 组件在类级别没有 @AutoCreate 注释,请使用 @In(required=false)。

因此,将:更改

@In private String bar;

为:

@In (required=false) private String bar;

可以解决问题。

Turns out this is expected behavior, quoting an answer from the seam forum:

Use @In(required=false) if the Seam component you're injecting does not have the @AutoCreate annotation at the class level.

So, changing:

@In private String bar;

to:

@In (required=false) private String bar;

fixes the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文