Description
I need to execute some JavaScript before form is submmited and as method getTriggerJavaScrip is final I have to do it like
SubmitLink link = new SubmitLink("link") {
private static final long serialVersionUID = 1L;
@Override
protected void onComponentTag(ComponentTag tag)
{
super.onComponentTag(tag);
// If we're disabled
if (!isLinkEnabled())
else
{
if (tag.getName().equalsIgnoreCase("a"))
tag.put("onclick", getTriggerJavaScript1());
}
}
protected String getTriggerJavaScript1()
{
if (getForm() != null)
{
// find the root form - the one we are really going to submit
Form<?> root = getForm().getRootForm();
StringBuilder sb = new StringBuilder(100);
// my code
sb.append("document.getElementById('");
sb.append(description.getMarkupId());
sb.append("').value=CKEDITOR.instances.");
sb.append(description.getMarkupId());
sb.append(".getData();");
// end of my code
sb.append("var e=document.getElementById('");
sb.append(root.getHiddenFieldId());
sb.append("'); e.name=\'");
sb.append(getInputName());
sb.append("'; e.value='x';");
sb.append("var f=document.getElementById('");
sb.append(root.getMarkupId());
sb.append("');");
if (shouldInvokeJavaScriptFormOnsubmit())
{
if (getForm() != root)
else
{ sb.append("var ff=f;"); }sb.append("if (ff.onsubmit != undefined)
{ if (ff.onsubmit()==false) return false; }");
}
sb.append("f.submit();e.value='';e.name='';return false;");
return sb.toString();
}
else
}
};
This ugly and moreover if form submiting logic changes my extended link might stop to work properly. I propose adding a method decorareTriggerJavaScript that allows users to decorate the form submiting script. e.g. in my case
SubmitLink link = new SubmitLink("link") {
private static final long serialVersionUID = 1L;
@Override
protected void decorareTriggerJavaScript(StringBuilder sb)
};