问题
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