ZK Disbale Div,Window,Layout Component?

淺唱寂寞╮ 提交于 2019-12-09 23:54:12

问题


I am using ZK Framework in my project i have plenty of other component inside a div or Window Component ,Can any one tell me how can i disable a Div or Window component in certain condition.As i checked there is no any disable attribute for these components.

Any other way we can i disable a Div or Window otherwise i have to disable each component inside the Div or Window or Layout


回答1:


Here a very easy way to disable all components that implement the
Disable interface.

@Wire("disable")
private List<Disable> allToDisable;

private disableAll(List<Disable> list){
   for(Disable d : list){
       d.setDisabled(true);
   }
}

You could edit the path of @Wire to fit your needs,
use a method of Selectors or any other method
that takes a zk selector path. Just let it end with
"disable", so it should select every Component that
implements the interface.




回答2:


I think there is no simple way, I would try something like this (found this on google but I remember doing something similar on my last project)

public static void disableComponents( AbstractComponent pComponent ) {

  for( Object o : pComponent.getChildren() ) {

     AbstractComponent ac = ( AbstractComponent ) o;

     try {
        Method m = ac.getClass().getMethod( "setDisabled", Boolean.TYPE );
        m.invoke( ac, true );
     } catch( Exception e ) {
     }

     List children = ac.getChildren();
     if( children != null ) {
        disableComponents( ac );
     }
  }

}




回答3:


We can improve Gatekeeper's (May 16 '13 at 9:22) solution adding the condition "if". if (ac instanceof Disable) { --- code -- }

public static void disableComponents( AbstractComponent pComponent ) {
    for( Object o : pComponent.getChildren() ) {
        AbstractComponent ac = ( AbstractComponent ) o;
        try {
            if (ac instanceof Disable) {
                Method m = ac.getClass().getMethod("setDisabled", Boolean.TYPE);
                m.invoke(ac, true);
            }
        } catch( Exception e ) {
            e.printStackTrace();
        }

        List children = ac.getChildren();
        if( children != null ) {
            disableComponents( ac );
        }
    }
}


来源:https://stackoverflow.com/questions/16583098/zk-disbale-div-window-layout-component

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!