我尝试从primefaces.org运行一个例子, 这个 http://www.primefaces.org/showcase/ui/multiSelectListbox.jsf
但结果是
这是我的代码 XHTML:
<h:body>
<h:form>
<p:multiSelectListbox value="#{multiSelectListboxBean.selection}" effect="slide">
<f:selectItems value="#{multiSelectListboxBean.categories}" />
</p:multiSelectListbox>
<p:commandButton value="Save" icon="ui-icon-check" update="out" style="margin:10px 0"/>
<h:outputText id="out" value="Value: #{multiSelectListboxBean.selection}" style="display:block"/>
</h:form>
ManagedBean代码:
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.model.SelectItem;
import javax.faces.model.SelectItemGroup;
@ManagedBean(name="multiSelectListboxBean")
@RequestScoped
public class AddPacchettiBean {
private List<SelectItem> categories;
private String selection;
@PostConstruct
public void init() {
categories = new ArrayList<SelectItem>();
SelectItemGroup group1 = new SelectItemGroup("Group 1");
SelectItemGroup group2 = new SelectItemGroup("Group 2");
SelectItemGroup group3 = new SelectItemGroup("Group 3");
SelectItemGroup group4 = new SelectItemGroup("Group 4");
SelectItemGroup group11 = new SelectItemGroup("Group 1.1");
SelectItemGroup group12 = new SelectItemGroup("Group 1.2");
SelectItemGroup group21 = new SelectItemGroup("Group 2.1");
SelectItem option31 = new SelectItem("Option 3.1", "Option 3.1");
SelectItem option32 = new SelectItem("Option 3.2", "Option 3.2");
SelectItem option33 = new SelectItem("Option 3.3", "Option 3.3");
SelectItem option34 = new SelectItem("Option 3.4", "Option 3.4");
SelectItem option41 = new SelectItem("Option 4.1", "Option 4.1");
SelectItem option111 = new SelectItem("Option 1.1.1");
SelectItem option112 = new SelectItem("Option 1.1.2");
group11.setSelectItems(new SelectItem[]{option111, option112});
SelectItem option121 = new SelectItem("Option 1.2.1", "Option 1.2.1");
SelectItem option122 = new SelectItem("Option 1.2.2", "Option 1.2.2");
SelectItem option123 = new SelectItem("Option 1.2.3", "Option 1.2.3");
group12.setSelectItems(new SelectItem[]{option121, option122, option123});
SelectItem option211 = new SelectItem("Option 2.1.1", "Option 2.1.1");
group21.setSelectItems(new SelectItem[]{option211});
group1.setSelectItems(new SelectItem[]{group11, group12});
group2.setSelectItems(new SelectItem[]{group21});
group3.setSelectItems(new SelectItem[]{option31, option32, option33, option34});
group4.setSelectItems(new SelectItem[]{option41});
categories.add(group1);
categories.add(group2);
categories.add(group3);
categories.add(group4);
}
public List<SelectItem> getCategories() {
return categories;
}
public String getSelection() {
return selection;
}
public void setSelection(String selection) {
this.selection = selection;
}
}
我不明白,为什么!!!!
答案 0 :(得分:0)
您的Primefaces装置上似乎缺少一些东西
xmlns:p="http://primefaces.org/ui"
)