You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by raybristol <ra...@gmail.com> on 2007/10/26 14:03:22 UTC

how to add a confirm window to a Link button?

I use PageableListView to make a table and there is a column called 'delete',
which works fine but I want to add a confirm window so when people click
'delete' a window will pop up asking 'yes' or 'no', in html, this can be
done use javascript, but with wicket control link button, how to add to it?


final PageableListView listView = new PageableListView("boxList",
thisBoxList, 10) {
		    protected void populateItem(ListItem item) {
	        final Box box = (Box)item.getModelObject();
	        
	        final int index = item.getIndex();
	        item.add(new Label("boxID", String.valueOf(box.getBarcode())));
	        item.add(new Label("JobProfileName", box.getJobProfileName()));

	        item.add(new Link("Delete") {
	        	public void
	        		onClick() {
	        		
	        		mpm.deleteBox(box.getBarcode());
	        		thisBoxList.remove(index);
	        		}
	        	});
	            }
        };


Many thanks!
-- 
View this message in context: http://www.nabble.com/how-to-add-a-confirm-window-to-a-Link-button--tf4696906.html#a13425883
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: how to add a confirm window to a Link button?

Posted by Eelco Hillenius <ee...@gmail.com>.
> That's great sample, thanks so much Jan, I will try that soon!

Also see this: http://chillenious.wordpress.com/2006/11/30/ask-confirmation-on-link-clicks-with-wicket/

Eelco

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: how to add a confirm window to a Link button?

Posted by raybristol <ra...@gmail.com>.
That's great sample, thanks so much Jan, I will try that soon!




Jan Kriesten wrote:
> 
> 
> just add a behavior to the link which ads a javascript 'onclick':
> 
> public class JavascriptEventConfirmation
>         extends AttributeModifier
> {
>   private static final long serialVersionUID = 1L;
> 
>   public JavascriptEventConfirmation( final String event, final String msg
> )
>   {
>     super( event, true, new Model( msg ) );
>   }
> 
>   @Override
>   protected String newValue( final String currentValue, final String
> replacementValue )
>   {
>     if( currentValue != null && currentValue.length() != 0 )
>     {
>       StringBuilder result = new StringBuilder( 256 );
>       result.append( "if( confirm('" );
>       result.append( escape( replacementValue ) );
>       result.append( "') ){" );
>       result.append( currentValue );
>       result.append( "} else return false;" );
>       return (result.toString());
>     }
>     else
>     {
>       return ("return confirm('" + escape( replacementValue ) + "')");
>     }
>   }
> 
>   private String escape( final String text )
>   {
>     if( text == null )
>     {
>       return (null);
>     }
> 
>     return (text.replaceAll( "\"", "&quot;" ));
>   }
> 
> }
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/how-to-add-a-confirm-window-to-a-Link-button--tf4696906.html#a13427749
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: how to add a confirm window to a Link button?

Posted by Jan Kriesten <ja...@renitence.de>.
just add a behavior to the link which ads a javascript 'onclick':

public class JavascriptEventConfirmation
        extends AttributeModifier
{
  private static final long serialVersionUID = 1L;

  public JavascriptEventConfirmation( final String event, final String msg )
  {
    super( event, true, new Model( msg ) );
  }

  @Override
  protected String newValue( final String currentValue, final String
replacementValue )
  {
    if( currentValue != null && currentValue.length() != 0 )
    {
      StringBuilder result = new StringBuilder( 256 );
      result.append( "if( confirm('" );
      result.append( escape( replacementValue ) );
      result.append( "') ){" );
      result.append( currentValue );
      result.append( "} else return false;" );
      return (result.toString());
    }
    else
    {
      return ("return confirm('" + escape( replacementValue ) + "')");
    }
  }

  private String escape( final String text )
  {
    if( text == null )
    {
      return (null);
    }

    return (text.replaceAll( "\"", "&quot;" ));
  }

}



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org