0

Error using script(solved)

asked 2013-02-20 18:20:58 +0800

nilsonhp gravatar image nilsonhp
123 3

updated 2013-02-22 17:06:17 +0800

Hi, everyone. I was having trouble to intercept tab selection, and I found this. I tried to implement Jimmy's solution exatly as it showed.

I create the composer, with the following code:

 package com.smartbiz.main.ui;

 import org.zkoss.zk.ui.event.Event;
 import org.zkoss.zk.ui.event.EventListener;
 import org.zkoss.zk.ui.event.ForwardEvent;
 import org.zkoss.zk.ui.util.GenericForwardComposer;
 import org.zkoss.zul.Messagebox;
 import org.zkoss.zul.Tab;


 public class AbstractTabComposer extends GenericForwardComposer {

/**
 * 
 */
private static final long serialVersionUID = 1L;

public void onSwitchTab(ForwardEvent event) throws InterruptedException {

    final Tab tab = (Tab) event.getOrigin().getTarget();
    Messagebox.show("Are you sure to leave?", "Exit", Messagebox.YES
            | Messagebox.NO, Messagebox.QUESTION, new EventListener() {

        public void onEvent(Event event) throws Exception {

            Integer evtName = ((Integer) event.getData()).intValue();

            if (Messagebox.YES == (evtName)) {
                tab.setSelected(true);
            } else if (Messagebox.NO == (evtName)) {
                // do nothing
            }

        }
    });

 }
}

Then, in my zul, i tried the script, as followed:

<zk xmlns:w="client">

 <script type="text/javascript"><![CDATA[
    function switchTab(notify, init){
        if (this.desktop && !init && notify)
            zAu.send(new zk.Event(this, 'onSwitchTab'));
        else
            this.$_sel(notify, init); //call the original method
    }
]]></script>
<window id="lineWindow" border="normal" width="100%" height="100%"
    sizable="false" mode="embedded" closable="true" minimizable="true"
    visible="true"
    apply="com.smartbiz.milksupply.ui.LineWindowController">

    <!--  Tabs on the left side (vertical) - MENU -->
    <tabbox id="tabboxVerticalMenu" height="100%" orient="vertical"
        apply="com.smartbiz.main.ui.AbstractTabComposer">

        <tabs id="tabsVerticalMenu" width="170px">
            <tab id="tabGetAll" w:_sel="switchTab"
                forward="onSwitchTab=onSwitchTab" />
            <!--                    <tab id="tabAdvancedSearch" visible="false"/> -->
            <tab id="tabInsert" w:_sel="switchTab"
                forward="onSwitchTab=onSwitchTab" />
            <tab id="tabViewDetails" visible="false" />
        </tabs>

        <tabpanels>

            <!-- Tabs content - MENU -->

            <!-- Tab content (Tab with id=tabGetAll) -->
            <tabpanel style="border:0">

                <div width="100%" align="center">

                    <!--                    Listbox that contains/show all lines registered -->

                    <groupbox mold="3d" closable="false">
                        <caption id="captionLineToSearch" />
                        <grid sclass="gridWidthWithGroupbox">

                            <columns>
                                <column width="32%" />
                                <column width="32%" />
                                <column width="36%" />
                            </columns>

                            <rows sclass="rowTransp">
                                <row>
                                    <hbox>
                                        <label id="labelSearchLine" />
                                        <combobox
                                            id="comboboxSearchLine" buttonVisible="false" />
                                    </hbox>
                                    <hbox>
                                        <label
                                            id="labelSearchProducer" />
                                        <combobox
                                            id="comboboxSearchProducer" buttonVisible="false" />
                                    </hbox>
                                    <hbox>
                                        <label id="labelSearchFarm" />
                                        <combobox
                                            id="comboboxSearchFarm" buttonVisible="false" />
                                    </hbox>
                                </row>

                                <row>
                                    <hbox />
                                    <hbox />
                                    <hbox style="float:right">
                                        <button id="buttonSearch"
                                            image="/view/resources/images/buttons/searchButton.png"
                                            sclass="otherButtons" />
                                        <button
                                            id="buttonClearSearch"
                                            image="/view/resources/images/buttons/clearSearchButton.png"
                                            sclass="otherButtons" />
                                    </hbox>
                                </row>

                            </rows>

                        </grid>
                    </groupbox>

                    <div style="text-align:left;">
                        <label id="labelSearchNotFound"
                            style="color:#CD5C5C;" visible="false" />
                    </div>

                    <div id="divSearchFound" visible="true"
                        height="15px" />

                    <groupbox mold="3d" closable="false">
                        <caption id="captionLineSearched" />

                        <grid id="gridProducer"
                            sclass="gridWidthWithGroupbox" width="802px" style="border:none"
                            height="270px">

                            <columns>
                                <column width="92%" />
                                <column width="4%" />
                                <column width="4%" />

                            </columns>

                            <rows id="rowsProducerGrid"
                                sclass="rowTransp">

                                <row id="rowListheader">

                                </row>

                            </rows>

                        </grid>

                    </groupbox>

                </div>

            </tabpanel>

            <!-- Tab content (Tab with id=tabAdvancedSearch) -->
            <!--            <tabpanel> -->

            <!--            </tabpanel> -->

            <tabpanel>

                <div id="divErrorToInsert" height="33px" />

                <lineComponentToInsert id="lineComponentToInsert" />

            </tabpanel>

            <tabpanel>

                <div id="divButtonsViewDetails" height="33px">
                    <button id="buttonDelete"
                        image="/view/resources/images/windowIcons/largeIcons/deleteLarge.png"
                        sclass="otherButtons" visible="false" style="float:right" />
                    <button id="buttonSave"
                        image="/view/resources/images/windowIcons/save.png"
                        sclass="otherButtons" visible="false" style="float:right" />
                    <button id="buttonEdit"
                        image="/view/resources/images/windowIcons/largeIcons/editLarge.png"
                        sclass="otherButtons" visible="false" style="float:right" />
                </div>

                <lineComponentViewDetails
                    id="lineComponentViewDetails" />

            </tabpanel>

        </tabpanels>

    </tabbox>

