On 8/30/07, janders <[EMAIL PROTECTED]> wrote:
>
> I don't think I'm doing a good job communicating what I'm trying to do.

Or maybe it's me not doing a good job explaining what you should do :)

> The markup looks like this (note there is no attribute readonly for input
> field with id="label"):
>
> <select wicket:id="type">
>   <option>home</option>
>   <option>work</option>
>   <option>other</option>
> </select>
> <input wicket:id="label" type="text" class="label" />
>
> What I want to do is dynamically set or remove the attribute readonly on the
> input field (label) depending on the dropdownchoice selection (type).  If
> the user selects "home" or "work" I want the attribute readonly to be set.
> If the user selects "other" I want the attribute to be removed so that the
> user can edit label.
>
> The Java code looks like:
>
> final AttributeModifier rot = new AttributeModifier("readonly", true, new
> Model("readonly"));  // true
>
> if (email.getType() != EmailAddress.Type.OTHER)
>
>     emailLabel.add(rot);      // <---- this works, by adding the readonly
> attribute
>
> item.add(emailLabel);
> item.add(new DropDownChoice("type", emailTypeList) {
>     @Override
>     protected boolean wantOnSelectionChangedNotifications() {
>         return true;
>     }
>     @Override
>     protected void onSelectionChanged(final Object newSelection) {
>         if (newSelection == EmailAddress.Type.OTHER) {
>
>             emailLabel.remove ??????? ;   //  <----- I can't figure out how
> to remove the attribute
>
>             emailLabel.requestFocus();
>         } else {
>             emailLabel.setModelValue(newSelection.toString());
>             emailLabel.add(rot);
>         }
>     }
> });
>

if (email.getType() != EmailAddress.Type.OTHER)

emailLabel.add(rot);
item.add(emailLabel);

item.add(new DropDownChoice("type", emailTypeList) {
   @Override
   protected boolean wantOnSelectionChangedNotifications() {
       return true;
   }
   @Override
   protected void onSelectionChanged(final Object newSelection) {
       if (newSelection == EmailAddress.Type.OTHER) {
           rot.setEnabled(false);
           emailLabel.requestFocus();
       } else {
           emailLabel.setModelValue(newSelection.toString());
           rot.setEnabled(false);
       }
   }
});


This code always adds the attribute modifier. However, it is disabled
when your use case happens.

> Because I have wantOnSelectionChangedNotifications() set to true, the user
> can select a choice and the label should change accordingly -- i.e., add
> attribute readonly or remove it for the selection of "other".
>
> So the problem that I'm having right now is how do I dynamically remove
> readonly (once added to the input field) when the user selects "other" from
> the dropdownchoice?

You don't need to remove it. Just turn it off/ on like the code
fragment above shows.

And for the finale, in Wicket 1.3 (I gather you are using 1.2), you
indeed can simply call remove(IBehavior) - attribute modifiers are
behaviors. So then emailLabel.remove(rot) should work fine.

Eelco

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

Reply via email to