ofbiz 实现checkbox翻页选择

本文介绍了一个基于OFBiz的复选框翻页功能实现方案,通过定义隐藏变量、使用JavaScript来处理checkbox的状态变化,并在后台Action中进行相应的逻辑处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由于项目需要,我用ofbiz实现了这个话题,在这里与大家共享.
ftl页面:
1,定义三个Hidden变量:
[quote] <body οnlοad="initPage();">
<input type="hidden" id="checkedStr" value="${checkedStr?if_exists}">
<input type="hidden" id="noCheckedStr" value="${noCheckedStr?if_exists}">
<input type="hidden" id="allSelect" value="${allSelect?if_exists}">[/quote]
看到名字大家应该知道是做什么用的,在这里不多解释.
2,javascript
// 获取checkbox信息,选中,未选中,当前选中
function getCheckBoxInformation() {
var checkboxes = document.getElementsByName("subMemberId");

var checkedStr = "";
var noCheckedStr = "";
for(i = 0; i < checkboxes.length; i++) {
var checkbox = checkboxes[i];
if(checkbox.checked) {
checkedStr = checkedStr + "," + checkbox.value;
}else {
noCheckedStr = noCheckedStr + "," + checkbox.value;
}
}

window.location.href='${action}
?VIEW_SIZE=${viewSize}&VIEW_INDEX=${viewIndex-1}&
hideFields=${parameters.hideFields?default("N")}${paramList}&
checkedStr='+checkedStr+'&noCheckedStr='+noCheckedStr+'&allSelect='+allSelect.value;
}

// 页面onload的时候计算当前页被选中项,并在页面表示
function initPage()
{
var allSelect = document.getElementById("allSelect");
var all_selected = allSelect.value;
var checkboxes = document.getElementsByName("subMemberId");
if(all_selected != "" && all_selected!= null)
{
var arrall_select = all_selected.split(",");
// alert(arrall_select.length);
if(arrall_select.length > 0)
{
for(k = 0; k < arrall_select.length; k++)
{
for(i = 0; i < checkboxes.length; i++)
{ var checkbox = checkboxes[i];
if((checkbox.value == arrall_select[k])==true)
{
checkbox.checked = true;
}
}
}
}
}
}
每次翻页的时候调用getCheckBoxInformation()方法,页面加载的时候调用initPage()方法.
3,后台Action操作,在每次执行时候调用下面的方法
private static String operationCheckInfo(DispatchContext ctx, Map context)
throws Exception {

Map result = new HashMap();
String allSelect;
//VIEW_INDEX,VIEW_SIZE判断是否是翻页操作
if (context.get("VIEW_INDEX") != null
&& context.get("VIEW_SIZE") != null) {
String all_select = (String) context.get("allSelect");
if (all_select == null || all_select.equals("")) {
all_select = "";
}
//获取当前选中的项目
String now_select = (String) context.get("checkedStr");
String[] all_now_select = null;
if (now_select != null || !now_select.equals("")) {
all_now_select = now_select.split(",");
}

//获取当前未选中项目
String no_select = (String) context.get("noCheckedStr");
String[] all_now_no_select = null;
if (now_select != null || !now_select.equals("")) {
all_now_no_select = no_select.split(",");
}

//将当前选中项目加入列表
for (int i = 1; i < all_now_select.length; i++) {
String strBoxSelected = all_now_select[i];
String strSearchWith = strBoxSelected + ",";
if (all_select.indexOf(strSearchWith) == -1) {
all_select = all_select + strSearchWith;
}
}
//将当前未选中项目从列表中删除
for (int i = 1; i < all_now_no_select.length; i++) {
String strBoxNoselected = all_now_no_select[i];
String strSearchWith = strBoxNoselected + ",";
int iSearchIndex = all_select.indexOf(strSearchWith);
if (iSearchIndex != -1) {
all_select = all_select.replaceAll(strSearchWith, "");
}
}

allSelect = all_select;
result.put("allSelect", all_select);
} else {

allSelect = "";
result.put("allSelect", "");
}

return allSelect;
}
到现在为止,checkbox的翻页选中已经完成,最后说一句的是,这次仅仅完成了任务,性能方面还有很大的缺陷,大家如果有好的想法或者建议,请与我留言.谢谢!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值