You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by wheleph <wh...@gmail.com> on 2007/11/01 16:54:53 UTC

Disabling Palette buttons

Hello everyone!

I want to disable remove button when the list of selected choices is empty. 
Below is my sublclass. But when I click on the button browser says that
"Component with id [[contentPanel_pupilForm_pupilPalette_addButton]] a was
not found while trying to perform markup update. ..." As you see I call
setOutputMarkupId(true). What's wrong?

[code]
	private class PupilPalette extends Palette {
		private Component addButton;
		private Component removeButton;
		
		public PupilPalette(final String id, final IModel model, 
				final IModel choicesModel, final IChoiceRenderer choiceRenderer, 
				final int rows, final boolean allowOrder) {
			super(id, model, choicesModel, choiceRenderer, rows, allowOrder);
			setOutputMarkupId(true);
			getRecorderComponent().add(new
AjaxFormComponentUpdatingBehavior("onchange") {
				@Override
				protected void onUpdate(final AjaxRequestTarget target) {
					addButton.setEnabled(availablePupils.size() == selectedPupils.size());
					removeButton.setEnabled(selectedPupils.isEmpty());
					target.addComponent(addButton);
					target.addComponent(removeButton);
				}
				
			});
		}
		
		/** {@inheritDoc} */
		@Override
		protected Component newAvailableHeader(final String componentId) {
			return new Label(componentId, getString("available.pupils"));
		}
		
		/** {@inheritDoc} */
		@Override
		protected Component newSelectedHeader(final String componentId) {
			return new Label(componentId, getString("selected.pupils"));
		}
		
		/** {@inheritDoc} */
		@Override
		protected Component newAddComponent() {
			addButton = super.newAddComponent();
			addButton.setOutputMarkupId(true);
			return addButton;
		}
		
		/** {@inheritDoc} */
		@Override
		protected Component newRemoveComponent() {
			removeButton = super.newRemoveComponent();
			removeButton.setOutputMarkupId(true);
			return removeButton;
		}
		
	}
[/code]
wheleph
-- 
View this message in context: http://www.nabble.com/Disabling-Palette-buttons-tf4732206.html#a13531373
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: Disabling Palette buttons

Posted by Igor Vaynberg <ig...@gmail.com>.
webmarkupcontainers were used because the buttons do not need to
submit anything to serverside, they are just there to add an onclick
javascript. i agree they dont handle disabling properly and that is a
bug, please open a jira issue.

-igor


On 11/2/07, wheleph <wh...@gmail.com> wrote:
>
> I solved the problem by creating custom add and remove buttons. It turned out
> that the original buttons that are used by Palette are not subclasses of
> Button but subclasses of WebMarkupContainer and hence they don't properly
> support disabled state and generating of markup id. I wonder why plain
> buttons were not used. Now I use the following subclass and it works just
> fine:
>
> [code]
>         private class PupilPalette extends Palette {
>                 private static final long serialVersionUID = 6962784629546969362L;
>
>                 private Button addButton;
>                 private Button removeButton;
>
>                 public PupilPalette(final String id, final IModel model,
>                                 final IModel choicesModel, final IChoiceRenderer choiceRenderer,
>                                 final int rows, final boolean allowOrder) {
>                         super(id, model, choicesModel, choiceRenderer, rows, allowOrder);
>                         setOutputMarkupId(true);
>                         getRecorderComponent().add(new
> AjaxFormComponentUpdatingBehavior("onchange") {
>
>                                 private static final long serialVersionUID = -1322527042794395640L;
>
>                                 @Override
>                                 protected void onUpdate(final AjaxRequestTarget target) {
>                                         checkButtonsEnabled();
>                                         target.addComponent(addButton);
>                                         target.addComponent(removeButton);
>                                 }
>
>                         });
>                         checkButtonsEnabled();
>                 }
>
>                 /**
>                  * Checks whether the add or remove buttons are enabled.
>                  */
>                 private void checkButtonsEnabled() {
>                         addButton.setEnabled(availablePupils.size() != selectedPupils.size());
>                         removeButton.setEnabled(!selectedPupils.isEmpty());
>                 }
>
>                 /** {@inheritDoc} */
>                 @Override
>                 protected Component newAvailableHeader(final String componentId) {
>                         return new Label(componentId, getString("available.pupils"));
>                 }
>
>                 /** {@inheritDoc} */
>                 @Override
>                 protected Component newSelectedHeader(final String componentId) {
>                         return new Label(componentId, getString("selected.pupils"));
>                 }
>
>                 /** {@inheritDoc} */
>                 @Override
>                 protected Component newAddComponent() {
>                         addButton = new Button("addButton", new Model("->")) {
>
>                                 private static final long serialVersionUID = 0L;
>
>                                 protected void onComponentTag(final ComponentTag tag) {
>                                         super.onComponentTag(tag);
>                                         tag.getAttributes().put("onclick",
> PupilPalette.this.getAddOnClickJS());
>                                 }
>                         };
>                         addButton.add(new Image("image", new ResourceReference(Palette.class,
> "add.gif")));
>
>                         addButton.setOutputMarkupId(true);
>                         return addButton;
>                 }
>
>                 /** {@inheritDoc} */
>                 @Override
>                 protected Component newRemoveComponent() {
>                         removeButton = new Button("removeButton") {
>                                 private static final long serialVersionUID = 1L;
>
>                                 protected void onComponentTag(final ComponentTag tag) {
>                                         super.onComponentTag(tag);
>                                         tag.getAttributes().put("onclick",
> PupilPalette.this.getRemoveOnClickJS());
>                                 }
>                         };
>                         removeButton.add(new Image("image", new ResourceReference(Palette.class,
> "remove.gif")));
>                         removeButton.setOutputMarkupId(true);
>                         return removeButton;
>                 }
>
>         }
> [/code]
>
> wheleph
>
> --
> View this message in context: http://www.nabble.com/Disabling-Palette-buttons-tf4732206.html#a13545250
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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: Disabling Palette buttons

