Jsf selectOneMenu中的空bean
因此,在我的用户配置文件页面中有一个SelectOne菜单。它的目标值是“我的用户配置文件”表中的一个字段。该字段是另一个表的外键。最初该值为空,因为用户尚未设置其信息 “选择一个”菜单如下所示:Jsf selectOneMenu中的空bean,jsf,managed-bean,Jsf,Managed Bean,因此,在我的用户配置文件页面中有一个SelectOne菜单。它的目标值是“我的用户配置文件”表中的一个字段。该字段是另一个表的外键。最初该值为空,因为用户尚未设置其信息 “选择一个”菜单如下所示: <p:selectOneMenu value="#{userProfileEdit.uinfo.datBean}" > <!-- This Value is null initially --> <f:selectItem itemLabel="Select O
<p:selectOneMenu value="#{userProfileEdit.uinfo.datBean}" > <!-- This Value is null initially -->
<f:selectItem itemLabel="Select One" itemValue="#{null}" />
<f:selectItems value="#{datBeanConverter.beansList}" var="bean" itemLabel="#{bean.title}" itemValue="#{bean}"/>
</p:selectOneMenu>
如果可以的话,我该怎么做
编辑:我的uinfo属性bean在userProfileEdit中初始化,如下所示
@ManagedBean
@RequestScoped
public class UserProfileEdit implements Serializable {
private Userinfo uinfo;
@EJB
private UserProfileService us;
//...
@PostConstruct
public void init() {
setUser();
this.uinfo = us.getUserInfo(username);
}
//...
}
您可以在bean的postconstruct方法中初始化它
@PostConstruct
public void init() {
...
UserInfo uinfo= new UserInfo();
//you will need to initialize the property datBean of UserInfo in the Constructor.
...
}
其他信息:
希望这有帮助。定义新的datBean变量,并将其放入如下值属性中
<p:selectOneMenu value="#{userProfileEdit.datBean}" > <!-- This Value is null initially -->
<f:selectItem itemLabel="Select One" itemValue="#{null}" />
<f:selectItems value="#{datBeanConverter.beansList}" var="bean" itemLabel="#{bean.title}" itemValue="#{bean}"/>
</p:selectOneMenu>
然后在提交表单之后,您可以创建uinfo对象并使用datBean对象 JSF的哪个版本?如果这个问题有助于解决您的问题,请接受这个问题,因为其他有相同问题的用户会很感激这个问题。是的,我会的,我离开了2个小时。我现在检查一下。太好了,请不要犹豫询问任何澄清。我确实需要澄清。我的uinfobean已经实例化了(我在我的主要帖子中添加了代码)。所以我不确定我是否理解错了你说的话。我不确定你的第二个答案是什么意思(我的bean已经被实例化了)。然而第一个是有效的,虽然我不得不改变一些东西,所以我要编辑你的评论,我希望你不介意。我仍然不明白为什么这样做有效,而不是我的原始代码。我继续删除了第二个解决方案(如果我的部分不正确的话,很抱歉)。我以为你误解了我最初的问题。如果我删除你的答案是错误的,我可能会错,很抱歉。问题是uinfo为null,因此解决方案是初始化此对象或替换,构造函数后调用@PostConstruct方法,因此在这里初始化。或者使用第一个解决方案UInfo不为空!!!你的答案不正确这就是我编辑它的原因。再看一次我的帖子。哦,对不起,昨晚很不愉快。干杯
<p:selectOneMenu value="#{userProfileEdit.datBean}" > <!-- This Value is null initially -->
<f:selectItem itemLabel="Select One" itemValue="#{null}" />
<f:selectItems value="#{datBeanConverter.beansList}" var="bean" itemLabel="#{bean.title}" itemValue="#{bean}"/>
</p:selectOneMenu>