Re: setEnabled(false) on FocusableTextField breaks persistence
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 optionhome/option optionwork/option optionother/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]
Re: setEnabled(false) on FocusableTextField breaks persistence
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 optionhome/option optionwork/option optionother/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:
Re: setEnabled(false) on FocusableTextField breaks persistence
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. Heh, no problem. Good you got it now. Eelco - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
setEnabled(false) on FocusableTextField breaks persistence
I posted this on the Databinder forum but no one seems to know of a work-around so I thought I'd post it here. Essentially I have a FocusableTextField that gets set by a DropDownChoice. If the choice is not other then I setEnabled to false and I place the string value of the DropDownChoice into the FocusableTextField. However the model is not persisted when setEnabled is false. Here is the code: // list of existing emailAddresses final List emailTypeList = Arrays.asList(EmailAddress.Type.values()); final ListView emailAddresses = new PropertyListView(emailAddresses) { @Override protected void populateItem(final ListItem item) { final EmailAddress email = (EmailAddress) item.getModelObject(); final FocusableTextField emailLabel = new FocusableTextField(label, page); if (email.getType() != EmailAddress.Type.OTHER) emailLabel.setEnabled(false); 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.setEnabled(true); emailLabel.requestFocus(); } else { emailLabel.setModelValue(newSelection.toString()); emailLabel.setEnabled(false); } } }); snip In this email example the dropdown choices are home, work, and other. If user selects home or work I want the value of the FocusableTextField to be home or work and I do not want the user to be able to edit the field. That's why I set the field's isEnabled to false. On the other hand, if the user selects other, then I set isEnabled to true so that the user can edit the field. This works properly (persists the value) because isEnabled is true. Is there a workaround for this problem or can someone recommend a different approach? -- View this message in context: http://www.nabble.com/setEnabled%28false%29-on-FocusableTextField-breaks-persistence-tf4351731.html#a12399840 Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: setEnabled(false) on FocusableTextField breaks persistence
the entire point of disabling the component is that you do not want it to process submitted input and update its model. you are looking for readonly behavior rather then disabled i think. why not just set the readonly attribute on that field. -igor On 8/29/07, janders [EMAIL PROTECTED] wrote: I posted this on the Databinder forum but no one seems to know of a work-around so I thought I'd post it here. Essentially I have a FocusableTextField that gets set by a DropDownChoice. If the choice is not other then I setEnabled to false and I place the string value of the DropDownChoice into the FocusableTextField. However the model is not persisted when setEnabled is false. Here is the code: // list of existing emailAddresses final List emailTypeList = Arrays.asList(EmailAddress.Type.values()); final ListView emailAddresses = new PropertyListView(emailAddresses) { @Override protected void populateItem(final ListItem item) { final EmailAddress email = (EmailAddress) item.getModelObject(); final FocusableTextField emailLabel = new FocusableTextField(label, page); if (email.getType() != EmailAddress.Type.OTHER) emailLabel.setEnabled(false); 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.setEnabled(true); emailLabel.requestFocus(); } else { emailLabel.setModelValue(newSelection.toString()); emailLabel.setEnabled(false); } } }); snip In this email example the dropdown choices are home, work, and other. If user selects home or work I want the value of the FocusableTextField to be home or work and I do not want the user to be able to edit the field. That's why I set the field's isEnabled to false. On the other hand, if the user selects other, then I set isEnabled to true so that the user can edit the field. This works properly (persists the value) because isEnabled is true. Is there a workaround for this problem or can someone recommend a different approach? -- View this message in context: http://www.nabble.com/setEnabled%28false%29-on-FocusableTextField-breaks-persistence-tf4351731.html#a12399840 Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: setEnabled(false) on FocusableTextField breaks persistence
So it sounds like I would use something like: final AttributeModifier ro = new AttributeModifier(readonly, true, new Model(readonly)); if (email.getType() != EmailAddress.Type.OTHER) emailLabel.add(ro); If so, then the question becomes, how would I remove that attribute or reset emailLabel to editable? igor.vaynberg wrote: the entire point of disabling the component is that you do not want it to process submitted input and update its model. you are looking for readonly behavior rather then disabled i think. why not just set the readonly attribute on that field. -igor On 8/29/07, janders [EMAIL PROTECTED] wrote: I posted this on the Databinder forum but no one seems to know of a work-around so I thought I'd post it here. Essentially I have a FocusableTextField that gets set by a DropDownChoice. If the choice is not other then I setEnabled to false and I place the string value of the DropDownChoice into the FocusableTextField. However the model is not persisted when setEnabled is false. Here is the code: // list of existing emailAddresses final List emailTypeList = Arrays.asList(EmailAddress.Type.values()); final ListView emailAddresses = new PropertyListView(emailAddresses) { @Override protected void populateItem(final ListItem item) { final EmailAddress email = (EmailAddress) item.getModelObject(); final FocusableTextField emailLabel = new FocusableTextField(label, page); if (email.getType() != EmailAddress.Type.OTHER) emailLabel.setEnabled(false); 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.setEnabled(true); emailLabel.requestFocus(); } else { emailLabel.setModelValue(newSelection.toString()); emailLabel.setEnabled(false); } } }); snip In this email example the dropdown choices are home, work, and other. If user selects home or work I want the value of the FocusableTextField to be home or work and I do not want the user to be able to edit the field. That's why I set the field's isEnabled to false. On the other hand, if the user selects other, then I set isEnabled to true so that the user can edit the field. This works properly (persists the value) because isEnabled is true. Is there a workaround for this problem or can someone recommend a different approach? -- View this message in context: http://www.nabble.com/setEnabled%28false%29-on-FocusableTextField-breaks-persistence-tf4351731.html#a12399840 Sent from the Wicket - User mailing list archive at Nabble.com. - 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#a12400575 Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: setEnabled(false) on FocusableTextField breaks persistence
create a dynamic model instead of new Model(readonly) -igor On 8/29/07, janders [EMAIL PROTECTED] wrote: So it sounds like I would use something like: final AttributeModifier ro = new AttributeModifier(readonly, true, new Model(readonly)); if (email.getType() != EmailAddress.Type.OTHER) emailLabel.add(ro); If so, then the question becomes, how would I remove that attribute or reset emailLabel to editable? igor.vaynberg wrote: the entire point of disabling the component is that you do not want it to process submitted input and update its model. you are looking for readonly behavior rather then disabled i think. why not just set the readonly attribute on that field. -igor On 8/29/07, janders [EMAIL PROTECTED] wrote: I posted this on the Databinder forum but no one seems to know of a work-around so I thought I'd post it here. Essentially I have a FocusableTextField that gets set by a DropDownChoice. If the choice is not other then I setEnabled to false and I place the string value of the DropDownChoice into the FocusableTextField. However the model is not persisted when setEnabled is false. Here is the code: // list of existing emailAddresses final List emailTypeList = Arrays.asList(EmailAddress.Type.values()); final ListView emailAddresses = new PropertyListView(emailAddresses) { @Override protected void populateItem(final ListItem item) { final EmailAddress email = (EmailAddress) item.getModelObject(); final FocusableTextField emailLabel = new FocusableTextField(label, page); if (email.getType() != EmailAddress.Type.OTHER) emailLabel.setEnabled(false); 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.setEnabled(true); emailLabel.requestFocus(); } else { emailLabel.setModelValue(newSelection.toString()); emailLabel.setEnabled(false); } } }); snip In this email example the dropdown choices are home, work, and other. If user selects home or work I want the value of the FocusableTextField to be home or work and I do not want the user to be able to edit the field. That's why I set the field's isEnabled to false. On the other hand, if the user selects other, then I set isEnabled to true so that the user can edit the field. This works properly (persists the value) because isEnabled is true. Is there a workaround for this problem or can someone recommend a different approach? -- View this message in context: http://www.nabble.com/setEnabled%28false%29-on-FocusableTextField-breaks-persistence-tf4351731.html#a12399840 Sent from the Wicket - User mailing list archive at Nabble.com. - 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#a12400575 Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: setEnabled(false) on FocusableTextField breaks persistence
I know how to add the attribute, I just don't know how to later remove it once added. - JA Eelco Hillenius wrote: So it sounds like I would use something like: final AttributeModifier ro = new AttributeModifier(readonly, true, new Model(readonly)); if (email.getType() != EmailAddress.Type.OTHER) emailLabel.add(ro); If so, then the question becomes, how would I remove that attribute or reset emailLabel to editable? Always add the attribute modifier, override isEnabled and let that return true if you want to add the attribute, and false if you don't. 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#a12400705 Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: setEnabled(false) on FocusableTextField breaks persistence
I know how to add the attribute, I just don't know how to later remove it once added. Like I said, override isEnabled in your attribute modifier. When that returns false, the attribute won't be added. For normal requests, where a page is rendered everytime again, it simply doesn't show up. For ajax request, you'll have to add to the ajaxrequest for re-rendering and the attribute should disappear as well. Eelco - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: setEnabled(false) on FocusableTextField breaks persistence
I don't understand. Are you saying that I should use setEnabled(false) or are you saying that I should use: final AttributeModifier rof = new AttributeModifier(readonly, false, new Model(readonly)); Either way this doesn't seem to work. - JA Eelco Hillenius wrote: I know how to add the attribute, I just don't know how to later remove it once added. Like I said, override isEnabled in your attribute modifier. When that returns false, the attribute won't be added. For normal requests, where a page is rendered everytime again, it simply doesn't show up. For ajax request, you'll have to add to the ajaxrequest for re-rendering and the attribute should disappear as well. 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#a12400938 Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: setEnabled(false) on FocusableTextField breaks persistence
I don't understand. Are you saying that I should use setEnabled(false) or are you saying that I should use: final AttributeModifier rof = new AttributeModifier(readonly, false, new Model(readonly)); new AttributeModifier(readonly, true, new Model(readonly) { public boolean isEnabled(Component c) { return shouldTheAttributeBeAdded(); } } and don't add the attribute in your markup. Eelco - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]