
org.nuiton.web.tapestry5.mixins.Confirm Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nuiton-tapestry Show documentation
Show all versions of nuiton-tapestry Show documentation
Extra classes for Tapestry based applications
The newest version!
/*
* #%L
* Nuiton Web :: Nuiton Tapestry
*
* $Id: Confirm.java 80 2011-06-28 12:25:30Z tchemit $
* $HeadURL: https://svn.nuiton.org/nuiton-web/tags/nuiton-web-1.17/nuiton-tapestry/src/main/java/org/nuiton/web/tapestry5/mixins/Confirm.java $
* %%
* Copyright (C) 2010 - 2011 CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
package org.nuiton.web.tapestry5.mixins;
import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.ClientElement;
import org.apache.tapestry5.annotations.AfterRender;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.InjectContainer;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.javascript.JavaScriptSupport;
/**
* A simple mixin for attaching a javascript confirmation box to the onclick
* event of any component that implements ClientElement.
*
* @author fdesbois
* @version $Id: Confirm.java 80 2011-06-28 12:25:30Z tchemit $
*/
@Import(library = "confirm.js")
public class Confirm {
@Parameter(value = "Are you sure?", defaultPrefix = BindingConstants.MESSAGE)
private String message;
@Parameter(value = "true")
private boolean condition;
@Inject
private JavaScriptSupport javaScriptSupport;
@InjectContainer
private ClientElement element;
@Parameter
private boolean wDisabled;
@AfterRender
public void afterRender() {
if (!wDisabled) {
javaScriptSupport.addScript(String.format("new Confirm('%s', '%s', %b);",
element.getClientId(), message.replace("'", "\\'"), condition));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy