我使用<p:selectCheckboxMenu>上List<Long>:
<p:selectCheckboxMenu value="#{bean.selectedItems}">
<f:selectItems value="#{bean.availableItems}" />
</p:selectCheckboxMenu>
Run Code Online (Sandbox Code Playgroud)
private List<Long> selectedItems;
private Map<String, Long> availableItems;
Run Code Online (Sandbox Code Playgroud)
提交表单并循环显示所选项目时,如下所示,
for (int i = 0; i < selectedItems.size(); i++) {
Long id = selectedItems.get(i);
// ...
}
Run Code Online (Sandbox Code Playgroud)
然后我得到一个类强制转换异常:
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long
at com.example.Bean.submit(Bean.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
... 27 more
Run Code Online (Sandbox Code Playgroud)
与出现同样的问题<p:selectManyCheckbox>,<p:selectManyMenu>,<h:selectManyMenu>等所有多选组件基本.它在<p:selectOneMenu>单个值Long属性上和所有其他单选组件中都可以正常工作.
这是怎么造成的,我该如何解决?
PrimeFacesp:selectBooleanCheckbox可以p:selectBooleanButton链接到boolean控制器中的原始数据类型变量。
我想要一个可以链接到参考数据类型的控制器Boolean。它必须能够显示null、true和false值。
可以p:triStateCheckbox链接到String变量,但不能链接到Boolean值。
是否有任何 JSF / PrimeFaces UI 组件可以表示BooleanJava 控制器中的引用数据类型?
我正在使用Jsf 2.0和Primefaces 3.2实现一个webapp.我注意到了这种意想不到的行为:我有一个selectOneMenu和一个commandButton,如下所示
<p:selectOneMenu id="selsel" value="#{bean.myObj}">
<f:selectItems value="#{bean.myObjList}" />
</p:selectOneMenu>
<p:commandButton id="btnid" value="Ok" actionListener="#{bean.updateSelectValues()}" />
Run Code Online (Sandbox Code Playgroud)
会发生的是,如果myObj不是a String,updateSelectValues则不调用该方法.我根本看不到任何异常或错误,它只是没有被调用.这是支持bean:
private List<MyObj> myObjList;
private MyObj myObj;
// getters and setters
public void updateSelectValues() {
System.out.println(this.myObj);
}
Run Code Online (Sandbox Code Playgroud)
myObj的代码:
public class MyObj implements Serializable {
private static final long serialVersionUID = 1L;
private String param1;
private int param2;
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("MyObj [param1=");
builder.append(this.param1);
builder.append(", param2=");
builder.append(this.param2);
builder.append("]");
return …Run Code Online (Sandbox Code Playgroud) 我正在使用JSF 2.0创建Web应用程序,我将分配用户来查看项目.为此我有两个清单.具有未分配该项目的用户的第一个列表和列表B具有已分配该项目的用户.我们可以交换数据.
我的代码是
<t:selectManyListbox id="sourceCars" style="width: 40%;"
value="#{PersonalInformationDataBean.listOfUsers}" size="10">
<t:selectItems value="#{PersonalInformationDataBean.showAllMyRemData()}" var="t"
itemLabel="#{t.title}" itemValue="#{t.status}"/>
</t:selectManyListbox>
<span>
<input type="button" value=" >> " id="dbleMeRight"/>
<input type="button" value=" << " id="dbleMeLeft"/>
</span>
<t:selectManyListbox id="targetCars" style="width: 40%;"
value="#{PersonalInformationDataBean.listOfUsers}" size="10">
<t:selectItems value="#{PersonalInformationDataBean.showAllMyData()}" var="n"
itemLabel="#{n.title}" itemValue="#{n.status}"/>
</t:selectManyListbox>
<h:commandButton value="Save Edited Project Info." action="#{PersonalInformationDataBean.editPatentData(MyLogin.loginname)}" />
Run Code Online (Sandbox Code Playgroud)
其中t是xmlns:t="http://myfaces.apache.org/tomahawk".
PersonalInformationDataBean.java
private List<String> listOfUsers = new ArrayList<String>();
private List<String> listOfUsers002 = new ArrayList<String>();
private List<CommonBean01> listOfListUsers = new ArrayList<CommonBean01>();
private List<CommonBean01> listOfListUsers002 = new ArrayList<CommonBean01>();
// above getter and …Run Code Online (Sandbox Code Playgroud)