SelectOneMenu:空指针异常
我正在尝试填充 primefaces 的 SelectOneMenu,但应用程序遇到 NullPointerException,我不知道问题出在哪里。 这是我的 SelectOneMenu 代码:
<h:outputText value="Domaine : " styleClass="champ"/>
<p:selectOneMenu value="#{projet.currentProjet.typeProjets}" >
<f:selectItem itemLabel="Domaine" itemValue="" />
<f:selectItems value="#{projet.inittprojet()}" var="typeprojet" itemValue="#{typeprojet}" itemLabel="#{typeprojet.designation}" />
</p:selectOneMenu>
这是我的支持 bean:
@Component("projetsBean")
@Scope("session") <br>
public class ProjetsBean implements Serializable{ <br>
private transient ProjetsService projetsService;
////////////////////////////////////////////////////////// setters & getters \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
public void setProjetsService(ProjetsService projetsService)
{
this.projetsService=projetsService;
}
public ProjetsService getProjetsService()
{
return projetsService;
}
////////////////////////////////////////////////////////// Méthodes \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
@PostConstruct
public List inittprojet() {
return projetsService.getAllProjets();
}
}
问候
i'm trying to populate a primefaces's SelectOneMenu but the application hits a NullPointerException, i don't know where is the problem.
here is my SelectOneMenu code:
<h:outputText value="Domaine : " styleClass="champ"/>
<p:selectOneMenu value="#{projet.currentProjet.typeProjets}" >
<f:selectItem itemLabel="Domaine" itemValue="" />
<f:selectItems value="#{projet.inittprojet()}" var="typeprojet" itemValue="#{typeprojet}" itemLabel="#{typeprojet.designation}" />
</p:selectOneMenu>
here is my backing bean:
@Component("projetsBean")
@Scope("session") <br>
public class ProjetsBean implements Serializable{ <br>
private transient ProjetsService projetsService;
////////////////////////////////////////////////////////// setters & getters \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
public void setProjetsService(ProjetsService projetsService)
{
this.projetsService=projetsService;
}
public ProjetsService getProjetsService()
{
return projetsService;
}
////////////////////////////////////////////////////////// Méthodes \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
@PostConstruct
public List inittprojet()
{
return projetsService.getAllProjets();
}
}
regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您没有显示堆栈跟踪或至少没有显示 NPE 发生的行,所以我只能猜测,但有一件事似乎很可疑。
您应该这样在 SelectOneMenu 中使用不可选择的选项:
如果省略
noSelectionOption="true"
,则可能会发生 NPE,因为 jsf 将其视为可选择的选项。Since you didn't show the stacktrace or at least the line where the NPE happens, I can only guess, but one thing seems suspicious.
You should use a non-selectable option in SelectOneMenu this way:
If you omit the
noSelectionOption="true"
, a NPE can occur because jsf treats it as selectable option.