You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "Artur W." <a_...@gazeta.pl> on 2008/10/11 14:34:10 UTC

AbstractBehavior problem after comonent re-render

Hi!

I added simple simple behavior:

public class XDateField extends DateTextField {

    public XDateField(String id, IModel model) {
        super(id, model, "yyyy-MM-dd");

        add(new AbstractBehavior() {
            @Override
            public void onRendered(Component component) {
                Response response = component.getResponse();
                response.write("\n&lt;a href=\"#\" onclick=\"changeDate('" +
component.getMarkupId() + "', -1)\"&gt;(DEC)&lt;/a&gt;");
            }
        });
        add(new DatePicker());
    }
}

It is rendering ok. But when the component is re-rendered via ajax
(target.addComponent(dateTextField))
my behavior is re-added. After each re-render my link looks like this:
[component] (DEC)(DEC)(DEC)(DEC)... [calendarIcon]


How to fix it?

Thanks in advance,
Artur


-- 
View this message in context: http://www.nabble.com/AbstractBehavior-problem-after-comonent-re-render-tp19932224p19932224.html
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: AbstractBehavior problem after comonent re-render

Posted by "Artur W." <a_...@gazeta.pl>.
Ok, I fixed it. I needed to remove it if it was rerendered again with ajax:

	private class ChangeDateBehavior extends AbstractBehavior {

		private Component component;
		private int days;

		public ChangeDateBehavior(int days) {
			this.days = days;
		}

		public void renderHead(IHeaderResponse response) {
			if (AjaxRequestTarget.get() != null) {
				final String javascript = "var e = Wicket.$('" + getMarkupId() +
						"'); if (e != null && typeof(e.parentNode) != 'undefined')
e.parentNode.removeChild(e);";
				response.renderJavascript(javascript, null);
			}
		}

		@Override
		public void onRendered(Component component) {
			Response response = component.getResponse();
			response.write("\n&lt;a id=\"" + getMarkupId() + "\"href=\"#\"
onclick=\"changeDate('" + component.getMarkupId() + "', " +
Integer.toString(days) + ")\"&gt;&lt;&lt;/a&gt;");
		}

		@Override
		public void bind(Component component) {
			this.component = component;
		}

		public String getMarkupId() {
			return component.getMarkupId() + "--cd";
		}

	}


Artur

-- 
View this message in context: http://www.nabble.com/AbstractBehavior-problem-after-comonent-re-render-tp19932224p19933012.html
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: AbstractBehavior problem after comonent re-render

Posted by James Carman <ja...@carmanconsulting.com>.
Can you just override isTemporary()?

On Sat, Oct 11, 2008 at 8:34 AM, Artur W. <a_...@gazeta.pl> wrote:
>
> Hi!
>
> I added simple simple behavior:
>
> public class XDateField extends DateTextField {
>
>    public XDateField(String id, IModel model) {
>        super(id, model, "yyyy-MM-dd");
>
>        add(new AbstractBehavior() {
>            @Override
>            public void onRendered(Component component) {
>                Response response = component.getResponse();
>                response.write("\n&lt;a href=\"#\" onclick=\"changeDate('" +
> component.getMarkupId() + "', -1)\"&gt;(DEC)&lt;/a&gt;");
>            }
>        });
>        add(new DatePicker());
>    }
> }
>
> It is rendering ok. But when the component is re-rendered via ajax
> (target.addComponent(dateTextField))
> my behavior is re-added. After each re-render my link looks like this:
> [component] (DEC)(DEC)(DEC)(DEC)... [calendarIcon]
>
>
> How to fix it?
>
> Thanks in advance,
> Artur
>
>
> --
> View this message in context: http://www.nabble.com/AbstractBehavior-problem-after-comonent-re-render-tp19932224p19932224.html
> 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