ZK How to create a container in readonly mode (layout of the Div window)?

I am developing a ZK application that contains several roles. For the role of "Guest" I have to do all the components in readonly mode. So how to create a container (div window layout) in readonly mode in a ZK application?

+4
source share
2 answers

Yes, you can do this in MVVM too.

So, let's start from the beginning.
You need to connect some components, as in the answer you repeat :

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

Secondly, the implementation of AfterCompose to disable and Init to check the status.
In regular MVVM, you almost never need to use it @AfterCompose, but when you need to connect to such solutions, you will need it.

@Init
public void init() {
    disable = checkForGuest();
}

 /**
 * This method will launch when all components are created.
 * @param view to wire the components
 */
@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
    Selectors.wireComponents(view, this, false); // after this your private fields are wired.
    disableAll(disable);
}

private void disableAll(boolean disableStatus){
   for(Disable d : allToDisable) {
       d.setDisabled(disableStatus);
   }
}

, , @Init , AfterCompose.

:

, @AfterCompose. disable zul:

 <checkbox disabled="@load(yourValue or vm.disabled)"/>

, 1 2 , .

:

, , .
.

@AfterCompose
public void afterCompose(@SelectorParam("*") Collection<Component> allToDisable, @ContextParam(ContextType.BINDER)Binder binder) {
    for(Component comp : allToDisable) {
        if (comp instanceof Disable) {
            ((Disable)comp).setDisabled(disable);
            binder.removeBindings(comp, "disabled");
        }
    }
} 

** : ** , @Wire("disable") , ZK Fiddle.
, , @Wire, @SelectorParam, , Selectors.
@Wire @SelectorParam, .
, , disable, , .
, -, disabled .
, Binder @ContextParam.
, binder.removeBindings(Component, String);.
, binder.removeBindings(Component);, .

( , Textbox, )

+2

enabled/disabled. "" , .

/ , , textbox, combobox,.... disabled, true, .

MVVM , :

<zk>
  <window title="Enable/Disable" border="normal" width="600px"
        apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('pkg$.TestVM')" >
        <hbox>
            <vbox>
                 <checkbox label='readonly' checked='@bind(vm.readonly)' />
            </vbox>
            <div>
                 <textbox value='test' disabled='@bind(vm.readonly)' />
                 <checkbox label='test' disabled='@bind(vm.readonly)' />
            </div>
        </hbox>
    </window>
</zk>

.

+1

Source: https://habr.com/ru/post/1619175/


All Articles