Seam 自动创建不起作用?

发布于 2025-01-05 05:37:53 字数 1150 浏览 0 评论 0原文

我正在尝试将接缝组件注入另一个组件中,自动创建它。但由于某种原因,注入的接缝组件会抛出 NPE。

XHTML

                   <a4j:commandLink id="cbrModal"
                                     action="#{detailAction.showInformation(1L)}"
                                     reRender="DetailModal"
                                     limitToList="true">
                        <h:outputText value="text"/>

                    </a4j:commandLink>

DetailActionBean.java

@Name("detailAction")
public class DetailActionBean implements Serializable {

    @In(create = true, required = false)
    @Out(required = false)
    private RulesValidator rulesValidator;

   public void showInformation(long id) {

                rulesValidator.setCheckCount(0); // rulesValidator == null here and throws npe

   }
)

RulesValidator.java

@AutoCreate
@Name("rulesValidator")
@Scope(ScopeType.SESSION)
public class RulesValidator implements Serializable {

    private int checkCount = 0;
    public void setCheckCount(int checkCount) {
        this.checkCount = checkCount;
    }


}

I am trying to Inject a seam component into another, auto creating it. But for some reason the injected seam component throws NPE.

XHTML

                   <a4j:commandLink id="cbrModal"
                                     action="#{detailAction.showInformation(1L)}"
                                     reRender="DetailModal"
                                     limitToList="true">
                        <h:outputText value="text"/>

                    </a4j:commandLink>

DetailActionBean.java

@Name("detailAction")
public class DetailActionBean implements Serializable {

    @In(create = true, required = false)
    @Out(required = false)
    private RulesValidator rulesValidator;

   public void showInformation(long id) {

                rulesValidator.setCheckCount(0); // rulesValidator == null here and throws npe

   }
)

RulesValidator.java

@AutoCreate
@Name("rulesValidator")
@Scope(ScopeType.SESSION)
public class RulesValidator implements Serializable {

    private int checkCount = 0;
    public void setCheckCount(int checkCount) {
        this.checkCount = checkCount;
    }


}

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

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

发布评论

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

评论(2

荒路情人 2025-01-12 05:37:53

Seam 将扫描基础包并查找 @Name 组件,然后这些组件可以自动连接。我应该为seam放置一个seam.properties文件(空)来知道要扫描哪些基础包。我正在开发的模块有seam.properties,因此RulesValidator 没有被扫描并被视为seam 组件。因此 autoCreate 不起作用。

Seam will scan a base package and look for @Name components and then those components are auto wireable. I am supposed to put a seam.properties file (empty) for seam to know which base packages to scan. The module I was working on dint have seam.properties and so RulesValidator was not being scanned and treated as a seam component. Hence autoCreate dint work.

假情假意假温柔 2025-01-12 05:37:53

required false 正是这个意思。如果它还不存在,则不会创建它,您应该检查它。 Autocreate 只是意味着您不需要在 in 注释上定义 create true 。

更新评论:
是的,如果存在此注释,seam 将在注入时自动创建组件。但你在注射中注明不需要!这就是为什么seam什么都不做的原因。只需删除 @In 的所有属性,它就应该可以工作。默认值就是您想要的。

Required false means exactly that. If it does not exist yet it will not be created and you should check that. Autocreate just means that you dont need to define create true on the in annotation.

Update for the comments:
Yes seam will autocreate a component on injection if this annotation is presemt. But you state in the injection that it is not required! Thats why seam does nothing. Just remove all properties of your @In and it should work. The defaults are what you want.

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