Actually it's in the specs that the button is not visible when not
applicable. So I can't use your proposed solution. However, I solved it
as follows:
add(new Button(edit) {
private static final long serialVersionUID =
5348615260629883659L;
private Boolean localVisibleFlag;
@Override
public void onSubmit() {
String username =
((AppAuthenticatedWebSession)getSession()).getUsername();
ARF arf = arfModel.getObject();
if (arf.getEditor() == null) {
arf.setEditor(username);
arfService.save(arf);
}
localVisibleFlag = null;
}
@Override
public boolean isVisible() {
if (localVisibleFlag == null) {
String editor =
arfModel.getObject().getEditor();
if (editor == null) {
localVisibleFlag = true;
return true;
}
localVisibleFlag = false;
return false;
} else {
return localVisibleFlag;
}
}
});
Works like a charm.
Cheers, Jonck
-Original Message-
From: Jeremy Thomerson [mailto:jer...@wickettraining.com]
Sent: woensdag 23 december 2009 17:14
To: users@wicket.apache.org
Subject: Re: Multi-user environment problem
Override isEnabled instead. That way it is visible, even after being
clicked when the other person clicked it first. You may have to add
some logic in the onClick that says oops - already in use.
--
Jeremy Thomerson
http://www.wickettraining.com
On Wed, Dec 23, 2009 at 9:46 AM, Kogel, Jonck-van-der
jonck-van-der.ko...@bmw.nl wrote:
Hi,
I'm having a problem with a multi-user environment. I have a form,
which has an edit button. When a user presses the edit button, I write
to the database that this current user is editing the form. So when
another user comes along and wants to edit it, he gets the message
that the form cannot be edited because it's locked by another user.
This works fine when user A loads the form, presses the edit button
and after that user B comes along. However, if the process is: user A
comes along and loads the form, user B loads the same form, then user
A presses the edit button and after that user B presses it. Then I get
an unexpected runtimeexception and the message:
WicketMessage: Submit Button topBar:edit (path=arfForm:topBar:edit) is
not visible
Now this obviously has to do with the way I'm determining whether or
not this button should be visible. What I did is extend the Button
class and override the isVisible method. Here I check whether there is
no editor, if so, the button should be visible so the current user can
become the editor. However, since in this situation, user B became the
editor while this user had already loaded the form, the button is no
longer valid for user A but he already has it on his screen. I thought
to check this in the onSubmit method and retrieve the persisted object
and check if nothing had changed in the meantime, but apparently
Wicket checks whether this button should have been visible in the
first place. And since I use LoadableDetachableModel as the underlying
model (arfModel) the updated object is retrieved and Wicket detects
that the isVisible method returns false and throws an error that I'm
trying to call the onSubmit method.
Does anyone know of an elegant solution for this problem? Please see
below for my implementation of the edit button.
Thanks, Jonck
add(new Button(edit) {
@Override
public void onSubmit() {
String username =
((AppAuthenticatedWebSession)getSession()).getUsername();
ARF currentArf = arfModel.getObject();
ARF persistedArf = arfService.load(currentArf.getId());
if (persistedArf.getEditor() == null ||
persistedArf.getEditor().equals(username)) {
currentArf.setEditor(username);
arfService.save(currentArf);
}
}
@Override
public boolean isVisible() {
String editor = arfModel.getObject().getEditor(); if (editor ==
null) {
return true;
}
return false;
}
});
-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org