Posted by wheleph <wh...@gmail.com>.
I solved the problem by creating custom add and remove buttons. It turned out
that the original buttons that are used by Palette are not subclasses of
Button but subclasses of WebMarkupContainer and hence they don't properly
support disabled state and generating of markup id. I wonder why plain
buttons were not used. Now I use the following subclass and it works just
fine:

[code]
	private class PupilPalette extends Palette {
		private static final long serialVersionUID = 6962784629546969362L;

		private Button addButton;
		private Button removeButton;
		
		public PupilPalette(final String id, final IModel model, 
				final IModel choicesModel, final IChoiceRenderer choiceRenderer, 
				final int rows, final boolean allowOrder) {
			super(id, model, choicesModel, choiceRenderer, rows, allowOrder);
			setOutputMarkupId(true);
			getRecorderComponent().add(new
AjaxFormComponentUpdatingBehavior("onchange") {

				private static final long serialVersionUID = -1322527042794395640L;

				@Override
				protected void onUpdate(final AjaxRequestTarget target) {
					checkButtonsEnabled();
					target.addComponent(addButton);
					target.addComponent(removeButton);
				}
				
			});
			checkButtonsEnabled();
		}
		
		/**
		 * Checks whether the add or remove buttons are enabled.
		 */
		private void checkButtonsEnabled() {
			addButton.setEnabled(availablePupils.size() != selectedPupils.size());
			removeButton.setEnabled(!selectedPupils.isEmpty());
		}
		
		/** {@inheritDoc} */
		@Override
		protected Component newAvailableHeader(final String componentId) {
			return new Label(componentId, getString("available.pupils"));
		}
		
		/** {@inheritDoc} */
		@Override
		protected Component newSelectedHeader(final String componentId) {
			return new Label(componentId, getString("selected.pupils"));
		}
		
		/** {@inheritDoc} */
		@Override
		protected Component newAddComponent() {
			addButton = new Button("addButton", new Model("->")) {

				private static final long serialVersionUID = 0L;

				protected void onComponentTag(final ComponentTag tag) {
					super.onComponentTag(tag);
					tag.getAttributes().put("onclick",
PupilPalette.this.getAddOnClickJS());
				}
			};
			addButton.add(new Image("image", new ResourceReference(Palette.class,
"add.gif")));

			addButton.setOutputMarkupId(true);
			return addButton;
		}
		
		/** {@inheritDoc} */
		@Override
		protected Component newRemoveComponent() {
			removeButton = new Button("removeButton") {
				private static final long serialVersionUID = 1L;

				protected void onComponentTag(final ComponentTag tag) {
					super.onComponentTag(tag);
					tag.getAttributes().put("onclick",
PupilPalette.this.getRemoveOnClickJS());
				}
			};
			removeButton.add(new Image("image", new ResourceReference(Palette.class,
"remove.gif")));
			removeButton.setOutputMarkupId(true);
			return removeButton;
		}
		
	}
[/code]

wheleph

-- 
View this message in context: http://www.nabble.com/Disabling-Palette-buttons-tf4732206.html#a13545250
Sent from the Wicket - User mailing list archive at Nabble.com.


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