You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Fatih Mehmet Ucar <fm...@gmail.com> on 2010/01/20 15:28:45 UTC

Re: javascript confirm - seems to work fine with link markup but not with button markup

AttributeAppender should solve your problem.

fmu

2010/1/20 Steve Whitson <st...@gmail.com>:
> Hi,
>
> I'm new to wicket, and am working on my first app.  Great alternative to
> other WebUI frameworks!
>
> I've added a link to my panel using this code:
>
>       Link deleteReportLink = new Link( "deletereport" ) {
>           @Override
>           public void onClick() {
>               System.out.println("deleting report" );
>               service.deleteReport( selectedReport );
>           }
>       };
>         add( deleteReportLink );
>
>   // add a confirmation to the Delete Report operation
>   deleteReportLink.add(
>           new SimpleAttributeModifier( "onclick", "return confirm( 'Are you
> sure?');" )
>       );
>
> Here's the markup:
>
>   <a href="#" wicket:id="deletereport">Delete Report</a>
>   <!--  <input type="button" wicket:id="deletereport" value="Delete Report"
> /> -->
>   <!-- <button type="button" wicket:id="deletereport">Delete Report</button>
>  -->
>
> In the markup, when I use an 'a' tag the javascript confirmation dialog
> works fine along with the onClick() override.  When I use it with either of
> the (commented out) button inputs, the dialog appears, but the 'onClick()'
> override is never executed.
>
> I'd much rather this work with a button and not a hyperlink.
>
> Any ideas or help is greatly appreciated.
>   -Steve
>
>
>
> ---------------------------------------------------------------------
> 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


Re: javascript confirm - seems to work fine with link markup but not with button markup (AttributePrepender)

Posted by Steve Whitson <st...@gmail.com>.
Yep... that did the trick!  Thanks much for all your help!
    -Steve

Here's what I did.... I made a copy of AttributeAppender, and changed 
the method newValue( String, String ) to this:

    protected String newValue(String currentValue, String appendValue)
    {
        final int appendValueLen = (appendValue == null) ? 0 : 
appendValue.length();

        final AppendingStringBuffer sb;
       
        // initializes the AppendStringBuffer
        if (currentValue == null)
        {
            sb = new AppendingStringBuffer(appendValueLen + 
separator.length());
        }
        else
        {
            sb = new AppendingStringBuffer(currentValue.length() + 
appendValueLen +
                separator.length());
        }

        // only append the value when it is not empty.
        if (!Strings.isEmpty(appendValue))
        {
            sb.append(appendValue);
            if ( ( currentValue != null ) && 
!Strings.isEmpty(currentValue) ) {
                sb.append(separator);
                sb.append(currentValue);
            }
        }
        else
        {
            if ( ( currentValue != null ) && 
!Strings.isEmpty(currentValue) ) {
                sb.append(currentValue);
            }
        }
        return sb.toString();
    }


Fatih Mehmet Ucar wrote:
> yes, if you are gonna use this in several places, creating a class
> like AttributePrepender may be a better idea.
>
> 2010/1/20 Ernesto Reinaldo Barreiro <re...@gmail.com>:
>   
>> I remember Martijn advising to copy/paste AttributeAppender and transforming
>> it to AttributePrepender for such a use case...
>>
>> Best,
>>
>> Ernesto
>>
>> On Wed, Jan 20, 2010 at 4:26 PM, Steve Whitson <st...@gmail.com>wrote:
>>
>>     
>>> Thanks for the suggestion...
>>>
>>> It appears as though I need to insert the attribute before the existing
>>> onclick attribute.  How do I retrieve the existing onclick attribute?  My
>>> hope is to retrieve the existing onclick attribute so I can prepend my
>>> onclick action and use AttributeModifier to replace the existing with the
>>> newly prepended content.
>>>
>>> Thanks much,
>>>   -Steve
>>>
>>>
>>>
>>> Fatih Mehmet Ucar wrote:
>>>
>>>       
>>>> AttributeAppender should solve your problem.
>>>>
>>>> fmu
>>>>
>>>> 2010/1/20 Steve Whitson <st...@gmail.com>:
>>>>
>>>>
>>>>         
>>>>> Hi,
>>>>>
>>>>> I'm new to wicket, and am working on my first app.  Great alternative to
>>>>> other WebUI frameworks!
>>>>>
>>>>> I've added a link to my panel using this code:
>>>>>
>>>>>      Link deleteReportLink = new Link( "deletereport" ) {
>>>>>          @Override
>>>>>          public void onClick() {
>>>>>              System.out.println("deleting report" );
>>>>>              service.deleteReport( selectedReport );
>>>>>          }
>>>>>      };
>>>>>        add( deleteReportLink );
>>>>>
>>>>>  // add a confirmation to the Delete Report operation
>>>>>  deleteReportLink.add(
>>>>>          new SimpleAttributeModifier( "onclick", "return confirm( 'Are
>>>>> you
>>>>> sure?');" )
>>>>>      );
>>>>>
>>>>> Here's the markup:
>>>>>
>>>>>  <a href="#" wicket:id="deletereport">Delete Report</a>
>>>>>  <!--  <input type="button" wicket:id="deletereport" value="Delete
>>>>> Report"
>>>>> /> -->
>>>>>  <!-- <button type="button" wicket:id="deletereport">Delete
>>>>> Report</button>
>>>>>  -->
>>>>>
>>>>> In the markup, when I use an 'a' tag the javascript confirmation dialog
>>>>> works fine along with the onClick() override.  When I use it with either
>>>>> of
>>>>> the (commented out) button inputs, the dialog appears, but the
>>>>> 'onClick()'
>>>>> override is never executed.
>>>>>
>>>>> I'd much rather this work with a button and not a hyperlink.
>>>>>
>>>>> Any ideas or help is greatly appreciated.
>>>>>  -Steve
>>>>>
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> 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
>>>>
>>>>
>>>>         
>>>       
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>   


Re: javascript confirm - seems to work fine with link markup but not with button markup

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
and maybe donating it back to the community;-)

Ernesto

On Wed, Jan 20, 2010 at 5:01 PM, Fatih Mehmet Ucar <fm...@gmail.com> wrote:

> yes, if you are gonna use this in several places, creating a class
> like AttributePrepender may be a better idea.
>
> 2010/1/20 Ernesto Reinaldo Barreiro <re...@gmail.com>:
> > I remember Martijn advising to copy/paste AttributeAppender and
> transforming
> > it to AttributePrepender for such a use case...
> >
> > Best,
> >
> > Ernesto
> >
> > On Wed, Jan 20, 2010 at 4:26 PM, Steve Whitson <steven.whitson@gmail.com
> >wrote:
> >
> >> Thanks for the suggestion...
> >>
> >> It appears as though I need to insert the attribute before the existing
> >> onclick attribute.  How do I retrieve the existing onclick attribute?
>  My
> >> hope is to retrieve the existing onclick attribute so I can prepend my
> >> onclick action and use AttributeModifier to replace the existing with
> the
> >> newly prepended content.
> >>
> >> Thanks much,
> >>   -Steve
> >>
> >>
> >>
> >> Fatih Mehmet Ucar wrote:
> >>
> >>> AttributeAppender should solve your problem.
> >>>
> >>> fmu
> >>>
> >>> 2010/1/20 Steve Whitson <st...@gmail.com>:
> >>>
> >>>
> >>>> Hi,
> >>>>
> >>>> I'm new to wicket, and am working on my first app.  Great alternative
> to
> >>>> other WebUI frameworks!
> >>>>
> >>>> I've added a link to my panel using this code:
> >>>>
> >>>>      Link deleteReportLink = new Link( "deletereport" ) {
> >>>>          @Override
> >>>>          public void onClick() {
> >>>>              System.out.println("deleting report" );
> >>>>              service.deleteReport( selectedReport );
> >>>>          }
> >>>>      };
> >>>>        add( deleteReportLink );
> >>>>
> >>>>  // add a confirmation to the Delete Report operation
> >>>>  deleteReportLink.add(
> >>>>          new SimpleAttributeModifier( "onclick", "return confirm( 'Are
> >>>> you
> >>>> sure?');" )
> >>>>      );
> >>>>
> >>>> Here's the markup:
> >>>>
> >>>>  <a href="#" wicket:id="deletereport">Delete Report</a>
> >>>>  <!--  <input type="button" wicket:id="deletereport" value="Delete
> >>>> Report"
> >>>> /> -->
> >>>>  <!-- <button type="button" wicket:id="deletereport">Delete
> >>>> Report</button>
> >>>>  -->
> >>>>
> >>>> In the markup, when I use an 'a' tag the javascript confirmation
> dialog
> >>>> works fine along with the onClick() override.  When I use it with
> either
> >>>> of
> >>>> the (commented out) button inputs, the dialog appears, but the
> >>>> 'onClick()'
> >>>> override is never executed.
> >>>>
> >>>> I'd much rather this work with a button and not a hyperlink.
> >>>>
> >>>> Any ideas or help is greatly appreciated.
> >>>>  -Steve
> >>>>
> >>>>
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> 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
> >>>
> >>>
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: javascript confirm - seems to work fine with link markup but not with button markup

Posted by Fatih Mehmet Ucar <fm...@gmail.com>.
yes, if you are gonna use this in several places, creating a class
like AttributePrepender may be a better idea.

2010/1/20 Ernesto Reinaldo Barreiro <re...@gmail.com>:
> I remember Martijn advising to copy/paste AttributeAppender and transforming
> it to AttributePrepender for such a use case...
>
> Best,
>
> Ernesto
>
> On Wed, Jan 20, 2010 at 4:26 PM, Steve Whitson <st...@gmail.com>wrote:
>
>> Thanks for the suggestion...
>>
>> It appears as though I need to insert the attribute before the existing
>> onclick attribute.  How do I retrieve the existing onclick attribute?  My
>> hope is to retrieve the existing onclick attribute so I can prepend my
>> onclick action and use AttributeModifier to replace the existing with the
>> newly prepended content.
>>
>> Thanks much,
>>   -Steve
>>
>>
>>
>> Fatih Mehmet Ucar wrote:
>>
>>> AttributeAppender should solve your problem.
>>>
>>> fmu
>>>
>>> 2010/1/20 Steve Whitson <st...@gmail.com>:
>>>
>>>
>>>> Hi,
>>>>
>>>> I'm new to wicket, and am working on my first app.  Great alternative to
>>>> other WebUI frameworks!
>>>>
>>>> I've added a link to my panel using this code:
>>>>
>>>>      Link deleteReportLink = new Link( "deletereport" ) {
>>>>          @Override
>>>>          public void onClick() {
>>>>              System.out.println("deleting report" );
>>>>              service.deleteReport( selectedReport );
>>>>          }
>>>>      };
>>>>        add( deleteReportLink );
>>>>
>>>>  // add a confirmation to the Delete Report operation
>>>>  deleteReportLink.add(
>>>>          new SimpleAttributeModifier( "onclick", "return confirm( 'Are
>>>> you
>>>> sure?');" )
>>>>      );
>>>>
>>>> Here's the markup:
>>>>
>>>>  <a href="#" wicket:id="deletereport">Delete Report</a>
>>>>  <!--  <input type="button" wicket:id="deletereport" value="Delete
>>>> Report"
>>>> /> -->
>>>>  <!-- <button type="button" wicket:id="deletereport">Delete
>>>> Report</button>
>>>>  -->
>>>>
>>>> In the markup, when I use an 'a' tag the javascript confirmation dialog
>>>> works fine along with the onClick() override.  When I use it with either
>>>> of
>>>> the (commented out) button inputs, the dialog appears, but the
>>>> 'onClick()'
>>>> override is never executed.
>>>>
>>>> I'd much rather this work with a button and not a hyperlink.
>>>>
>>>> Any ideas or help is greatly appreciated.
>>>>  -Steve
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>>>
>>>
>>
>>
>

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


Re: javascript confirm - seems to work fine with link markup but not with button markup

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
I remember Martijn advising to copy/paste AttributeAppender and transforming
it to AttributePrepender for such a use case...

Best,

Ernesto

On Wed, Jan 20, 2010 at 4:26 PM, Steve Whitson <st...@gmail.com>wrote:

> Thanks for the suggestion...
>
> It appears as though I need to insert the attribute before the existing
> onclick attribute.  How do I retrieve the existing onclick attribute?  My
> hope is to retrieve the existing onclick attribute so I can prepend my
> onclick action and use AttributeModifier to replace the existing with the
> newly prepended content.
>
> Thanks much,
>   -Steve
>
>
>
> Fatih Mehmet Ucar wrote:
>
>> AttributeAppender should solve your problem.
>>
>> fmu
>>
>> 2010/1/20 Steve Whitson <st...@gmail.com>:
>>
>>
>>> Hi,
>>>
>>> I'm new to wicket, and am working on my first app.  Great alternative to
>>> other WebUI frameworks!
>>>
>>> I've added a link to my panel using this code:
>>>
>>>      Link deleteReportLink = new Link( "deletereport" ) {
>>>          @Override
>>>          public void onClick() {
>>>              System.out.println("deleting report" );
>>>              service.deleteReport( selectedReport );
>>>          }
>>>      };
>>>        add( deleteReportLink );
>>>
>>>  // add a confirmation to the Delete Report operation
>>>  deleteReportLink.add(
>>>          new SimpleAttributeModifier( "onclick", "return confirm( 'Are
>>> you
>>> sure?');" )
>>>      );
>>>
>>> Here's the markup:
>>>
>>>  <a href="#" wicket:id="deletereport">Delete Report</a>
>>>  <!--  <input type="button" wicket:id="deletereport" value="Delete
>>> Report"
>>> /> -->
>>>  <!-- <button type="button" wicket:id="deletereport">Delete
>>> Report</button>
>>>  -->
>>>
>>> In the markup, when I use an 'a' tag the javascript confirmation dialog
>>> works fine along with the onClick() override.  When I use it with either
>>> of
>>> the (commented out) button inputs, the dialog appears, but the
>>> 'onClick()'
>>> override is never executed.
>>>
>>> I'd much rather this work with a button and not a hyperlink.
>>>
>>> Any ideas or help is greatly appreciated.
>>>  -Steve
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>
>

Re: javascript confirm - seems to work fine with link markup but not with button markup

Posted by Fatih Mehmet Ucar <fm...@gmail.com>.
onClick code is created in onComponentTag(), and replaced by getOnClickScript()
you can override the getOnClickScript() to prepend custom js code.

fmu

2010/1/20 Steve Whitson <st...@gmail.com>:
> Thanks for the suggestion...
>
> It appears as though I need to insert the attribute before the existing
> onclick attribute.  How do I retrieve the existing onclick attribute?  My
> hope is to retrieve the existing onclick attribute so I can prepend my
> onclick action and use AttributeModifier to replace the existing with the
> newly prepended content.
>
> Thanks much,
>   -Steve
>
>
> Fatih Mehmet Ucar wrote:
>>
>> AttributeAppender should solve your problem.
>>
>> fmu
>>
>> 2010/1/20 Steve Whitson <st...@gmail.com>:
>>
>>>
>>> Hi,
>>>
>>> I'm new to wicket, and am working on my first app.  Great alternative to
>>> other WebUI frameworks!
>>>
>>> I've added a link to my panel using this code:
>>>
>>>      Link deleteReportLink = new Link( "deletereport" ) {
>>>          @Override
>>>          public void onClick() {
>>>              System.out.println("deleting report" );
>>>              service.deleteReport( selectedReport );
>>>          }
>>>      };
>>>        add( deleteReportLink );
>>>
>>>  // add a confirmation to the Delete Report operation
>>>  deleteReportLink.add(
>>>          new SimpleAttributeModifier( "onclick", "return confirm( 'Are
>>> you
>>> sure?');" )
>>>      );
>>>
>>> Here's the markup:
>>>
>>>  <a href="#" wicket:id="deletereport">Delete Report</a>
>>>  <!--  <input type="button" wicket:id="deletereport" value="Delete
>>> Report"
>>> /> -->
>>>  <!-- <button type="button" wicket:id="deletereport">Delete
>>> Report</button>
>>>  -->
>>>
>>> In the markup, when I use an 'a' tag the javascript confirmation dialog
>>> works fine along with the onClick() override.  When I use it with either
>>> of
>>> the (commented out) button inputs, the dialog appears, but the
>>> 'onClick()'
>>> override is never executed.
>>>
>>> I'd much rather this work with a button and not a hyperlink.
>>>
>>> Any ideas or help is greatly appreciated.
>>>  -Steve
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>
>

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


Re: javascript confirm - seems to work fine with link markup but not with button markup

Posted by Steve Whitson <st...@gmail.com>.
Thanks for the suggestion...

It appears as though I need to insert the attribute before the existing 
onclick attribute.  How do I retrieve the existing onclick attribute?  
My hope is to retrieve the existing onclick attribute so I can prepend 
my onclick action and use AttributeModifier to replace the existing with 
the newly prepended content.

Thanks much,
    -Steve


Fatih Mehmet Ucar wrote:
> AttributeAppender should solve your problem.
>
> fmu
>
> 2010/1/20 Steve Whitson <st...@gmail.com>:
>   
>> Hi,
>>
>> I'm new to wicket, and am working on my first app.  Great alternative to
>> other WebUI frameworks!
>>
>> I've added a link to my panel using this code:
>>
>>       Link deleteReportLink = new Link( "deletereport" ) {
>>           @Override
>>           public void onClick() {
>>               System.out.println("deleting report" );
>>               service.deleteReport( selectedReport );
>>           }
>>       };
>>         add( deleteReportLink );
>>
>>   // add a confirmation to the Delete Report operation
>>   deleteReportLink.add(
>>           new SimpleAttributeModifier( "onclick", "return confirm( 'Are you
>> sure?');" )
>>       );
>>
>> Here's the markup:
>>
>>   <a href="#" wicket:id="deletereport">Delete Report</a>
>>   <!--  <input type="button" wicket:id="deletereport" value="Delete Report"
>> /> -->
>>   <!-- <button type="button" wicket:id="deletereport">Delete Report</button>
>>  -->
>>
>> In the markup, when I use an 'a' tag the javascript confirmation dialog
>> works fine along with the onClick() override.  When I use it with either of
>> the (commented out) button inputs, the dialog appears, but the 'onClick()'
>> override is never executed.
>>
>> I'd much rather this work with a button and not a hyperlink.
>>
>> Any ideas or help is greatly appreciated.
>>   -Steve
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
>