You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Vignesh Palanisamy <vi...@mcruncher.com> on 2013/07/04 03:30:44 UTC
ConfirmAjaxFallbackLink with LoadableDetachableModel
Hi all,
I have a ConfirmAjaxFallbackLink which is use to display confirmation
dialog, when a user attempts to delete an item in a datatable.
public abstract class ConfirmAjaxFallbackLink extends AjaxFallbackLink
{
private String confirmMessage;
private IModel<String> confirmMessageModel;
public ConfirmAjaxFallbackLink(String id, String confirmMessage)
{
super(id);
this.confirmMessage = confirmMessage;
}
public ConfirmAjaxFallbackLink(String id, IModel<String> messageModel)
{
super(id, messageModel);
this.confirmMessageModel = messageModel;
}
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
{
super.updateAjaxAttributes(attributes);
AjaxCallListener ajaxCallListener = new AjaxCallListener();
if (confirmMessage != null) {
ajaxCallListener.onPrecondition(new
JavaScriptEventConfirmation(confirmMessage).getBeforeHandler(this));
} else {
ajaxCallListener.onPrecondition(new
JavaScriptEventConfirmation(confirmMessageModel.getObject()).getBeforeHandler(this));
}
attributes.getAjaxCallListeners().add(ajaxCallListener);
}
@Override
public abstract void onClick(AjaxRequestTarget target);
}
it works fine with static message and static model
but i want to load the message dynamically. so i use LoadableDetachableModel
like this
new ConfirmAjaxFallbackLink("deleteItemLink", new
LoadableDetachableModel<String>()
{
@Override
protected String load()
{
List<String> activeUsages =
findActiveUsages();
if (activeUsages.size() > 0) {
return "This item is actively used in "
+activeUsages +", Do you still want to delete it?";
}
return "Do you want delete?"
}
})
{
@Override
public void onClick(AjaxRequestTarget target)
{
onDelete(target);
}
};
But it doesn't load dynamically. while we refresh the page only it loading.
can you have any idea about it.
Thanks,
Vignesh
Re: ConfirmAjaxFallbackLink with LoadableDetachableModel
Posted by Sven Meier <sv...@meiers.net>.
Hi,
since the message is written into the HTML's javascript, you'll have to
update the component to reflect a change:
@Override
public void onClick(AjaxRequestTarget target)
{
target.add(this); // re-render this link to have
updated message in the browser
info("Clicked on "+ new Date());
}
Sven
On 07/05/2013 03:47 AM, Vignesh Palanisamy wrote:
> I had attach a quick start project with it.
>
> steps:
>
> * Extract the project, build and run jetty
> * File Foo should be created in "user.dir". Open it and keep it aside.
> * Go to browser, access the application, click the link.
> * A confirmation dialog will display the message "foo message" . Click
> the cancel button and come back.
> * Edit the file Foo and change the text.
> * Click the link again without refreshing the page. Only "foo message"
> is displayed instead of the changed text in the file.
> * Now refresh the page and click the link again. The edited message
> will be displayed.
>
>
>
> thanks
>
>
> On Thu, Jul 4, 2013 at 3:22 PM, Sven Meier <sven@meiers.net
> <ma...@meiers.net>> wrote:
>
> Looks fine to me. Can you create a quickstart?
>
> Sven
>
>
> On 07/04/2013 03:30 AM, Vignesh Palanisamy wrote:
>
> Hi all,
>
> I have a ConfirmAjaxFallbackLink which is use to display
> confirmation
> dialog, when a user attempts to delete an item in a datatable.
>
> public abstract class ConfirmAjaxFallbackLink extends
> AjaxFallbackLink
> {
> private String confirmMessage;
> private IModel<String> confirmMessageModel;
>
>
> public ConfirmAjaxFallbackLink(String id, String
> confirmMessage)
> {
> super(id);
> this.confirmMessage = confirmMessage;
> }
>
> public ConfirmAjaxFallbackLink(String id, IModel<String>
> messageModel)
> {
> super(id, messageModel);
> this.confirmMessageModel = messageModel;
> }
>
> @Override
> protected void updateAjaxAttributes(AjaxRequestAttributes
> attributes)
> {
> super.updateAjaxAttributes(attributes);
> AjaxCallListener ajaxCallListener = new
> AjaxCallListener();
> if (confirmMessage != null) {
> ajaxCallListener.onPrecondition(new
> JavaScriptEventConfirmation(confirmMessage).getBeforeHandler(this));
> } else {
> ajaxCallListener.onPrecondition(new
> JavaScriptEventConfirmation(confirmMessageModel.getObject()).getBeforeHandler(this));
> }
> attributes.getAjaxCallListeners().add(ajaxCallListener);
> }
>
> @Override
> public abstract void onClick(AjaxRequestTarget target);
> }
>
>
>
> it works fine with static message and static model
>
>
> but i want to load the message dynamically. so i use
> LoadableDetachableModel
>
> like this
>
> new ConfirmAjaxFallbackLink("deleteItemLink", new
> LoadableDetachableModel<String>()
> {
> @Override
> protected String load()
> {
> List<String> activeUsages =
> findActiveUsages();
> if (activeUsages.size() > 0) {
> return "This item is
> actively used in "
> +activeUsages +", Do you still want to delete it?";
> }
> return "Do you want delete?"
> }
> })
> {
> @Override
> public void
> onClick(AjaxRequestTarget target)
> {
> onDelete(target);
> }
> };
>
>
> But it doesn't load dynamically. while we refresh the page
> only it loading.
>
>
> can you have any idea about it.
>
>
>
> Thanks,
> Vignesh
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
Re: ConfirmAjaxFallbackLink with LoadableDetachableModel
Posted by Vignesh Palanisamy <vi...@mcruncher.com>.
I had attach a quick start project with it.
steps:
* Extract the project, build and run jetty
* File Foo should be created in "user.dir". Open it and keep it aside.
* Go to browser, access the application, click the link.
* A confirmation dialog will display the message "foo message" . Click the
cancel button and come back.
* Edit the file Foo and change the text.
* Click the link again without refreshing the page. Only "foo message" is
displayed instead of the changed text in the file.
* Now refresh the page and click the link again. The edited message will be
displayed.
thanks
On Thu, Jul 4, 2013 at 3:22 PM, Sven Meier <sv...@meiers.net> wrote:
> Looks fine to me. Can you create a quickstart?
>
> Sven
>
>
> On 07/04/2013 03:30 AM, Vignesh Palanisamy wrote:
>
>> Hi all,
>>
>> I have a ConfirmAjaxFallbackLink which is use to display confirmation
>> dialog, when a user attempts to delete an item in a datatable.
>>
>> public abstract class ConfirmAjaxFallbackLink extends AjaxFallbackLink
>> {
>> private String confirmMessage;
>> private IModel<String> confirmMessageModel;
>>
>>
>> public ConfirmAjaxFallbackLink(String id, String confirmMessage)
>> {
>> super(id);
>> this.confirmMessage = confirmMessage;
>> }
>>
>> public ConfirmAjaxFallbackLink(String id, IModel<String>
>> messageModel)
>> {
>> super(id, messageModel);
>> this.confirmMessageModel = messageModel;
>> }
>>
>> @Override
>> protected void updateAjaxAttributes(**AjaxRequestAttributes
>> attributes)
>> {
>> super.updateAjaxAttributes(**attributes);
>> AjaxCallListener ajaxCallListener = new AjaxCallListener();
>> if (confirmMessage != null) {
>> ajaxCallListener.**onPrecondition(new
>> JavaScriptEventConfirmation(**confirmMessage).**getBeforeHandler(this));
>> } else {
>> ajaxCallListener.**onPrecondition(new
>> JavaScriptEventConfirmation(**confirmMessageModel.getObject(**
>> )).getBeforeHandler(this));
>> }
>> attributes.**getAjaxCallListeners().add(**ajaxCallListener);
>> }
>>
>> @Override
>> public abstract void onClick(AjaxRequestTarget target);
>> }
>>
>>
>>
>> it works fine with static message and static model
>>
>>
>> but i want to load the message dynamically. so i use
>> LoadableDetachableModel
>>
>> like this
>>
>> new ConfirmAjaxFallbackLink("**deleteItemLink", new
>> LoadableDetachableModel<**String>()
>> {
>> @Override
>> protected String load()
>> {
>> List<String> activeUsages =
>> findActiveUsages();
>> if (activeUsages.size() > 0) {
>> return "This item is actively used
>> in "
>> +activeUsages +", Do you still want to delete it?";
>> }
>> return "Do you want delete?"
>> }
>> })
>> {
>> @Override
>> public void onClick(AjaxRequestTarget target)
>> {
>> onDelete(target);
>> }
>> };
>>
>>
>> But it doesn't load dynamically. while we refresh the page only it
>> loading.
>>
>>
>> can you have any idea about it.
>>
>>
>>
>> Thanks,
>> Vignesh
>>
>>
>
Re: ConfirmAjaxFallbackLink with LoadableDetachableModel
Posted by Sven Meier <sv...@meiers.net>.
Looks fine to me. Can you create a quickstart?
Sven
On 07/04/2013 03:30 AM, Vignesh Palanisamy wrote:
> Hi all,
>
> I have a ConfirmAjaxFallbackLink which is use to display confirmation
> dialog, when a user attempts to delete an item in a datatable.
>
> public abstract class ConfirmAjaxFallbackLink extends AjaxFallbackLink
> {
> private String confirmMessage;
> private IModel<String> confirmMessageModel;
>
>
> public ConfirmAjaxFallbackLink(String id, String confirmMessage)
> {
> super(id);
> this.confirmMessage = confirmMessage;
> }
>
> public ConfirmAjaxFallbackLink(String id, IModel<String> messageModel)
> {
> super(id, messageModel);
> this.confirmMessageModel = messageModel;
> }
>
> @Override
> protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
> {
> super.updateAjaxAttributes(attributes);
> AjaxCallListener ajaxCallListener = new AjaxCallListener();
> if (confirmMessage != null) {
> ajaxCallListener.onPrecondition(new
> JavaScriptEventConfirmation(confirmMessage).getBeforeHandler(this));
> } else {
> ajaxCallListener.onPrecondition(new
> JavaScriptEventConfirmation(confirmMessageModel.getObject()).getBeforeHandler(this));
> }
> attributes.getAjaxCallListeners().add(ajaxCallListener);
> }
>
> @Override
> public abstract void onClick(AjaxRequestTarget target);
> }
>
>
>
> it works fine with static message and static model
>
>
> but i want to load the message dynamically. so i use LoadableDetachableModel
>
> like this
>
> new ConfirmAjaxFallbackLink("deleteItemLink", new
> LoadableDetachableModel<String>()
> {
> @Override
> protected String load()
> {
> List<String> activeUsages =
> findActiveUsages();
> if (activeUsages.size() > 0) {
> return "This item is actively used in "
> +activeUsages +", Do you still want to delete it?";
> }
> return "Do you want delete?"
> }
> })
> {
> @Override
> public void onClick(AjaxRequestTarget target)
> {
> onDelete(target);
> }
> };
>
>
> But it doesn't load dynamically. while we refresh the page only it loading.
>
>
> can you have any idea about it.
>
>
>
> Thanks,
> Vignesh
>