How embarrassing -- I think I'd better keep my day job. I can't believe that
I could not grasp that you meant that I should modify rot using
rot.setEnabled(true or false) depending on the biz logic.
Thanks much, your suggestion worked flawlessly. Here is what I ended up
with:
protected void populateItem(final ListItem item) {
final EmailAddress email = (EmailAddress)
item.getModelObject();
final FocusableTextField emailLabel = new
FocusableTextField("label", page);
final AttributeModifier rot = new
AttributeModifier("readonly", true, new Model("readonly"));
if (email.getType() == EmailAddress.Type.OTHER)
rot.setEnabled(false);
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(true);
}
}
});
<snip>
- JA
Eelco Hillenius wrote:
>
> 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]
>
>
>
--
View this message in context:
http://www.nabble.com/setEnabled%28false%29-on-FocusableTextField-breaks-persistence-tf4351731.html#a12419384
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]