Managing ZK Tabpanels Scenario:

I am working on  a Java/ZK Subscriber Management application. There are 2 tabs: Basic Info and STB-VC. The first one for creating a new subscriber and the second one for assigning STB/VC(Set-top box and viewing card). 

I am trying to achieve/ensure Someone can only click/use the second tabpanel only after creating a new subscriber and not before. 



I have the following code which does that. Is there a better way to achieve the task?

Subscriber.zul

    &lt;window id="main" title="" border="normal"
        apply="com.sss.composer.SubscriberComposer" width="100%"
        height="100%"&gt;

        &lt;div align="right"&gt;
            &lt;image id="home" src="/img/home.png" width="30px" /&gt;
            &lt;image id="logout" src="/img/logout.png" width="30px" /&gt;
        &lt;/div&gt;

        &lt;tabbox id="tb"&gt;
            &lt;tabs id="tabs"&gt;
                &lt;tab id="A" label="Basic Info" /&gt;
                &lt;tab id="B" label="STB-VC" /&gt;
            &lt;/tabs&gt;
            &lt;tabpanels&gt;
                &lt;tabpanel id="basic"&gt;
                    &lt;!--  Subscriber Creation Form --&gt;
                    &lt;include id="inc1" src="basic.zul"&gt;&lt;/include&gt;
                &lt;/tabpanel&gt;
                &lt;tabpanel id="stbvc"&gt;
                    &lt;include id="inc2"&gt;&lt;/include&gt;
                &lt;/tabpanel&gt;
                &lt;tabpanel&gt;
                    &lt;label id="x3" value="x3"&gt;&lt;/label&gt;
                &lt;/tabpanel&gt;
                &lt;tabpanel&gt;
                    &lt;label id="x4" value="x4"&gt;&lt;/label&gt;

                &lt;tabpanel&gt;
                    &lt;label id="x5" value="x5"&gt;&lt;/label&gt;
                &lt;/tabpanel&gt;
            &lt;/tabpanels&gt;
        &lt;/tabbox&gt;
    &lt;/window&gt;


SubscriberComposer

public void onSelect$tb(ForwardEvent fe) {

        try {
            Object o = fe.getOrigin().getTarget();

            if (o instanceof Tab) {

                Tab t = (Tab) o;

                Tabpanel tp = t.getLinkedPanel();

                tp.invalidate();

                if ((tp.getId().equals("stbvc") &amp;&amp; (Sessions.getCurrent()
                        .getAttribute("subscriber") == null))) {

                    Messagebox.show(
                            "Create Subscriber first,then assign STB/VC!",
                            "Warning", Messagebox.OK, Messagebox.INFORMATION);

                    tb.setSelectedPanel(basic);

                } else {

                    inc2.setSrc("stbvc.zul");

                    System.out.println("Subscriber ID set in session...");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
Your code could be improved by using a guard clause which reduces horizontal spacing.  



Names of variables shouldn't be shortened. Tabpanel tp could be easily refactored to a more meaningful Tabpanel tabPanel. Increasing readability helps Sam the Maintainer to the maintaining job.  



You should catch specific exceptions, not just Exception. Also you should enclose only the code which can throw an exception.  



Object target = fe.getOrigin().getTarget();

if (!(target instanceof Tab)) { return; }

Tab tab = (Tab) target ;

Tabpanel tabPanel = tab.getLinkedPanel();

tabPanel.invalidate();

if ((tabPanel.getId().equals("stbvc") &amp;&amp; (Sessions.getCurrent()
        .getAttribute("subscriber") == null))) {

    Messagebox.show(
            "Create Subscriber first,then assign STB/VC!",
            "Warning", Messagebox.OK, Messagebox.INFORMATION);

    tabPanel.setSelectedPanel(basic);

} else {

    inc2.setSrc("stbvc.zul");

    System.out.println("Subscriber ID set in session...");
}