Pergunta

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;
    }


}
Foi útil?

Solução

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.

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top