English 中文(简体)
How to use ZK getFellow() method?
原标题:
  • 时间:2010-10-20 17:42:26
  •  标签:
  • java
  • zk

I am passing a bunch of tabs from a zul file to a java file like so:

tabs.zul

<tabs>
  <tab id="tab1" label="Tab1"> </tab>
  <tab id="tab2" label="Tab2"> </tab>
</tabs>
<zscript>
  testTabs = new TestTabs();
  Tab[] tabs = {tab1, tab2}
  testTabs.registerTabs(tabs)
</zscript>

TestTabs.java

public class TestTabs {
  ....
  private HashMap<String,Tab> tabMap;

    void registerTabs (Tab[] tabs) {
      this.tabMap = new HashMap<String,Tab>();
      for (Tab t: tabs) {
        this.tabMap.put(t.getId(),t);
      }
    }

   if(condition) {
     tabMap.get("tab1").setVisible(true);
     tabMap.get("tab2").setVisible(true);
   }  

}

Now, I guess using Hashmaps to access a tab is a roundabout way. Using a getFellow(String id) method to access a tab would be much simpler, right ? But, I am not sure how to implement that. Can someone help me with this?

Thanks, Sony

最佳回答

There are several ways to do that:

  1. Extend org.zkoss.zul.Window in your class and link it in your zul file like this:
    <window id="myWindow" use="package.to.your.ClassThatExtendsWindow">
    <!-- your tabs go here -->
    </window>
    Then in your class you can use Tab tab1 = (Tab) this.getFellow("tab1");
  2. Extend org.zkoss.zk.ui.util.GenericForwardComposer and link it in your zul like this:
    <window id="myWindow" apply="package.to.your.ClassThatExtendsGenericForwardComposer">
    <!-- your tabs go here -->
    </window>
    Then in your class declare private Tab tab1; and you can use it right away.

Note the differente bewtween the use and apply keywords. If you use the second approach, make sure that the name of your variable matches the id of your component ("tab1").

问题回答

The getFellow() method can be used on ZK s component. Users can get access the component by it s ID

myWindow.getFellow("label_1");

if you re using ZK MVC way on your application.

you can save your **"composer" into the desktop, then you can access any part of the page.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签