You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Johannes Schneider <ma...@cedarsoft.com> on 2009/08/04 11:54:22 UTC
ConfirmLink Ajax + Fallback anyone?
Hi,
I think that is one of that components that has been created several
times out there.
Does anybody have a good implementation available?
There is a wiki page that contains both types of confirmation links
(http://cwiki.apache.org/WICKET/getting-user-confirmation.html) but not
a combination of both.
Thanks,
Johannes
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: ConfirmLink Ajax + Fallback anyone?
Posted by Johannes Schneider <ma...@cedarsoft.com>.
Ok, I have created some classes that seem to work. Could anyone take a
look at it and give any feedback?
What about the styles for the confirmation page? How should those be added?
Thanks
Johannes
/**
* A confirmation link that uses JavaScript if available.
*/
public class ConfirmationLink extends AjaxFallbackLink<Object> {
@NotNull
@NonNls
private final Model<? extends String> message;
@NotNull
private final Action action;
public ConfirmationLink( @NotNull @NonNls String id, @NotNull @NonNls
Model<? extends String> message, @NotNull Action action ) {
super( id );
this.message = message;
this.action = action;
add( new JavaScriptEventConfirmation(
JavaScriptEventConfirmation.EVENT_ON_CLICK, message ) );
}
@Override
public void onClick( @Nullable AjaxRequestTarget target ) {
if ( target == null ) {
//Fallback!
MarkupContainer parent = getParent();
if ( parent == null ) {
throw new IllegalStateException( "No parent found!" );
}
FallbackConfirmationLinkPanel.replace( parent, message, action );
} else {
//Javascript
action.execute();
}
}
public interface Action extends Serializable {
/**
* Executes the action
*/
void execute();
}
}
/**
* Contains a confirm link (as fallback if javascript is not available)
*/
public class FallbackConfirmationLinkPanel extends Panel {
/**
* Creates a confirm link panel
*
* @param componentToReplace the confirmation link panel this panel
replaces
* @param message the message
* @param action the action
*/
public FallbackConfirmationLinkPanel( @NotNull final Component
componentToReplace, @NotNull Model<? extends String> message, @NotNull
final ConfirmationLink.Action action ) {
super( componentToReplace.getId() );
add( new Label( "message", message ) );
add( new Link( "confirm" ) {
@Override
public void onClick() {
action.execute();
getParent().replaceWith( componentToReplace );
}
} );
add( new Link( "cancel" ) {
@Override
public void onClick() {
getParent().replaceWith( componentToReplace );
}
} );
}
public static void replace( @NotNull final Component
componentToReplace, @NotNull Model<? extends String> message, @NotNull
ConfirmationLink.Action action ) {
componentToReplace.replaceWith( new FallbackConfirmationLinkPanel(
componentToReplace, message, action ) );
}
}
Johannes Schneider wrote:
> Hi,
>
> I think that is one of that components that has been created several
> times out there.
> Does anybody have a good implementation available?
>
> There is a wiki page that contains both types of confirmation links
> (http://cwiki.apache.org/WICKET/getting-user-confirmation.html) but not
> a combination of both.
>
>
>
> Thanks,
>
> Johannes
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org