1

Initialisation of components with visible attribute

asked 2014-02-10 16:54:57 +0800

salman1 gravatar image salman1 flag of United Kingdom
40 4

updated 2014-02-10 16:55:33 +0800

This problem is driving me insane, I've spent over a week trying to figure it out. Just wondering if its a bug or something I'm doing incorrectly. Using zk 7.0. I have a sample zul as follows:

<hbox apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('xi.search.acquisition.upload.RunVM')" visible="@bind(vm.runUploadVisibility)">
<button upload="true,maxsize=-1,multiple=true,native" onUpload="@global-command('doUpload')"/>
</hbox>

In summary, the visibility of the hbox is determined by data binding a value. This area should be invisible until some user action (e.g. another button click) then the contents of the hbox should become visible (in this case the upload button).

I can get this to work i.e. initially runUploadVisibility is false in the VM then after a user action it is set to true, the hbox and button appear. However, when I click the button, nothing happens at all.

If runUploadVisibility is set to true in the VM (i.e. initially the hbox and all children are visible) and i click the button then the button produces an upload dialog as expected.

My question is, if visibility is false initially in the VM, does the upload button miss some initialisation code? Is this the reason it doesn't work in the above scenario?

delete flag offensive retag edit

4 Answers

Sort by ยป oldest newest most voted
-1

answered 2014-02-11 16:05:00 +0800

salman1 gravatar image salman1 flag of United Kingdom
40 4

Thanks for your responses. @Barracus, viewmodel code below. @Chilliworld, I used @load to start with then moved onto @bind in my frantic attempts to try and get it working. Have also tried local commands. The first hbox, has a binder attached to it so that the button can make the next hbox visible/invisible. Code below

<hbox apply="org.zkoss.bind.BindComposer">
       <button label="New Upload" onClick="@global-command('showNewRunUpload')" />
</hbox>
...


<hbox apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('xi.search.acquisition.upload.RunVM')" visible="@load(vm.runUploadVisibility)">

        <button upload="true" onUpload="@command('doUpload')" onClick="@command('printSomething')"/>
</hbox>

The viewmodel:

public class RunVM {
boolean runUploadVisibility = false;  // getters and setters omitted in this example for brevity 
....

@GlobalCommand 
@NotifyChange("runUploadVisibility")
public void showNewRunUpload(){
    runUploadVisibility = !runUploadVisibility;
}


@Command("printSomething")
public void printSomething(){
    System.out.println("printing");

}

@Command("doUpload")
@NotifyChange({"runs", "selectedRuns"})
public void doUpload(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx){
...
}//end doUpload

....
}// end class

Command 'printSomething()' always executes with the onClick event. The onUpload event doesn't register for some reason when runUploadVisibility = 'false' initially. onUpload only seems to work when runUploadVisibility is first set to true in the view model.

link publish delete flag offensive edit
0

answered 2014-02-10 18:12:40 +0800

barracus gravatar image barracus flag of Italy
38 4

Could you post code from RunVM viewmodel?

Are you using NotifyChange above doUpload command?

link publish delete flag offensive edit
0

answered 2014-02-10 19:42:57 +0800

chillworld gravatar image chillworld flag of Belgium
5322 4 9
https://github.com/chillw...

updated 2014-02-10 19:44:04 +0800

First, do @load for the visibility. @bind = @load + @save. I don't think you need the @save there.

Second, @global-command? Try just @command.

so try refactor to this :

<hbox apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('xi.search.acquisition.upload.RunVM')" visible="@load(vm.runUploadVisibility)">
  <button upload="true" onUpload="@command('doUpload')"/>
</hbox>

In the vm :

@Command
public void doUpload(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) {
    //your code here.
}
link publish delete flag offensive edit
0

answered 2014-02-11 18:41:26 +0800

chillworld gravatar image chillworld flag of Belgium
5322 4 9
https://github.com/chillw...

wow oke, now I get some more. You use multiple bindcomposers. (and one have no class assigned)

Set your bindcomposer to the highest element (like window or something) so you have this:

<window apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('xi.search.acquisition.upload.RunVM')">

Then you have only one viewmodel that reacts for your whole zul. (now you viewmodel reacts only for the Hbox and what's inside)

Then add mine first answer to it and normally you should have no problems.

Greetz chill.

link publish delete flag offensive edit

Comments

My idea is to have many view models on the same zul page. So there would be another hbox that appears/disappears with its own visibility binding. The idea of the top level Binder (not attached to a particular view model) is to allow buttons at the top of the zul call global commands for visibility

salman1 ( 2014-02-12 13:02:19 +0800 )edit

Oke I get your point. Just a way of seeing things. Did you try add logging in the java code of the global-command? Check if it's triggered (maybe the notifyChanged isn't working)

chillworld ( 2014-02-12 13:20:14 +0800 )edit

I used the ZK Bind Tracker tool (http://books.zkoss.org/wiki/SmallTalks/2013/June/ZKBindingTracker-AChrome_Extension) but the command is just not invoked on the server side. We are definitely thinking along the same lines!

salman1 ( 2014-02-13 16:14:59 +0800 )edit

did you try to use an @command and in the command call BindUtils.postGlobalComand ?

chillworld ( 2014-02-13 16:46:23 +0800 )edit

why call global command from within the @command? I only need the global command to set the visibility to true or false

salman1 ( 2014-02-13 16:52:46 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2014-02-10 16:54:57 +0800

Seen: 149 times

Last updated: Feb 11 '14

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More