-
FEATURED COMPONENTS
First time here? Check out the FAQ!
<toolbarbutton label="${labels.email.search.btn.details}" disabled="@load(empty vm.selected)" image="/images/buttons/details.png" onClick="@command('doViewDetails')" />
@Command public void doViewDetails() { Executions.getCurrent().sendRedirect( "account/details-account.zul?username=" + getSelected().getUsername(), "_blank"); }
<toolbarbutton image="/images/buttons/reset.png" disabled="@load(empty vm.selected)" label="${labels.account.search.reset}" onClick="@command('doReset')" />
@Command @NotifyChange({ "accounts", "selected" }) public void doReset() { Messagebox.show("Do you want to reset the password for the account " + selected.getUsername() + "?", new Messagebox.Button[] { Messagebox.Button.NO, Messagebox.Button.YES }, new EventListener<Messagebox.ClickEvent>() { public void onEvent(Messagebox.ClickEvent event) { if (Messagebox.Button.YES.equals(event.getButton())) { try { accountBean.resetAccountPassword(selected.getUsername()); Messagebox.show("Account password for " + selected.getUsername() + " has been reset successfully.", "Info", Messagebox.OK, Messagebox.INFORMATION); } catch (WebException e) { LOGGER.error("Error resetting the account password", e); Messagebox.show("Error while resetting the password for account " + selected.getUsername() + "\n" + e.getMessage(), "Error", Messagebox.OK, Messagebox.ERROR); } } } }); }
accountBean.resetAccountPassword(selected.getUsername());
hi
is't possible to provide a runnable sample code, it will help debug
If you can't provide runnable sample code, I am guessing:
1. in doReset method, when MVVM invoke it, it only shows Messagebox, finish command
2. when you click messagebox button, it execute Messagebox event, but now, not invoked from MVVM, MVVM command finished, so selected may be null or not
you could try to add local Final field in doReset
public void doReset() { final Object selededItem = xxx; ... }
not sure if it will work or not
after study MVVM doc, I found one link may helper, refer to Show Dialog
Hi,
thanks for the link, I have used it to refactor the code and use a new modal window instead of using the Messagebox.
However, the problem was related to the fact that I was notifying changes to selected and accounts (list of entities).
Now for example I have changed doReset like this:
@Command @NotifyChange({ "messageBox", "messageBoxEvent" }) public void doReset()
And then the modal window, on the OK button, it fires this command:
@Command @NotifyChange({ "accounts", "selected", "messageBox", "messageBoxEvent" }) public void doConfirmOk() { if ("reset".equalsIgnoreCase(messageBoxEvent)) { resetPassword(); ...
In this way the selected item and the messagebox are working correctly.
Asked: 2012-06-04 09:45:12 +0800
Seen: 505 times
Last updated: Jun 06 '12