我试图将接缝组件注入另一个组件,然后自动创建它。但是由于某种原因,注入的接缝组件会抛出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;
    }


}

最佳答案

Seam将扫描基本软件包并查找@Name组件,然后这些组件可以自动连线。我应该将seam.properties文件(空)放入seam中,以了解要扫描的基本软件包。我正在dint上工作的模块具有seam.properties,因此未对RulesValidator进行扫描并将其视为接缝组件。因此,autoCreate dint工作。

09-05 12:41