trainReqColl.zul
请看下面Listbox
<?page title="TrainingRequireCollection" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="年度訓練需求收集" border="normal" id="WinColl" width="auto" apply="com.web.TrainReqCollController" position="center,center">
<div align="center">
<div align="center" width="980px">
<groupbox closable="false">
<grid fixedLayout="true">
<columns>
<column width="100px" />
<column width="180px" />
<column width="130px" />
<column width="210px" />
<column width="90px" />
<column width="210px" />
</columns>
<rows>
<row>
<label value="階層 " pre="true" />
<combobox id="cobPerson_level" autodrop="true" constraint="no empty" readonly="true">
<comboitem label="課長"></comboitem>
<comboitem label="經理"></comboitem>
</combobox>
<label value="職等 " pre="true" />
<combobox id="cobTitle" autodrop="true" constraint="no empty" readonly="true">
<comboitem label="1"></comboitem>
<comboitem label="3"></comboitem>
<comboitem label="5"></comboitem>
</combobox>
<label value="課程名稱" pre="true" />
<combobox id="cobCourseName" autodrop="true" constraint="no empty" readonly="true">
<comboitem label="課程名稱1"></comboitem>
<comboitem label="課程名稱2"></comboitem>
<comboitem label="課程名稱3"></comboitem>
</combobox>
</row>
<row>
<label value="時數" pre="true" />
<intbox id="txtHours" format="0" constraint="no empty,no negative,no zero" />
<label value="人數" pre="true" />
<intbox id="txtNumber_of_Person" format="0" constraint="no empty,no negative,no zero" />
<label value="班次 " pre="true" />
<intbox id="txtOrder_of_Classes" format="0" constraint="no empty,no negative,no zero" />
</row>
<row>
<label value="內/外訓" pre="true" />
<radiogroup id="rdoInternalExternal">
<radio label="內訓" value="0" />
<space spacing="5px" />
<radio label="外訓" value="1" />
</radiogroup>
<label value="訓練目標與說明" pre="true" />
<cell colspan="3" style="color: #00547A" valign="top">
<textbox id="txtTarget_Description" rows="1" width="450px" />
</cell>
</row>
<row>
<label value="填寫日期" pre="true" />
<datebox id="dboxInsert_Date" format="yy-MM-dd HH:mm:ss" readonly="true" constraint="no empty" />
<label value="發送日期" pre="true" />
<datebox id="dboxSend_Date" format="yy-MM-dd HH:mm:ss" readonly="true" constraint="no empty" />
</row>
<row>
<label value="備註" pre="true" />
<cell colspan="3" style="color: #00547A" valign="top">
<textbox id="txtRemark" rows="1" width="450px" />
</cell>
</row>
</rows>
</grid>
</groupbox>
<hbox pack="center" width="980px">
<button id="btnAdd" label="Add" mold="trendy"
height="27px" width="55px" />
</hbox>
</div>
<div height="500px">
<listbox model="@{WinColl.trcModel}" width="980px" checkmark="true" fixedLayout="true" mold="paging" pageSize="6" emptyMessage="No items match your search">
<listhead sizable="true">
<listheader width="30px" />
<listheader label="階層" width="50px" align="center" />
<listheader label="職等" width="50px" align="center" />
<listheader label="課程名稱" width="50px" align="center" />
<listheader label="時數" width="50px" align="center" />
<listheader label="人數" width="50px" align="center" />
<listheader label="班次" width="70px" align="center" />
<listheader label="內/外訓" width="70px" align="center" />
<listheader label="訓練目標與說明" width="70px" align="center" />
<listheader label="備註" width="70" align="center" />
<listheader label="填寫日期" width="70" align="center" />
<listheader label="發送日期" width="70" align="center" />
</listhead>
<template name="model">
<listitem>
<listcell />
<listcell label="@{each.personLevel}" />
<listcell label="@{each.title}" />
<listcell label="@{each.courseName}" />
<listcell label="@{each.hours}" />
<listcell label="@{each.numberOfPerson}" />
<listcell label="@{each.orderOfClasses}" />
<listcell label="@{each.internalExternalTraining}" />
<listcell label="@{each.targetDescription}" />
<listcell label="@{each.remark}" />
<listcell label="@{each.insertDate}"/>
<listcell style="@{each.sendDate}" />
</listitem>
</template>
</listbox>
</div>
</div>
</window>
</zk>
TrainReqCollController.java
这是web层
package com.web;
import java.text.ParseException;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zkplus.spring.SpringUtil;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.Datebox;
import org.zkoss.zul.Intbox;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Radiogroup;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;
import com.entity.TrTrainReqColl;
import com.service.ITrainReqCollService;
@Controller
public class TrainReqCollController extends GenericForwardComposer {
private static final long serialVersionUID = 1L;
@Autowired
private ITrainReqCollService trainReqCollService;
TrTrainReqColl ttrc = null;
WebCommon common = new WebCommon();
private Window parentWindow;
private ListModelList<TrTrainReqColl> trcModel;
public ListModelList<TrTrainReqColl> getTrcModel() {
return trcModel;
}
//Add Zul Compnent
Combobox cobPerson_level;
Combobox cobTitle;
Combobox cobCourseName;
Intbox txtHours;
Intbox txtNumber_of_Person;
Intbox txtOrder_of_Classes;
Radiogroup rdoInternalExternal;
Textbox txtTarget_Description;
Datebox dboxInsert_Date;
Datebox dboxSend_Date;
Textbox txtRemark;
//default construct
public TrainReqCollController(){
System.out.println("Enter Default ConStruct");
ttrc.setInsertDate(common.getDateNow());
}
//do it when first startup
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
System.out.println("Enter doAfterCompose");
SpringUtil.getApplicationContext().getAutowireCapableBeanFactory().autowireBean(this);
parentWindow = (Window) comp;
ttrc = new TrTrainReqColl();
trcModel = new ListModelList<TrTrainReqColl>(trainReqCollService.getAllTRC());
((ListModelList<TrTrainReqColl>)trcModel).setMultiple(true);
}
//hr add TrainReqColl info
public void onClick$btnAdd() throws Exception, ParseException{
ttrc.setPersonLevel(common.getComboboxLabel(cobPerson_level));
ttrc.setTitle(Integer.parseInt(common.getComboboxLabel(cobTitle)));
ttrc.setCourseName(common.getComboboxLabel(cobCourseName));
ttrc.setHours(common.getIntbox(txtHours));
ttrc.setNumberOfPerson(common.getIntbox(txtNumber_of_Person));
ttrc.setOrderOfClasses(common.getIntbox(txtOrder_of_Classes));
ttrc.setInternalExternalTraining(common.getRadioValue(rdoInternalExternal));
ttrc.setTargetDescription(common.getTextboxValue(txtTarget_Description));
ttrc.setSendDate(common.getDate(dboxSend_Date));
ttrc.setRemark(common.getTextboxValue(txtRemark));
try {
//Clients.showBusy("page loading......");
trainReqCollService.saveAll(ttrc);
this.showSuccessMessage("Insert Success!");
} catch (Exception e) {
this.showErrorMessage("Insert Fail!", "plase contact with MIS");
} finally {
Clients.clearBusy();
}
}
//insert success alert and forward next page
@SuppressWarnings("unchecked")
public void showSuccessMessage(String msg) {
Messagebox.show(msg, "Prompt", Messagebox.OK, Messagebox.QUESTION, new EventListener() {
public void onEvent(Event evt) {
Executions.sendRedirect("/training/TrainReqColl.zul");
}
});
}
//insert fail alert
public void showErrorMessage(String title, String msg) {
Messagebox.show(msg, title, Messagebox.OK, Messagebox.ERROR);
}
}
Log记载,输出正常
INFO: Parsing jndi:/localhost/ELearning/WEB-INF/zk.xml
Enter Default ConStruct
Enter doAfterCompose
Hibernate:
select
trtrainreq0_.ID as ID0_,
trtrainreq0_.COURSE_NAME as COURSE2_0_,
trtrainreq0_.HOURS as HOURS0_,
trtrainreq0_.INSERT_DATE as INSERT4_0_,
trtrainreq0_.INTERNAL_EXTERNAL_TRAINING as INTERNAL5_0_,
trtrainreq0_.NUMBER_OF_PERSON as NUMBER6_0_,
trtrainreq0_.ORDER_OF_CLASSES as ORDER7_0_,
trtrainreq0_.PERSON_LEVEL as PERSON8_0_,
trtrainreq0_.REMARK as REMARK0_,
trtrainreq0_.SEND_DATE as SEND10_0_,
trtrainreq0_.TARGET_DESCRIPTION as TARGET11_0_,
trtrainreq0_.TITLE as TITLE0_
from
EXAM.TR_TRAIN_REQ_COLL trtrainreq0_
八月 26, 2014 3:57:52 下午 org.zkoss.util.resource.impl.LabelLoaderImpl loadLabels
INFO: Loading labels for en_US
八月 26, 2014 3:57:52 下午 org.zkoss.util.resource.impl.LabelLoaderImpl loadLabels
INFO: Loading labels for en
但是web缺没值
11 个解决方案
#1
表沉啊,顶起
#2
listitem标签改成这样试下,
<listitem value="${each }">
#3
估计这里也只有你懂ZK了。网上查啊 查,现在效果是:
我再贴下最新的代码
package com.web;
import java.text.ParseException;
import java.util.List;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zkplus.databind.BindingListModelList;
import org.zkoss.zkplus.spring.SpringUtil;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.Datebox;
import org.zkoss.zul.Intbox;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Radiogroup;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;
import com.entity.TrTrainReqColl;
import com.service.ITrainReqCollService;
@Controller
public class TrainReqCollController extends GenericForwardComposer {
private static final long serialVersionUID = 1L;
@Autowired
private ITrainReqCollService trainReqCollService;
TrTrainReqColl ttrc = null;
WebCommon common = new WebCommon();
private Window parentWindow;
private ListModelList<TrTrainReqColl> trcModel;
private List<TrTrainReqColl> listTrTrainReqColl;
//Add Zul Compnent
Combobox cobPerson_level;
Combobox cobTitle;
Combobox cobCourseName;
Intbox txtHours;
Intbox txtNumber_of_Person;
Intbox txtOrder_of_Classes;
Radiogroup rdoInternalExternal;
Textbox txtTarget_Description;
Datebox dboxInsert_Date;
Datebox dboxSend_Date;
Textbox txtRemark;
Listbox listTRC;
public Listbox getListTRC() {
return listTRC;
}
public void setListTRC(Listbox listTRC) {
this.listTRC = listTRC;
}
//default construct
public TrainReqCollController(){
System.out.println("Enter Default ConStruct");
}
//do it when first startup
@SuppressWarnings("unchecked")
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
System.out.println("Enter doAfterCompose");
SpringUtil.getApplicationContext().getAutowireCapableBeanFactory().autowireBean(this);
parentWindow = (Window) comp;
ttrc = new TrTrainReqColl();
ttrc.setInsertDate(common.getDateNow());
// listTRC = (Listbox) parentWindow.getFellow("listTRC");
// listTrTrainReqColl = trainReqCollService.getAllTRC();
// BindingListModelList bindlist = new BindingListModelList<>(listTrTrainReqColl, true);
// listTRC.setModel(bindlist);
trcModel = new ListModelList<>(trainReqCollService.getAllTRC());
((ListModelList<TrTrainReqColl>)trcModel).setMultiple(true);
listTRC.setModel(trcModel);
}
public ListModelList<TrTrainReqColl> getTrcModel() {
return trcModel;
}
public void setTrcModel(ListModelList<TrTrainReqColl> trcModel) {
this.trcModel = trcModel;
}
@Listen("onSelect = listbox")
public void updateMessage() {
Set<TrTrainReqColl> selectedCars = ((ListModelList<TrTrainReqColl>)trcModel).getSelection();
int size = selectedCars.size();
showNotify(size > 0 ? size + " cars selected: " + selectedCars : "no car selected", parentWindow);
}
private void showNotify(String msg,Component ref){
Clients.showNotification(msg,"info",ref,"top_right",2000);
}
//hr add TrainReqColl info
public void onClick$btnAdd() throws Exception, ParseException{
ttrc.setPersonLevel(common.getComboboxLabel(cobPerson_level));
ttrc.setTitle(Integer.parseInt(common.getComboboxLabel(cobTitle)));
ttrc.setCourseName(common.getComboboxLabel(cobCourseName));
ttrc.setHours(common.getIntbox(txtHours));
ttrc.setNumberOfPerson(common.getIntbox(txtNumber_of_Person));
ttrc.setOrderOfClasses(common.getIntbox(txtOrder_of_Classes));
ttrc.setInternalExternalTraining(common.getRadioValue(rdoInternalExternal));
ttrc.setTargetDescription(common.getTextboxValue(txtTarget_Description));
ttrc.setSendDate(common.getDate(dboxSend_Date));
ttrc.setRemark(common.getTextboxValue(txtRemark));
try {
//Clients.showBusy("page loading......");
trainReqCollService.saveAll(ttrc);
this.showSuccessMessage("Insert Success!");
} catch (Exception e) {
this.showErrorMessage("Insert Fail!", "plase contact with MIS");
} finally {
Clients.clearBusy();
}
}
//insert success alert and forward next page
@SuppressWarnings("unchecked")
public void showSuccessMessage(String msg) {
Messagebox.show(msg, "Prompt", Messagebox.OK, Messagebox.QUESTION, new EventListener() {
public void onEvent(Event evt) {
Executions.sendRedirect("/training/TrainReqColl.zul");
}
});
}
//insert fail alert
public void showErrorMessage(String title, String msg) {
Messagebox.show(msg, title, Messagebox.OK, Messagebox.ERROR);
}
}
<?page title="TrainingRequireCollection" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="年度訓練需求收集" border="normal" id="WinColl" width="auto" apply="com.web.TrainReqCollController" position="center,center">
<div align="center">
<div align="center" width="980px">
<groupbox closable="false">
<grid fixedLayout="true">
<columns>
<column width="100px" />
<column width="180px" />
<column width="130px" />
<column width="210px" />
<column width="90px" />
<column width="210px" />
</columns>
<rows>
<row>
<label value="階層 " pre="true" />
<combobox id="cobPerson_level" autodrop="true" constraint="no empty" readonly="true">
<comboitem label="課長"></comboitem>
<comboitem label="經理"></comboitem>
</combobox>
<label value="職等 " pre="true" />
<combobox id="cobTitle" autodrop="true" constraint="no empty" readonly="true">
<comboitem label="1"></comboitem>
<comboitem label="3"></comboitem>
<comboitem label="5"></comboitem>
</combobox>
<label value="課程名稱" pre="true" />
<combobox id="cobCourseName" autodrop="true" constraint="no empty" readonly="true">
<comboitem label="課程名稱1"></comboitem>
<comboitem label="課程名稱2"></comboitem>
<comboitem label="課程名稱3"></comboitem>
</combobox>
</row>
<row>
<label value="時數" pre="true" />
<intbox id="txtHours" format="0" constraint="no empty,no negative,no zero" />
<label value="人數" pre="true" />
<intbox id="txtNumber_of_Person" format="0" constraint="no empty,no negative,no zero" />
<label value="班次 " pre="true" />
<intbox id="txtOrder_of_Classes" format="0" constraint="no empty,no negative,no zero" />
</row>
<row>
<label value="內/外訓" pre="true" />
<radiogroup id="rdoInternalExternal">
<radio label="內訓" value="0" />
<space spacing="5px" />
<radio label="外訓" value="1" />
</radiogroup>
<label value="訓練目標與說明" pre="true" />
<cell colspan="3" style="color: #00547A" valign="top">
<textbox id="txtTarget_Description" rows="1" width="450px" />
</cell>
</row>
<row>
<label value="填寫日期" pre="true" />
<datebox id="dboxInsert_Date" format="yy-MM-dd HH:mm:ss" readonly="true" constraint="no empty" />
<label value="發送日期" pre="true" />
<datebox id="dboxSend_Date" format="yy-MM-dd HH:mm:ss" readonly="true" constraint="no empty" />
</row>
<row>
<label value="備註" pre="true" />
<cell colspan="3" style="color: #00547A" valign="top">
<textbox id="txtRemark" rows="1" width="450px" />
</cell>
</row>
</rows>
</grid>
</groupbox>
<hbox pack="center" width="980px">
<button id="btnAdd" label="Add" mold="trendy"
height="27px" width="55px" />
</hbox>
</div>
<div height="500px">
<listbox id="listTRC" model="@{listTrTrainReqColl}" width="980px" checkmark="true" fixedLayout="true" mold="paging" pageSize="6" emptyMessage="No items match your search">
<listhead sizable="true">
<listheader width="30px" />
<listheader label="階層" width="50px" align="center" />
<listheader label="職等" width="50px" align="center" />
<listheader label="課程名稱" width="50px" align="center" />
<listheader label="時數" width="50px" align="center" />
<listheader label="人數" width="50px" align="center" />
<listheader label="班次" width="70px" align="center" />
<listheader label="內/外訓" width="70px" align="center" />
<listheader label="訓練目標與說明" width="70px" align="center" />
<listheader label="備註" width="70" align="center" />
<listheader label="填寫日期" width="70" align="center" />
<listheader label="發送日期" width="70" align="center" />
</listhead>
<template name="model">
<listitem self="@{each=ttrc}" value="${each }">
<listcell />
<listcell label="@{ttrc.personLevel}" />
<listcell label="@{ttrc.title}" />
<listcell label="@{ttrc.courseName}" />
<listcell label="@{ttrc.hours}" />
<listcell label="@{ttrc.numberOfPerson}" />
<listcell label="@{ttrc.orderOfClasses}" />
<listcell label="@{ttrc.internalExternalTraining}" />
<listcell label="@{ttrc.targetDescription}" />
<listcell label="@{ttrc.remark}" />
<listcell label="@{ttrc.insertDate}"/>
<listcell style="@{ttrc.sendDate}" />
</listitem>
</template>
</listbox>
</div>
</div>
</window>
</zk>
#4
<div height="500px">
<listbox id="listTRC" model="@{listTrTrainReqColl}" vflex="true" width="980px" >
<listhead sizable="true">
<listheader label="階層" width="300px" align="center" />
</listhead>
<listitem self="@{each=ttrc}" value="${ttrc}">
<listcell label="${ttrc.id}" />
</listitem>
</listbox>
</div>
#5
你那个Controller注解没用的,去掉吧。 我贴下我的代码, 你参考下,
首先我的Controller继承了SelectorComposer 跟你那个是否有区别我不太确定, 老早的东西了,忘记了。
我是这样注入页面元素的, 变量名就是页面的id, 这个id我看到你后来也加上上去了。 我不知道你不加@Wire注解能不能跟页面元素对应上,这个你确认下。
这里代码很清楚, serviec查询一页数据, 跟你的基本一样。
页面:
跟你不太一样, 你可以参考改下,看是否有用
这是
首先我的Controller继承了SelectorComposer 跟你那个是否有区别我不太确定, 老早的东西了,忘记了。
@Wire private Listbox adspList;
@Wire private Paging pager;
@Wire
private Datebox syncDateBox;
我是这样注入页面元素的, 变量名就是页面的id, 这个id我看到你后来也加上上去了。 我不知道你不加@Wire注解能不能跟页面元素对应上,这个你确认下。
Pagination<Adspace> page = adspaceService.getOnePage(adSpc, curr);
ListModelList<Adspace> model = new ListModelList<Adspace>(page.getResult());
model.setMultiple(true);
adspList.setModel(model);
这里代码很清楚, serviec查询一页数据, 跟你的基本一样。
页面:
<listbox id="adspList" checkmark="true">
<listhead>
<listheader label="id" />
<listheader label="编号" sort="auto" />
</listhead>
<template name="model">
<listitem value="${each }">
<listcell label="${each.id }"></listcell>
<listcell label="${each.adZoneId }"></listcell>
</listitem>
</template>
</listbox>
<paging id="pager" activePage="0" />
跟你不太一样, 你可以参考改下,看是否有用
这是
#6
顶
#7
OK,可以了,谢谢,以后有问题我直接发帖请你回答好了!
#8
OK 非常感谢,对了还有个问题。
我设置了 checkmark="true"
我想实现批量选中删除,我后台如何获取到选中行呢?
#9
Listbox 有个getSelectedItems方法, 返回选中Listitem的集合, 如何没有勾选则集合为空
#10
thx,这个功能也搞定了!
#11
求助:向页面注入两种model,一种是list(实体),另一种list(String)。前台listbox当中有嵌套,分别用model初始化listitem。要如何实现??
我尝试如下没能成功:
原因:报错没有唯一的ID。
在里面<listbox>外添加<window>,页面没有报错,控制台报 空指针。list<String>没有与页面中对应。
我尝试如下没能成功:
原因:报错没有唯一的ID。
在里面<listbox>外添加<window>,页面没有报错,控制台报 空指针。list<String>没有与页面中对应。
#1
表沉啊,顶起
#2
listitem标签改成这样试下,
<listitem value="${each }">
#3
估计这里也只有你懂ZK了。网上查啊 查,现在效果是:
我再贴下最新的代码
package com.web;
import java.text.ParseException;
import java.util.List;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zkplus.databind.BindingListModelList;
import org.zkoss.zkplus.spring.SpringUtil;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.Datebox;
import org.zkoss.zul.Intbox;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Radiogroup;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;
import com.entity.TrTrainReqColl;
import com.service.ITrainReqCollService;
@Controller
public class TrainReqCollController extends GenericForwardComposer {
private static final long serialVersionUID = 1L;
@Autowired
private ITrainReqCollService trainReqCollService;
TrTrainReqColl ttrc = null;
WebCommon common = new WebCommon();
private Window parentWindow;
private ListModelList<TrTrainReqColl> trcModel;
private List<TrTrainReqColl> listTrTrainReqColl;
//Add Zul Compnent
Combobox cobPerson_level;
Combobox cobTitle;
Combobox cobCourseName;
Intbox txtHours;
Intbox txtNumber_of_Person;
Intbox txtOrder_of_Classes;
Radiogroup rdoInternalExternal;
Textbox txtTarget_Description;
Datebox dboxInsert_Date;
Datebox dboxSend_Date;
Textbox txtRemark;
Listbox listTRC;
public Listbox getListTRC() {
return listTRC;
}
public void setListTRC(Listbox listTRC) {
this.listTRC = listTRC;
}
//default construct
public TrainReqCollController(){
System.out.println("Enter Default ConStruct");
}
//do it when first startup
@SuppressWarnings("unchecked")
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
System.out.println("Enter doAfterCompose");
SpringUtil.getApplicationContext().getAutowireCapableBeanFactory().autowireBean(this);
parentWindow = (Window) comp;
ttrc = new TrTrainReqColl();
ttrc.setInsertDate(common.getDateNow());
// listTRC = (Listbox) parentWindow.getFellow("listTRC");
// listTrTrainReqColl = trainReqCollService.getAllTRC();
// BindingListModelList bindlist = new BindingListModelList<>(listTrTrainReqColl, true);
// listTRC.setModel(bindlist);
trcModel = new ListModelList<>(trainReqCollService.getAllTRC());
((ListModelList<TrTrainReqColl>)trcModel).setMultiple(true);
listTRC.setModel(trcModel);
}
public ListModelList<TrTrainReqColl> getTrcModel() {
return trcModel;
}
public void setTrcModel(ListModelList<TrTrainReqColl> trcModel) {
this.trcModel = trcModel;
}
@Listen("onSelect = listbox")
public void updateMessage() {
Set<TrTrainReqColl> selectedCars = ((ListModelList<TrTrainReqColl>)trcModel).getSelection();
int size = selectedCars.size();
showNotify(size > 0 ? size + " cars selected: " + selectedCars : "no car selected", parentWindow);
}
private void showNotify(String msg,Component ref){
Clients.showNotification(msg,"info",ref,"top_right",2000);
}
//hr add TrainReqColl info
public void onClick$btnAdd() throws Exception, ParseException{
ttrc.setPersonLevel(common.getComboboxLabel(cobPerson_level));
ttrc.setTitle(Integer.parseInt(common.getComboboxLabel(cobTitle)));
ttrc.setCourseName(common.getComboboxLabel(cobCourseName));
ttrc.setHours(common.getIntbox(txtHours));
ttrc.setNumberOfPerson(common.getIntbox(txtNumber_of_Person));
ttrc.setOrderOfClasses(common.getIntbox(txtOrder_of_Classes));
ttrc.setInternalExternalTraining(common.getRadioValue(rdoInternalExternal));
ttrc.setTargetDescription(common.getTextboxValue(txtTarget_Description));
ttrc.setSendDate(common.getDate(dboxSend_Date));
ttrc.setRemark(common.getTextboxValue(txtRemark));
try {
//Clients.showBusy("page loading......");
trainReqCollService.saveAll(ttrc);
this.showSuccessMessage("Insert Success!");
} catch (Exception e) {
this.showErrorMessage("Insert Fail!", "plase contact with MIS");
} finally {
Clients.clearBusy();
}
}
//insert success alert and forward next page
@SuppressWarnings("unchecked")
public void showSuccessMessage(String msg) {
Messagebox.show(msg, "Prompt", Messagebox.OK, Messagebox.QUESTION, new EventListener() {
public void onEvent(Event evt) {
Executions.sendRedirect("/training/TrainReqColl.zul");
}
});
}
//insert fail alert
public void showErrorMessage(String title, String msg) {
Messagebox.show(msg, title, Messagebox.OK, Messagebox.ERROR);
}
}
<?page title="TrainingRequireCollection" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="年度訓練需求收集" border="normal" id="WinColl" width="auto" apply="com.web.TrainReqCollController" position="center,center">
<div align="center">
<div align="center" width="980px">
<groupbox closable="false">
<grid fixedLayout="true">
<columns>
<column width="100px" />
<column width="180px" />
<column width="130px" />
<column width="210px" />
<column width="90px" />
<column width="210px" />
</columns>
<rows>
<row>
<label value="階層 " pre="true" />
<combobox id="cobPerson_level" autodrop="true" constraint="no empty" readonly="true">
<comboitem label="課長"></comboitem>
<comboitem label="經理"></comboitem>
</combobox>
<label value="職等 " pre="true" />
<combobox id="cobTitle" autodrop="true" constraint="no empty" readonly="true">
<comboitem label="1"></comboitem>
<comboitem label="3"></comboitem>
<comboitem label="5"></comboitem>
</combobox>
<label value="課程名稱" pre="true" />
<combobox id="cobCourseName" autodrop="true" constraint="no empty" readonly="true">
<comboitem label="課程名稱1"></comboitem>
<comboitem label="課程名稱2"></comboitem>
<comboitem label="課程名稱3"></comboitem>
</combobox>
</row>
<row>
<label value="時數" pre="true" />
<intbox id="txtHours" format="0" constraint="no empty,no negative,no zero" />
<label value="人數" pre="true" />
<intbox id="txtNumber_of_Person" format="0" constraint="no empty,no negative,no zero" />
<label value="班次 " pre="true" />
<intbox id="txtOrder_of_Classes" format="0" constraint="no empty,no negative,no zero" />
</row>
<row>
<label value="內/外訓" pre="true" />
<radiogroup id="rdoInternalExternal">
<radio label="內訓" value="0" />
<space spacing="5px" />
<radio label="外訓" value="1" />
</radiogroup>
<label value="訓練目標與說明" pre="true" />
<cell colspan="3" style="color: #00547A" valign="top">
<textbox id="txtTarget_Description" rows="1" width="450px" />
</cell>
</row>
<row>
<label value="填寫日期" pre="true" />
<datebox id="dboxInsert_Date" format="yy-MM-dd HH:mm:ss" readonly="true" constraint="no empty" />
<label value="發送日期" pre="true" />
<datebox id="dboxSend_Date" format="yy-MM-dd HH:mm:ss" readonly="true" constraint="no empty" />
</row>
<row>
<label value="備註" pre="true" />
<cell colspan="3" style="color: #00547A" valign="top">
<textbox id="txtRemark" rows="1" width="450px" />
</cell>
</row>
</rows>
</grid>
</groupbox>
<hbox pack="center" width="980px">
<button id="btnAdd" label="Add" mold="trendy"
height="27px" width="55px" />
</hbox>
</div>
<div height="500px">
<listbox id="listTRC" model="@{listTrTrainReqColl}" width="980px" checkmark="true" fixedLayout="true" mold="paging" pageSize="6" emptyMessage="No items match your search">
<listhead sizable="true">
<listheader width="30px" />
<listheader label="階層" width="50px" align="center" />
<listheader label="職等" width="50px" align="center" />
<listheader label="課程名稱" width="50px" align="center" />
<listheader label="時數" width="50px" align="center" />
<listheader label="人數" width="50px" align="center" />
<listheader label="班次" width="70px" align="center" />
<listheader label="內/外訓" width="70px" align="center" />
<listheader label="訓練目標與說明" width="70px" align="center" />
<listheader label="備註" width="70" align="center" />
<listheader label="填寫日期" width="70" align="center" />
<listheader label="發送日期" width="70" align="center" />
</listhead>
<template name="model">
<listitem self="@{each=ttrc}" value="${each }">
<listcell />
<listcell label="@{ttrc.personLevel}" />
<listcell label="@{ttrc.title}" />
<listcell label="@{ttrc.courseName}" />
<listcell label="@{ttrc.hours}" />
<listcell label="@{ttrc.numberOfPerson}" />
<listcell label="@{ttrc.orderOfClasses}" />
<listcell label="@{ttrc.internalExternalTraining}" />
<listcell label="@{ttrc.targetDescription}" />
<listcell label="@{ttrc.remark}" />
<listcell label="@{ttrc.insertDate}"/>
<listcell style="@{ttrc.sendDate}" />
</listitem>
</template>
</listbox>
</div>
</div>
</window>
</zk>
#4
<div height="500px">
<listbox id="listTRC" model="@{listTrTrainReqColl}" vflex="true" width="980px" >
<listhead sizable="true">
<listheader label="階層" width="300px" align="center" />
</listhead>
<listitem self="@{each=ttrc}" value="${ttrc}">
<listcell label="${ttrc.id}" />
</listitem>
</listbox>
</div>
#5
你那个Controller注解没用的,去掉吧。 我贴下我的代码, 你参考下,
首先我的Controller继承了SelectorComposer 跟你那个是否有区别我不太确定, 老早的东西了,忘记了。
我是这样注入页面元素的, 变量名就是页面的id, 这个id我看到你后来也加上上去了。 我不知道你不加@Wire注解能不能跟页面元素对应上,这个你确认下。
这里代码很清楚, serviec查询一页数据, 跟你的基本一样。
页面:
跟你不太一样, 你可以参考改下,看是否有用
这是
首先我的Controller继承了SelectorComposer 跟你那个是否有区别我不太确定, 老早的东西了,忘记了。
@Wire private Listbox adspList;
@Wire private Paging pager;
@Wire
private Datebox syncDateBox;
我是这样注入页面元素的, 变量名就是页面的id, 这个id我看到你后来也加上上去了。 我不知道你不加@Wire注解能不能跟页面元素对应上,这个你确认下。
Pagination<Adspace> page = adspaceService.getOnePage(adSpc, curr);
ListModelList<Adspace> model = new ListModelList<Adspace>(page.getResult());
model.setMultiple(true);
adspList.setModel(model);
这里代码很清楚, serviec查询一页数据, 跟你的基本一样。
页面:
<listbox id="adspList" checkmark="true">
<listhead>
<listheader label="id" />
<listheader label="编号" sort="auto" />
</listhead>
<template name="model">
<listitem value="${each }">
<listcell label="${each.id }"></listcell>
<listcell label="${each.adZoneId }"></listcell>
</listitem>
</template>
</listbox>
<paging id="pager" activePage="0" />
跟你不太一样, 你可以参考改下,看是否有用
这是
#6
顶
#7
OK,可以了,谢谢,以后有问题我直接发帖请你回答好了!
#8
OK 非常感谢,对了还有个问题。
我设置了 checkmark="true"
我想实现批量选中删除,我后台如何获取到选中行呢?
#9
Listbox 有个getSelectedItems方法, 返回选中Listitem的集合, 如何没有勾选则集合为空
#10
thx,这个功能也搞定了!
#11
求助:向页面注入两种model,一种是list(实体),另一种list(String)。前台listbox当中有嵌套,分别用model初始化listitem。要如何实现??
我尝试如下没能成功:
原因:报错没有唯一的ID。
在里面<listbox>外添加<window>,页面没有报错,控制台报 空指针。list<String>没有与页面中对应。
我尝试如下没能成功:
原因:报错没有唯一的ID。
在里面<listbox>外添加<window>,页面没有报错,控制台报 空指针。list<String>没有与页面中对应。