get the components markupid from the component itself. johan
On Thu, May 15, 2008 at 3:03 PM, Eyal Golan <[EMAIL PROTECTED]> wrote: > thanks, > that's exactly what I did. > I add to my component (button) an AbstarctBehavior, which is an > IHeaderContributor. > I even override renderHead: > @Override > public void renderHead(IHeaderResponse response) { > > response.renderCSSReference("/eurekify/style/button/EurekifyButton.css"); > > > response.renderJavascriptReference("/eurekify/style/button/EurekifyButton.js"); > // response.renderJavascriptReference(new > JavascriptResourceReference( > // EurekifyButtonBehavior.class, "resizeScript.js")); > } > > The script I am adding to each button comes from a utility class: > static String getResizeScript(String markupId) { > StringBuilder strBuilder = new StringBuilder(); > strBuilder.append("<script language=\"javascript\">"); > strBuilder.append("document.getElementById('btnObj_"); > strBuilder.append(markupId); > strBuilder.append("').style.width = calcBtnSize('"); > strBuilder.append(markupId).append("')"); > strBuilder.append("</script>"); > return strBuilder.toString(); > } > > This is the script that I mentioned in my first question. > > Again: > If I call this script in the Button class, in the onAfterRender() method, > it > is added to the end of the output HTML. > If I call this in the behavior, in the onRendered(Component component), it > is added just after the </button>. > > I did something like this in the onload script: > window.onload = function(id) { > document.getElementById('btnObj_'+id).style.width = function(id) > {calcBtnSize(id)}; > } > > firebug says that it can't find document.getElementById('btnObj_'+id) ... > On Thu, May 15, 2008 at 3:50 PM, Johan Compagner <[EMAIL PROTECTED]> > wrote: > > > you can also do it on component > > public void renderHead(final HtmlHeaderContainer container) > > > > or let the component implement IHeaderContributor > > > > i guess that renderHead(final HtmlHeaderContainer container) shouldnt be > > public but more protected or final.. > > > > johan > > > > > > On Thu, May 15, 2008 at 2:44 PM, Eyal Golan <[EMAIL PROTECTED]> wrote: > > > > > ok. thank, I'll try it (though I have never written JavaScript till a > few > > > days ago...) > > > BTW, why is the difference between the overriding method and the > behavior > > > method? > > > > > > On Thu, May 15, 2008 at 2:52 PM, Johan Compagner <[EMAIL PROTECTED] > > > > > wrote: > > > > > > > use a behavior that adds an onDocumentLoad/Ready script to the > browser > > > > > > > > On Thu, May 15, 2008 at 12:35 PM, Eyal Golan <[EMAIL PROTECTED]> > > wrote: > > > > > > > > > Hello, > > > > > I have a MyButton that extends Button. > > > > > I have a JavaScript that I need to ad to the output markup after > the > > > > > button's markup. > > > > > I'm trying to do this with two differnet options: > > > > > Either I Override onAfterRender in MyButton: > > > > > @Override > > > > > protected void onAfterRender() { > > > > > if (isVisible()) { > > > > > > > getResponse().write(Consts.getResizeScript(getMarkupId())); > > > > > } > > > > > super.onAfterRender(); > > > > > } > > > > > > > > > > Or, I add to the button a behavior and write this: > > > > > @Override > > > > > public void onRendered(Component component) { > > > > > if (component.isVisible()) { > > > > > > > > > > > > > > > > > > > > > > > > > component.getResponse().write(Consts.getResizeScript(component.getMarkupId())); > > > > > } > > > > > > > > > > } > > > > > > > > > > Now, the situation is like this: > > > > > Using the first option (override in the component), the script is > > added > > > > to > > > > > the end of the html. Just after the </html> > > > > > Using the second option (the behavior), the script is added just > > after > > > > the > > > > > close tag of the button </button>. > > > > > > > > > > Using FF, all is ok, but in IE7, there's a problem in calculating > the > > > > size > > > > > and the button is not shown correctly. > > > > > > > > > > What causes the differences? and how can I manipulate the behavior > to > > > > work > > > > > like option 1 ? > > > > > > > > > > Thanks very much... > > > > > > > > > > -- > > > > > Eyal Golan > > > > > [EMAIL PROTECTED] > > > > > > > > > > Visit: http://jvdrums.sourceforge.net/ > > > > > > > > > > > > > > > > > > > > > -- > > > Eyal Golan > > > [EMAIL PROTECTED] > > > > > > Visit: http://jvdrums.sourceforge.net/ > > > > > > > > > -- > Eyal Golan > [EMAIL PROTECTED] > > Visit: http://jvdrums.sourceforge.net/ >