On 3/26/07, Johan Compagner <[EMAIL PROTECTED]> wrote:
Why cant you work with static id's when you do override getMarkupId?
If you do that and then return:
return getMarkupAttributes().get("id")
then that should work fine
Then I have to create custom components for all components where I
attach this behavior to. That is intrusive and cumbersome.
For now I have subclassed AjaxFormComponentUpdatingBehavior and
overwritten everything Wicket does:
public abstract class IridiumAjaxFormComponentUpdatingBehavior extends
AjaxFormComponentUpdatingBehavior
{
public IridiumAjaxFormComponentUpdatingBehavior(String event)
{
super(event);
}
@Override
protected void onBind()
{
// expliciet super.onBind uitgezet, deze zet namelijk
standaard de output markup
// id op true. Dit clasht met eigen geschreven javascript in
de pagina. Gebruikers
// moeten zelf setOutputMarkupId aanzetten op de component.
if (!(getComponent() instanceof FormComponent))
{
throw new WicketRuntimeException("Behavior "
+ getClass().getName() + " can only be added to an
isntance of a FormComponent");
}
}
@Override
protected void onComponentTag(final ComponentTag tag)
{
// zorg ervoor dat we de markup id pushen als deze niet in de
markup gezet is.
String id = getComponent().getMarkupAttributes().getString("id");
if (id == null)
{
id = getComponent().getMarkupId();
tag.put("id", id);
}
super.onComponentTag(tag);
// only add the event handler when the component is enabled.
if (this.getComponent().isEnabled())
{
tag.put(getEvent(), getMyEventHandler(id));
}
}
/**
* @see wicket.ajax.AjaxEventBehavior#getEventHandler()
*/
private CharSequence getMyEventHandler(String id)
{
return getCallbackScript(new
AppendingStringBuffer("wicketAjaxPost('").append(
getCallbackUrl()).append(
"', wicketSerialize(document.getElementById('" + id +
"'))"), null, null);
}
}
Martijn
--
Learn Wicket at ApacheCon Europe: http://apachecon.com
Join the wicket community at irc.freenode.net: ##wicket
Wicket 1.2.5 will keep your server alive. Download Wicket now!
http://wicketframework.org