ステートレス Bean を注入する ManagedBean がありますが、常に注入用の nullpointer が返されます。ここで何が間違っていますか?(私はJSFとその単なる例を学んでいるので、クラスの命名などは無視してください)
2 つの異なる jar (web.jar と services.jar) があります。
管理された Bean
@ManagedBean
@RequestScoped
public class HelloPB
{
@Inject
private ExamServiceBase examService;
private String name = "";
public String getName()
{
Exam exam = examService.getSingleExam();
return exam.getName();
}
public void setName(final String name)
{
//this.name = name;
}
public String getHello()
{
if ( name == null || name.length() < 1 )
{
return null;
}
return "Hello " + name;
}
}
ステートレス Bean
@Stateless
public class ExamServiceBase implements ExamService{
@PersistenceContext(name="QuestifyPersistUnit")
private EntityManager em;
public Exam getExam(String id){
return em.find(Exam.class, id);
}
public Exam getSingleExam(){
return em.find(Exam.class, "9E69F3EE-AE9E-4D53-B531-35504EDA450F");
}
}
index.xhtml
<h:body>
<h:outputScript name="jsf.js" library="javax.faces" target="body">
</h:outputScript>
<h1>JSF 2 Demo</h1>
<h:form>
<h:inputText id="name" value="#{helloPB.name}">
<f:ajax render="helloTextOutput" />
</h:inputText>
<h:commandButton value="Say Hi via Ajax">
<f:ajax execute="name" render="helloTextOutput" />
</h:commandButton>
<h:outputText id="helloTextOutput" value="#{helloPB.hello}" />
</h:form>
</h:body>