0

onUpload and @NotifyChange

asked 2012-04-27 14:51:04 +0800

kjir gravatar image kjir
24

Hi all,
I am trying to implement image uploading for a form in my application. Everything works except a small detail: when I call a method on my ViewModel, it doesn't seem to trigger the @NotifyChange behaviour I am expecting. Here is the relevant part of my zul:

<groupbox id="insertForm"
	form="@id('logo') @load(vm.selected) @save(vm.selected, before='update') @save(vm.selected, before='delete')">
	<caption label="Insert/edit Logo" />
	Image:
	<textbox id="strpath" readonly="true" value="@load(logo.path)" />
	<button id="path" upload="true"
		onUpload="vm.setImage(event.media)" label="Upload image" />
         [...]
</groupbox>

And here is the relevant part of setImage:


@NotifyChange("selected")
public void setImage(Media file) {
    if (file instanceof Image) {
        this.image = (Image)file;
        getSelected().setPath("/path/to/images/" + image.getName());
    }
}

Now I would expect the textbox to display my new path as soon as the file is uploaded and the function is called, but it doesn't seem to be working... What am I missing? I am pretty new to ZK and the MVVM pattern, so I probably went wrong somewhere... Any help would be appreciated!

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2012-04-28 06:15:06 +0800

Matze2 gravatar image Matze2
773 7

I guess you need to use ZK6 command not inline Java for your event handler. Something like this:

onUpload="@command('updateImage')"

@Command
@NotifyChange(...)
public void updateImage(@ContextParam(ContextType.TRIGGER_EVENT) UploadEvent event) {
...
}

link publish delete flag offensive edit

answered 2012-04-28 12:07:00 +0800

kjir gravatar image kjir
24

There is no ContextType.TRIGGER_EVENT, but I did with ContextType.BIND_CONTEXT and then ctx.getTriggerEvent() and it works. Thank you!

link publish delete flag offensive edit

answered 2012-04-28 21:03:07 +0800

Matze2 gravatar image Matze2
773 7

Yes, sorry. It will be in 6.0.1.

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2012-04-27 14:51:04 +0800

Seen: 278 times

Last updated: Apr 28 '12

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