p:selectOneMenu 有问题吗?
以下代码适用于 h:selectOneMenu
,但不适用于 p:selectOneMenu
p:selectOneMenu
中没有项目
Facelet
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<h:selectOneMenu value="#{testBean.name}">
<f:selectItems value="#{testBean.names}"/>
</h:selectOneMenu>
<p:selectOneMenu value="#{testBean.name}">
<f:selectItems value="#{testBean.names}"/>
</p:selectOneMenu>
</h:form>
</h:body>
</html>
Bean
package net.footfeed.beans;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class TestBean {
private String name = "name1";
private String[] names = new String[] {"name1", "name2", "name2"};
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String[] getNames() {
return names;
}
}
The following code works fine for h:selectOneMenu
but doesn't work for p:selectOneMenu
There is no item in p:selectOneMenu
Facelet
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<h:selectOneMenu value="#{testBean.name}">
<f:selectItems value="#{testBean.names}"/>
</h:selectOneMenu>
<p:selectOneMenu value="#{testBean.name}">
<f:selectItems value="#{testBean.names}"/>
</p:selectOneMenu>
</h:form>
</h:body>
</html>
Bean
package net.footfeed.beans;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class TestBean {
private String name = "name1";
private String[] names = new String[] {"name1", "name2", "name2"};
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String[] getNames() {
return names;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
奇怪的是,它不支持
上的List
或T[]
。您需要创建一个List
或SelectItem[]
,或者更好的是显式指定var
属性。这仅适用于List
。由于
这没有意义,我建议将此问题报告给他们的问题跟踪器。
更奇怪的是,当我省略
itemLabel
(它应该只将itemValue
显示为标签)时,它会在 Tomcat 上抛出一个非常严重的 NPE:PrimeFaces 3.0 显然仍处于测试阶段阶段。
Curious, it doesn't support a
List<T>
orT[]
on<f:selectItems>
. You'd need to to create aList<SelectItem>
orSelectItem[]
or, better, to explicitly specify thevar
attribute. This works withList<T>
only.with
Since this makes no sense, I'd suggest to report this issue to their issue tracker.
More curious, when I omit the
itemLabel
(which should then just display theitemValue
as label), it throws a pretty serious NPE on Tomcat:PrimeFaces 3.0 is clearly still in beta stage.