or even better, it should really be something like this

class deleteuserlink extends link {
   protected void oncomponenttag(tag) {
      string uname=((user)getmodelobject()).getusername();
      tag.put("onclick", "return alert('are you sure you want to
delete "+uname.....
   }
}

and in your code you should be doing

add(new deleteuserlink("delete-user", usermodel));

this is where wicket really shines, it lets you work with objects and
models. especially in the next release where you can do

class deleteuserlink extends link<user> {
   protected void oncomponenttag(tag) {
      string uname=getmodelobject().getusername();
      tag.put("onclick", "return alert('are you sure you want to
delete "+uname.....
   }
}


-igor

On Mon, Mar 17, 2008 at 2:56 AM, Timo Rantalaiho <[EMAIL PROTECTED]> wrote:
> On Tue, 11 Mar 2008, tsuresh wrote:
>  > > When I click on the next name the output is User selected: Bob. i.e. The
>  > > first output comes in second click and second ouput comes in third click
>  > > and so on. My code is as shown below: Where am I missing ? Please help.
>  > >
>  > >  String username ="";
>  > >   Link userLink = new Link("user") {
>  > >
>  > >                     public void onClick() {
>  > >                         User selectedUser = (User)
>  > > getParent().getModelObject();
>  > >                         username = selectedUser.getUsername();
>  > >
>  > >                     }
>  > >                 };
>  > >
>  > >                 userLink.add(new SimpleAttributeModifier("onclick",
>  > > "return alert('User selected:" +username + "');"));
>
>  Think about when the last line is evaluated: it happens
>  already when the link is being constructed and the behavior
>  is being appended onto it, so it uses the value that username
>  has at that moment. Link.onClick() happens later and doesn't
>  change the existing AttributeModifier anymore.
>
>  Rather than that, you should do something more dynamic like
>
>   userLink.add(new AttributeModifier("onclick", true,
>     new AbstractReadOnlyModel() {
>         @Override
>         public Object getObject() {
>             return nameOfSelectedUser();
>         }
>     });
>
>     ...
>
>     private String nameOfSelectedUser() {
>         return ((User) getModelObject()).getUserName();
>     }
>
>
>  Best wishes,
>  Timo
>
>  --
>  Timo Rantalaiho
>  Reaktor Innovations Oy    <URL: http://www.ri.fi/ >
>
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: [EMAIL PROTECTED]
>  For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to