我想在一个中使用枚举值<h:selectManyCheckbox>
.正确填充复选框,但是,在选择某些值并提交它们时,它们的运行时类型是String
,而不是枚举.我的代码:
<h:selectManyCheckbox value="#{userController.roles}" layout="pageDirection">
<f:selectItems value="#{userController.rolesSelectMany}" />
</h:selectManyCheckbox>
Run Code Online (Sandbox Code Playgroud)
UserController类(SecurityRole是枚举类型):
public SelectItem[] getRolesSelectMany() {
SelectItem[] items = new SelectItem[SecurityRole.values().length];
int i = 0;
for (SecurityRole role : SecurityRole.values()) {
items[i++] = new SelectItem(role, role.toString());
}
return items;
}
public List<SecurityRole> getRoles() {
getCurrent().getRoles();
}
public void setRoles(List<SecurityRole> roles) {
getCurrent().setRoles(roles);
}
Run Code Online (Sandbox Code Playgroud)
当JSF调用setRoles方法时,它包含String类型的列表,而不是枚举类型.有任何想法吗?谢谢!
我为一些统计数据开发了一个接口JEE/JSF.我创建了复选框以选择用户希望显示的引用,但问题是我用来根据数据库中的数据生成复选框Arraylist.
我不能按我的意愿定位它们.我希望在10个复选框后,其他人直接生成线等.
我有这个结果
我希望我能做到这一点
MTBFBEAN
private List<String> selectedReference = new ArrayList<String>();
private List<String> listReference = new ArrayList<String>();
private Boolean afficher = false; // Déclaration du bool pour le rendered de
// ma vue dans MTBF
@SuppressWarnings("deprecation")
public StatisticsBeanMTBF() {
this.beginDate = new Date(2001, 00, 01);
List<ProductConfModel> listtmp = this.moduleGlobal.getProductConfModels(2);
for (ProductConfModel pcm : listtmp) {
this.listReference.add(pcm.getReference());
}
}
public void mTBFByType() {
this.afficher = true;
this.listMTBF = new ArrayList<StatistiquesMTBF>();
List<StatistiquesMTBF> suspense = this.moduleGlobal.getMTBFByType(nbHeure, nbJour, NS, DAE, beginDate, endDate);
for (StatistiquesMTBF …
Run Code Online (Sandbox Code Playgroud) 当你需要填写JPA M:N关系时,处理多个chackbox的最佳方法是什么...例如我有一个JPA实体硬件和实体连接.
硬件有一组连接:
private Set<Connectivity> connectivities = new HashSet<Connectivity>(0);
Run Code Online (Sandbox Code Playgroud)
并有一个像这样的setter和getter:
@ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.REFRESH }, mappedBy = "hwProviders")
public Set<Connectivity> getConnectivities() {
return this.connectivities;
}
public void setConnectivities(Set<Connectivity> connectivities) {
this.connectivities = connectivities;
}
Run Code Online (Sandbox Code Playgroud)
我在gui中使用JSF2.2和primefaces 5.3:
<p:selectManyCheckbox id="connectivity" value="#{hardware.connectivities}" converter="omnifaces.SelectItemsConverter" layout="pageDirection">
<f:selectItems value="#{connectivityes}" var="connect" itemValue="#{connect}" itemLabel="#{connect.name}"/>
</p:selectManyCheckbox>
Run Code Online (Sandbox Code Playgroud)
我有延迟异常的问题,即使我在渲染视图之前调用强制加载该集合:
hardware.getConnectivities().size();
Run Code Online (Sandbox Code Playgroud)
关于如何处理这种情况的任何建议?
我正在使用omnifaces进行实体转换.
Tnx到BalusC我已经成功完成了加载,但我仍然存在问题.当我选中复选框并提交表单时,我会在转换中获得延迟异常,我认为:
16:34:50,538 SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (default task-12) org.hibernate.LazyInitializationException: failed to lazily initialize a collection, could not initialize proxy - no Session
at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:575)
at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:214)
at …
Run Code Online (Sandbox Code Playgroud) 我正在使用这个http://www.primefaces.org/showcase-labs/ui/selectManyCheckbox.jsf primefaces组件来获取动态booleanCheckboxes值
<p:selectManyCheckbox value="#{bean.selectedMovies}"
layout="pageDirection">
<f:selectItems value="#{bean.movies}" />
</p:selectManyCheckbox>
Run Code Online (Sandbox Code Playgroud)
我需要对所有布尔复选框应用不同的颜色,如下图所示
如果id = 1,那么如果id = 2,颜色将为红色,然后颜色将为橙色,依此类推.
我们知道这些是电影中的动态值,那么如何从支持bean中为这些动态复选框设置背景颜色?
我尝试将样式应用于selectManyCheckbox,但它作为背景颜色应用于整个selectManyCheckbox面板.
那么我应该如何动态地从支持bean设置颜色到selectManyCheckbox值呢?
我正在尝试使用带枚举的JSF/SelectManyCheckBox标记:
这是我的xhtml代码:
<h:form id="searchForm">
<h:panelGrid columns="2">
<h:outputText value="Searched queues" />
<h:panelGroup>
<h:selectManyCheckbox layout="pageDirection" value="#{jmsErrorController.errorSearchCriteria.searchedQueues}" converter="queueConverter">
<f:selectItems value="#{jmsErrorController.completeQueueList}" />
</h:selectManyCheckbox>
</h:panelGroup>
</h:panelGrid>
<h:commandButton action="#{jmsErrorController.search}"
value="Search !" />
</h:form>
Run Code Online (Sandbox Code Playgroud)
我添加了另一篇文章中所述的转换器.
它似乎工作正常,但我在控制台上看到这个堆栈跟踪:
28-Jun-2013 09:07:46 com.sun.faces.renderkit.html_basic.MenuRenderer createCollection
SEVERE: Unable to create new Collection instance for type java.util.Arrays$ArrayList
java.lang.InstantiationException: java.util.Arrays$ArrayList
at java.lang.Class.newInstance0(Class.java:340)
at java.lang.Class.newInstance(Class.java:308)
at com.sun.faces.renderkit.html_basic.MenuRenderer.createCollection(MenuRenderer.java:907)
at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValuesForModel(MenuRenderer.java:367)
at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValue(MenuRenderer.java:129)
at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:315)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030)
at javax.faces.component.UIInput.validate(UIInput.java:960)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1233)
at javax.faces.component.UIInput.processValidators(UIInput.java:698)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIForm.processValidators(UIForm.java:253)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1172)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at …
Run Code Online (Sandbox Code Playgroud) 假设这个页面的代码:
<h:form prependId="false" id="form">
<h:selectManyCheckbox id="checkBoxList" value="#{backedBean.lstIdSelectedItems}" layout="pageDirection">
<f:selectItems value="#{backedBean.lstAvailableItems}" var="item" itemLabel="#{item.label}" itemValue="#{item.value}" />
<f:ajax listener="#{backedBean.itemClicked}" />
</h:selectManyCheckbox>
</h:form>
Run Code Online (Sandbox Code Playgroud)
和会话管理bean的代码:
public class BackedBean implements Serializable {
private List<SelectItem> lstAvailableItems;
private List<Long> lstIdSelectedItems;
public BackedBean() {
lstAvailableItems = new ArrayList<SelectItem>();
lstIdSelectedItems = new ArrayList<Long>();
}
@PostConstruct
private void postConstruct(){
for (int i = 0; i < 10; i++) {
SelectItem item = new SelectItem(new Long(i), "CHKID " + i);
lstAvailableItems.add(item);
}
}
public void itemClicked(AjaxBehaviorEvent ae){
HtmlSelectManyCheckbox uiCmp = (HtmlSelectManyCheckbox)ae.getSource();
// …
Run Code Online (Sandbox Code Playgroud) 如何从支持bean中的UISelectMany组件中收集所有选定值,例如h:selectManyListbox,h:selectManyMenu,h:selectManyCheckbox,p:selectManyListbox,p:selectManyMenu,p:selectManyCheckbox等?
如果有人可以帮助一个例子,那将真的有帮助.
任务:有一个带有selectMany复选框的面板,该面板有5列。选择框的值按升序排列,但它们在列中从左到右而不是从上到下显示。
使用:Primefaces代码:
<p:selectManyCheckbox id="chkbx" value=.. layout="grid" columns="5">
<p:selectItems value=.. itemValue=".." itemLabel=".."/>
</p:selectManyCheckbox>
Run Code Online (Sandbox Code Playgroud)
当前屏幕:
[] a [] b [] c
[] d [] e [] f
[] g [] h [] i
Run Code Online (Sandbox Code Playgroud)
预期:
[] a [] d [] g
[] b [] e [] h
[] c [] f [] i
Run Code Online (Sandbox Code Playgroud) 我使用<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
属性上和所有其他单选组件中都可以正常工作.
这是怎么造成的,我该如何解决?
我正在尝试实施一个,<p:selectManyCheckbox>
但我没有成功.
现在我有以下架构:
Course - have many Disciplines
Discipline - belongs to none, one or many Courses.
Run Code Online (Sandbox Code Playgroud)
在Course
课堂上我有两个ArrayList<Discipline>
:
public class CourseMBean{
(...)
// Stores all disciplines
private static ArrayList<Discipline> allDisciplines;
// Stores only the disciplines that's already associated with this course.
private static ArrayList<Discipline> courseDisciplines;
(get and set for the arraylists)
(...)
}
Run Code Online (Sandbox Code Playgroud)
所有数据都来自MYSQL数据库,但这不是问题.现在我想创建一个新课程,所以我在courseDisciplines中没有任何内容.
我希望在复选框中显示allDisciplines,并希望在用户选择一个复选框时,在courseDisciplines中添加此复选框的对象Discipline - 并且当取消选中一个复选框时,从courseDsiciplines中删除该规则.
我的JSF 2.0代码如下:
<p:selectManyCheckbox id="disciplines" value="#{courseMBean.allDisciplines}" layout="grid" columns="2">
<f:selectItems value="#{courseMBean.courseDisciplines}" />
</p:selectManyCheckbox>
Run Code Online (Sandbox Code Playgroud)
这实际上显示所有学科没有任何选中的复选框,什么是正确的.但是当我选择一些复选框并提交表单时,我尝试在courseDisciplines中打印元素,这不会在控制台中显示任何内容.
我做错了什么?
我需要selectManyCheckbox
在4列中显示列表,但问题是该组件生成一个表,所以我不知道如何定义列.
我正在使用PF 3.4,我无法升级到PF 4.x. 你们有这个解决方案吗?
EDITED
现在我在我的代码中有这个
<h:form id="formAdminAccesosXPerfil">
<h:panelGrid title="Accesos" columns="5">
<c:forEach items="#{accesosXPerfilMB.listadoAcceso}" var="availableItem" varStatus="loop">
<h:panelGroup>
<p:selectBooleanCheckbox id="box_#{loop.index}" value="#{accesosXPerfilMB.checkBoxItems[availableItem]}" />
<h:outputLabel for="box_#{loop.index}" value="#{availableItem.nombre}" />
</h:panelGroup>
</c:forEach>
</h:panelGrid>
Run Code Online (Sandbox Code Playgroud)
Managebean是@ViewScoped
我改变了建议的方法,因为它对我不起作用......
从:
public void save() {
List<E> selectedItems = checkboxItems.entrySet().stream()
.filter(e -> e.getValue() == Boolean.TRUE)
.map(e -> e.getKey())
.collect(Collectors.toList());
// ...
Run Code Online (Sandbox Code Playgroud)
}
对此:
public void guardarAccesos(){
try {
System.out.println("Size: "+getCheckBoxItems().entrySet().size());
for(BpAcceso acceso:getCheckBoxItems().keySet()){
System.out.println("Acceso Seleccionado: "+acceso.getNombre());
}
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
但是我没有在hashMap上获得任何选定的项目.只是为了确保我使用的是jdk1.6
我想在JSF顶部使用PrimeFaces组件选中一些复选框中的所有复选框.
我的代码是这样的:
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
<p:outputLabel value="Confere:" style="font-weight:bold!important" />
<p:selectManyCheckbox
value="#{funcionarioBean.funcionario.permissaoConfere.stringArray}">
<f:selectItem itemLabel="Consulta" itemValue="C" />
<f:selectItem itemLabel="Edição" itemValue="E" />
<f:selectItem itemLabel="Deleção" itemValue="D" />
<f:selectItem itemLabel="Inclusão" itemValue="I" />
<f:selectItem itemLabel="Relatório" itemValue="R" />
<f:selectItem itemLabel="Check All"/>
</p:selectManyCheckbox>
</h:panelGrid>
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
<p:outputLabel value="Visitante:" style="font-weight:bold!important" />
<p:selectManyCheckbox
value="#{funcionarioBean.funcionario.permissaoVisitante.stringArray}">
<f:selectItem itemLabel="Consulta" itemValue="C" />
<f:selectItem itemLabel="Edição" itemValue="E" />
<f:selectItem itemLabel="Deleção" itemValue="D" />
<f:selectItem itemLabel="Inclusão" itemValue="I" />
<f:selectItem itemLabel="Relatório" itemValue="R" />
<f:selectItem itemLabel="Check All"/>
</p:selectManyCheckbox>
</h:panelGrid>
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
<p:outputLabel value="Ocorrências:" style="font-weight:bold!important" /> …
Run Code Online (Sandbox Code Playgroud) jsf ×10
primefaces ×8
jsf-2 ×5
ajax ×1
collections ×1
css ×1
enums ×1
jpa ×1
jquery ×1
layout ×1
orientation ×1
selectall ×1
selecteditem ×1