[英]JSF: display h:selectManyCheckBox vertically in h:dataTable
I have a simply facelet which display a list of products in tabular format. 我有一个简单的facelet,以表格格式显示产品列表。 In the last column of each row, there is a checkbox used to mark the product for deletion.
在每行的最后一列中,有一个用于标记产品以进行删除的复选框。 Until now i have to put a selectBooleanCheckBox on each row and have a "mark for deletion" property in the Product entity but i think it's ugly because i have some presentation stuff in my model bean.
到目前为止,我必须在每一行上放置一个selectBooleanCheckBox,并在Product实体中有一个“mark for deletion”属性,但我认为它很难看,因为我的模型bean中有一些演示文稿。
Is there anyway to have ah:selectManyCheckBox which has its f:selectItem distribute on each row of the dataTable ? 反正有啊:selectManyCheckBox有哪个f:selectItem分布在dataTable的每一行?
Thank you 谢谢
The t:selectManyCheckbox layout="spread"
is an excellent suggestion. t:selectManyCheckbox layout="spread"
是一个很好的建议。
As an alternative, you can also just bind the h:selectBooleanCheckbox
component to a Map<Long, Boolean>
property where Long
represents the entity ID (or whatever identifier which you can use to identify the row) and Boolean
represents the checked state. 作为替代方案,您还可以将
h:selectBooleanCheckbox
组件绑定到Map<Long, Boolean>
属性,其中Long
表示实体ID(或可用于标识行的任何标识符), Boolean
表示已检查状态。
Eg 例如
public class Bean {
private List<Entity> entities;
private Map<Long, Boolean> checked = new HashMap<Long, Boolean>();
public void submit() {
for (Entity entity : entities) {
if (checked.get(entity.getId())) {
// Entity is checked. Do your thing here.
}
}
}
// ...
}
with 同
<h:dataTable value="#{bean.entities}" var="entity">
<h:column>
<h:selectBooleanCheckbox value="#{bean.checked[entity.id]}" />
</h:column>
...
</h:dataTable>
<h:commandButton value="submit" action="#{bean.submit}" />
The Map<Long, Boolean>
will be automagically filled with the ID of all entities as map keys and the checkbox value is set as map value associated with the entity ID as key. Map<Long, Boolean>
将自动填充所有实体的ID作为映射键,并将checkbox值设置为与实体ID关联的映射值作为键。
你可以使用MyFaces Tomahawk的<t:selectManyCheckbox>
with layout="spread"
In my application, i have used below set of code to get multiple checkbox list to be displayed vertically with scrollbar: 在我的应用程序中,我使用下面的代码集来获取多个复选框列表,使用滚动条垂直显示:
<style type="text/css">
#productCategoryId label {
float: inherit;
font-size: 10px!important;
font-weight: normal;
}
#productCategoryId table.formTable th, table.formTable td {
padding: 0px 0px 0 0;
}
</style>
<div style="width:200px;height: 280px;overflow-y:scroll;overflow-x:hidden;border:1px solid #999;" max-height=280px>
<h:selectManyCheckbox id="productCategoryId" layout="pageDirection" style="width:200px" styleClass="changeId">
<f:selectItem itemValue="-1000" itemLabel="ALL" />
<f:selectItems value="#{lookup.list['RSM_LOOKUP']['PRODUCT_CATEGORY']}"/>
</h:selectManyCheckbox >
</div>
The best way to use selectManyCheckbox and dataTable is... 使用selectManyCheckbox和dataTable的最佳方法是......
=== Page.xhtml === === Page.xhtml ===
<ice:selectManyCheckbox id="idSelectManyCheckbox" layout="spread"
value="#{MyBean.selectedsValuesCheckbox}" >
<f:selectItems value="#{MyBean.selectItemsCheck}"/>
</ice:selectManyCheckbox>
<ice:dataTable varStatus="rowVar"
value="#{MyBean.listOfMyObjects}" var="anyNameVar">
<ice:column>
<ice:checkbox for="idSelectManyCheckbox" index="#{rowVar.index}" />
</ice:column>
<ice:column>
<ice:outputText value="#{anyNameVar.property1}" />
</ice:column>
<!-- ... more columns .. -->
</ice:dataTable>
=== MyBean.java === === MyBean.java ===
private List<MyObject> listOfMyObjects = new ArrayList<MyObject>(3);
private List<String> selectedsValuesCheckbox = new ArrayList<String>(2);
private SelectItem[] selectItemsCheck = new SelectItem[3];
private handleSelectItemsCheck(){
int idx = 0;
selectedsValuesCheckbox.add("1");
selectedsValuesCheckbox.add("3");
for (MyObject myObject : listOfMyObjects) {
selectItemsCheck[idx++] =
new SelectItem(myObject.property1, myObject.property2); // value and label
}
}
// Gets and sets //获取和设置
================================================================ ================================================== ==============
*you must use layout="spread" in that situation.
*in the table the checkboxs 1 and 3 will be selected. because "selectedsValuesCheckbox"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.