</window>
 </zk>

But using this, i can't access my window, because it says that the server could not complete my request, because switchTab is undefined.

I not familiar with the use of zk and script together. Can anyone help me in how can i solve the issue??

Thanks

Nilson

delete flag offensive retag edit

1 Answer

Sort by » oldest newest most voted
0

answered 2013-02-22 17:10:22 +0800

nilsonhp gravatar image nilsonhp
123 3

Ok, guys, i could not make it work the way it was, and i'm still don't know why.

After many tries, i was able to override de doClick_ method, and was able to intercept and confirm my change. Bellow is the code:

 {...
StringBuilder over = new StringBuilder();

    over.append("function switchTab(){");

    over.append("zAu.send(new zk.Event(this, 'onSwitchTab'));}");

    tabGetAll.setWidgetOverride("doClick_", over.toString());

    tabGetAll.addEventListener("onSwitchTab", new EventListener() {

        public void onEvent(Event event) throws Exception {

            String msg = "Tem certeza que deseja sair desta Tela? Os Dados serão Perdidos ";
            Messagebox.show(msg, "Sair", Messagebox.YES | Messagebox.NO,
                    Messagebox.QUESTION, new EventListener() {

                        public void onEvent(Event event) throws Exception {
                            Integer evtName = ((Integer) event.getData())
                                    .intValue();

                            if (Messagebox.YES == (evtName)) {
                                tabGetAll.setSelected(true);
                                goBackToTabGetAll();
                            }

                        }
                    });

        }
    });
  ...}

I put this code in my onCreate$Comp, and with it was able to solve my problem. If anyone know another ways to do it, i would apreciate.

Thanks

Nilson

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: 2013-02-20 18:20:58 +0800

Seen: 14 times

Last updated: Feb 22 '13

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