0

我有一个带有 ListModel 的列表框。我在 doAfterCompose 上设置模型,然后从计时器组件更新模型。列表框的每一列都有一个排序比较器。问题是,当对列进行排序(升序/降序)然后刷新事件添加一行数据时,数据将作为行的最后一个元素附加,而不是根据所选列排序。如何添加一行然后自动排序?

日志.zul

<?init class="AuthenticationInit"?>
<zk>
<zscript>
<![CDATA[
import java.util.Comparator;
import com.akarprima.dao.model.JobStatus;
import com.akarprima.util.JobStatusComparator;
Comparator nameAsc = new JobStatusComparator(true, JobStatusComparator.NAME);
Comparator nameDsc = new JobStatusComparator(false, JobStatusComparator.NAME);
Comparator dateAsc = new JobStatusComparator(true, JobStatusComparator.DATE);
Comparator dateDsc = new JobStatusComparator(false, JobStatusComparator.DATE);
Comparator sessionAsc = new JobStatusComparator(true, JobStatusComparator.SESSION);
Comparator sessionDsc = new JobStatusComparator(false, JobStatusComparator.SESSION);
Comparator sTimeAsc = new JobStatusComparator(true, JobStatusComparator.START_TIME);
Comparator sTimeDsc = new JobStatusComparator(false, JobStatusComparator.START_TIME);
Comparator eTimeAsc = new JobStatusComparator(true, JobStatusComparator.END_TIME);
Comparator eTimeDsc = new JobStatusComparator(false, JobStatusComparator.END_TIME);
Comparator durationTimeAsc = new JobStatusComparator(true, JobStatusComparator.DURATION);
Comparator durationTimeDsc = new JobStatusComparator(false, JobStatusComparator.DURATION);
   ]]>
</zscript>
<window border="none"
    apply="JobLogController">
    <label id="message" />
    <listbox id="jobLog" height="100%" sizedByContent="true"
        span="true">
        <listhead>
            <listheader label="No" />
            <listheader label="Date" sortAscending="${dateAsc}"
                sortDescending="${dateDsc}" />
            <listheader label="Session"
                sortAscending="${sessionAsc}" sortDescending="${sessionDsc}" />
            <listheader label="Job Name" sortAscending="${nameAsc}"
                sortDescending="${nameDsc}" sortDirection="ascending" />
            <listheader label="Start" sortAscending="${sTimeAsc}"
                sortDescending="${sTimeDsc}" />
            <listheader label="Finish" sortAscending="${eTimeAsc}"
                sortDescending="${eTimeDsc}" />
            <listheader label="Running Time"
                sortAscending="${durationTimeAsc}"
                sortDescending="${durationTimeDsc}" />
        </listhead>
        <template name="model">
            <listitem>
                <listcell label="${forEachStatus.index + 1}" />
                <listcell label="${each.value.date}" />
                <listcell label="${each.value.session}" />
                <listcell label="${each.value.jobName}" />
                <listcell label="${each.value.startTime}" />
                <listcell label="${each.value.endTime}" />
                <listcell label="${each.value.duration}" />
            </listitem>
        </template>
    </listbox>
    <timer id="timer" delay="5000" repeats="true" />
</window>
   </zk>

JobLogController.java

package com.akarprima.idx.controller.daily;

public class JobLogController extends SelectorComposer<Component>
{
    private static final long serialVersionUID = 4463081939576759090L;
    AppJobStatusDAO ajdao = new AppJobStatusDAO();

    @Wire
    private Listbox jobLog;

    private ListModelMap<String, JobStatus> jd = new ListModelMap<String, JobStatus>();

    @Override
    public void doAfterCompose(Component comp) throws Exception
    {
        super.doAfterCompose(comp);
        jobLog.setModel(jd);
        refresh();
    }

    @Listen("onTimer = timer")
    public void refresh()
    {
        AppUtils.compareAddMap(jd, ajdao.getJobLogDailyMap());
    }
}
4

0 回答 0