0

get selected item from listbox and pass to another window/modal listbox

asked 2016-03-18 09:55:56 +0800

Fahmy gravatar image Fahmy
3 1

updated 2016-03-18 10:05:53 +0800

Hello everyone, I really am new with both zk and java, and just recently learn to show data from database to listbox.

I had no idea to do this. So sorry if the question is not good.

So I want to show details according to '@bind(terpilih.aktivitas)' of selected item from listbox in the main zul to another zul/windowpopup(monitoringPopUp.zul) listbox by clicking the list/item and then click toolbar button with command 'detaildata'.

Here is my main zul code:

<window title="Aktivitas Monitoring" id="WindowUser" width="100%" border="normal"  apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('com.swamedia.soki.webui.monitoring.MonitoringCtrl')">
<groupbox mold="3d" contentStyle="max-height:350px; overflow:auto;">
    <caption label="Hasil Monitoring">
            <hbox>
                <toolbar>
                    <toolbarbutton tooltiptext="Lihat Detail"
                        onClick="@command('detaildata')" />
                </toolbar>
            </hbox>
    </caption>
<listbox id="testListbox" mold="paging" model="@bind(vm.monitorList)" emptyMessage="Tidak ada data untuk ditampilkan" selectedItem="@bind(vm.selectedMonitor)" PageSize="5" pagingPosition="both">
    <listhead>
        <listheader label="Tanggal" width="8%" />
        <listheader label="Waktu" width="8%" />
        <listheader label="Aktivitas" width="25%"/>
        <listheader label="Hasil Monitoring" />
        <listheader label="Status" width="5%"/>
        <listheader label="Keterangan" />
    </listhead>
    <template name="model" var="terpilih">
        <listitem>
            <listcell label="@bind(terpilih.tgl)"></listcell>
            <listcell label="@bind(terpilih.danll)"></listcell>
            <listcell label="@bind(terpilih.aktivitas)"></listcell>
            <listcell label="@bind(terpilih.hasil)"></listcell>
            <listcell label="@bind(terpilih.status)" style="text-align:center;"></listcell>
            <listcell label="@bind(terpilih.keterangan)"></listcell>
        </listitem>
    </template>
</listbox>
</groupbox></window>

This is my controller code:

package com.swamedia.soki.webui.monitoring;

import com.swamedia.soki.backend.model.Monitoring;
import com.swamedia.soki.backend.model.SecUser;
import com.swamedia.soki.backend.dao.MonitoringDAO;
import com.swamedia.soki.backend.dao.impl.MonitoringDAOImpl;
import com.swamedia.soki.webui.util.GFCBaseCtrl;

public class MonitoringCtrl extends GFCBaseCtrl {

    private List<Monitoring> monitorList;

    private Monitoring selectedMonitor;

    @Wire("#WindowUserPopUp")
    Window WindowUserPopUp;

    @Wire("#WindowUser")
    Window WindowUser;

    @WireVariable
    private MonitoringDAO monitorService;

    @Init
    public void initSetup(@ContextParam(ContextType.VIEW) Component view) {
        Selectors.wireComponents(view, this, false);
        monitorList = monitorService.findAll();
    }

    public void setMonitorList(List<Monitoring> monitorList) {
        this.monitorList = monitorList;
    }

    public List<Monitoring> getMonitorList(){
        return monitorList;
    }

    public void setSelectedMonitor(Monitoring selectedMonitor) {
        this.selectedMonitor = selectedMonitor;
    }
    public Monitoring getSelectedMonitor() {
        return selectedMonitor;
    }

    @Command
    public void keluar() {
        WindowUserPopUp.detach();
    }

    @Command
    public void detaildata(){
        if(selectedMonitor == null){
        Messagebox.show("No data selected!", "Warning", Messagebox.OK, Messagebox.EXCLAMATION);
        }else{
        Window window = (Window)Executions.createComponents(
                "/WEB-INF/pages/monitoring/monitoringPopUp.zul", this.self, args);
        window.setClosable(true);
        window.doModal();
        }
    }
}

And this is my popup zul (monitoringPopUp.zul):

<window title="Detail Data Monitoring" id="WindowUserPopUp" width="900px" border="normal" apply="org.zkoss.bind.BindComposer"
closable="true" viewModel="@id('vm') @init('com.swamedia.soki.webui.monitoring.MonitoringPopup')">
<listbox mold="paging" model="" selectedItem="" PageSize="10">
    <listhead>
            <listheader label="Tanggal" width="9%"/>
            <listheader label="Waktu" width="8%"/>
            <listheader label="Aktivitas" width="25%"/>
            <listheader label="Hasil Monitoring"/>
            <listheader label="Status" width="6%"/>
            <listheader label="Keterangan"/>
    </listhead>
    <template name="model" var="terpilih">
        <listitem>
            <listcell label="*this is where i want to show tgl value from selected item"></listcell>
            <listcell label="*this is where i want to show danll value from selected item"></listcell>
            <listcell label="*this is where i want to show aktivitas value from selected item"></listcell>
            <listcell label="*this is where i want to show hasil value from selected item"></listcell>
            <listcell label="*this is where i want to show status value from selected item"></listcell>
            <listcell label="*this is where i want to show keterangan value from selected item"></listcell>
        </listitem>
    </template>
</listbox>
</window>

Thanks....

delete flag offensive retag edit

Comments

to @Darksu, thank you so much for your answer, i can't post comment at your answer since i don't have enough point, I'll read your link.. :)

Fahmy ( 2016-03-18 10:11:54 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-03-18 10:06:39 +0800

Darksu gravatar image Darksu
1991 1 4

Hello Fahmy,

A very good example that you can use, can be found at the following url:

http://emrpms.blogspot.gr/2012/06/mvvm-modal-windowpass-parameter-and.html

Best Regards,

Darksu

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2016-03-18 09:55:56 +0800

Seen: 39 times

Last updated: Mar 18 '16

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More