Author: ivaynberg Date: Tue Nov 14 23:13:30 2006 New Revision: 475139 URL: http://svn.apache.org/viewvc?view=rev&rev=475139 Log: tweaks
Modified: incubator/wicket/trunk/wicket/src/main/java/wicket/behavior/AbstractBehavior.java incubator/wicket/trunk/wicket/src/main/java/wicket/markup/html/IHeaderResponse.java incubator/wicket/trunk/wicket/src/main/java/wicket/markup/html/WebPage.java Modified: incubator/wicket/trunk/wicket/src/main/java/wicket/behavior/AbstractBehavior.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/behavior/AbstractBehavior.java?view=diff&rev=475139&r1=475138&r2=475139 ============================================================================== --- incubator/wicket/trunk/wicket/src/main/java/wicket/behavior/AbstractBehavior.java (original) +++ incubator/wicket/trunk/wicket/src/main/java/wicket/behavior/AbstractBehavior.java Tue Nov 14 23:13:30 2006 @@ -65,8 +65,14 @@ */ public final void rendered(final Component component) { - onRendered(component); - cleanup(); + try + { + onRendered(component); + } + finally + { + cleanup(); + } } /** @@ -85,8 +91,14 @@ */ public void exception(Component component, RuntimeException exception) { - onException(component, exception); - cleanup(); + try + { + onException(component, exception); + } + finally + { + cleanup(); + } } /** Modified: incubator/wicket/trunk/wicket/src/main/java/wicket/markup/html/IHeaderResponse.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/markup/html/IHeaderResponse.java?view=diff&rev=475139&r1=475138&r2=475139 ============================================================================== --- incubator/wicket/trunk/wicket/src/main/java/wicket/markup/html/IHeaderResponse.java (original) +++ incubator/wicket/trunk/wicket/src/main/java/wicket/markup/html/IHeaderResponse.java Tue Nov 14 23:13:30 2006 @@ -14,108 +14,111 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package wicket.markup.html; - -import java.io.Serializable; - -import wicket.ResourceReference; -import wicket.Response; - -/** - * Interface that is used to render header elements (usually javascript and CSS - * references). - * - * Implementation of this interface is responsible for filtering duplicate - * contributions (so that for example the same javascript is not loaded twice) - * during the same request. - * - * @author Matej Knopp - */ -public interface IHeaderResponse extends Serializable -{ - /** - * Writes a javascript reference, if the specified reference hasn't been - * rendered yet. - * - * @param reference - * resource reference pointing to the javascript resource - */ - public void renderJavascriptReference(ResourceReference reference); - - /** - * Renders javascript code to the response, if the javascript has not - * already been rendered. - * - * @param javascript - * javacript content to be rendered. - * - * @param id - * unique id for the javascript element. This can be null, - * however in that case the ajax header contribution can't detect - * duplicate script fragments. - */ - public void renderJavascript(CharSequence javascript, String id); - - /** - * Writes a CSS reference, if the specified reference hasn't been rendered - * yet. - * - * @param reference - * resource reference pointing to the CSS resource - */ - public void renderCSSReference(ResourceReference reference); - - /** - * Renders an arbitrary string to the header. The string is only rendered if - * the same string hasn't been rendered before. - * <p> - * Note: This method is kind of dangerous as users are able to write to the - * output whatever they like. - * - * @param string - * string to be rendered to head - */ - public void renderString(CharSequence string); - - /** - * Marks the given object as rendered. The object can be anything (string, - * resource reference, etc...). The purpose of this function is to allow - * user to manually keep track of rendered items. This can be useful for - * items that are expensive to generate (like interpolated text). - * - * @param object - * object to be marked as rendered. - */ - public void markRendered(Object object); - - /** - * Returns whether the given object has been marked as rendered. - * <ul> - * <li>Methods <code>renderJavascriptReference</code> and - * <code>renderCSSReference</code> mark the specified - * [EMAIL PROTECTED] ResourceReference} as rendered. - * <li>Method <code>renderJavascript</code> marks List of two elements - * (first is javascript body CharSequence and second is id) as rendered. - * <li>Method <code>renderString</code> marks the whole string as - * rendered. - * <li>Method <code>markRendered</code> can be used to mark an arbitrary - * object as rendered - * </ul> - * - * @param object - * Object that is queried to be rendered - * @return Whether the object has been marked as rendered during the request - */ - public boolean wasRendered(Object object); - - /** - * Returns the response that can be used to write arbitrary text to the head - * section. - * <p> - * Note: This method is kind of dangerous as users are able to write to the - * output whatever they like. - * - * @return Reponse - */ - public Response getResponse(); -} +package wicket.markup.html; + +import java.io.Serializable; + +import wicket.ResourceReference; +import wicket.Response; + +/** + * Interface that is used to render header elements (usually javascript and CSS + * references). + * + * Implementation of this interface is responsible for filtering duplicate + * contributions (so that for example the same javascript is not loaded twice) + * during the same request. + * + * @author Matej Knopp + */ +public interface IHeaderResponse extends Serializable +{ + /** + * Writes a javascript reference, if the specified reference hasn't been + * rendered yet. + * + * @param reference + * resource reference pointing to the javascript resource + */ + public void renderJavascriptReference(ResourceReference reference); + + /** + * Renders javascript code to the response, if the javascript has not + * already been rendered. + * + * the necessary surrounding <code>script</code> tags will be added to the + * output. + * + * @param javascript + * javacript content to be rendered. + * + * @param id + * unique id for the javascript element. This can be null, + * however in that case the ajax header contribution can't detect + * duplicate script fragments. + */ + public void renderJavascript(CharSequence javascript, String id); + + /** + * Writes a CSS reference, if the specified reference hasn't been rendered + * yet. + * + * @param reference + * resource reference pointing to the CSS resource + */ + public void renderCSSReference(ResourceReference reference); + + /** + * Renders an arbitrary string to the header. The string is only rendered if + * the same string hasn't been rendered before. + * <p> + * Note: This method is kind of dangerous as users are able to write to the + * output whatever they like. + * + * @param string + * string to be rendered to head + */ + public void renderString(CharSequence string); + + /** + * Marks the given object as rendered. The object can be anything (string, + * resource reference, etc...). The purpose of this function is to allow + * user to manually keep track of rendered items. This can be useful for + * items that are expensive to generate (like interpolated text). + * + * @param object + * object to be marked as rendered. + */ + public void markRendered(Object object); + + /** + * Returns whether the given object has been marked as rendered. + * <ul> + * <li>Methods <code>renderJavascriptReference</code> and + * <code>renderCSSReference</code> mark the specified + * [EMAIL PROTECTED] ResourceReference} as rendered. + * <li>Method <code>renderJavascript</code> marks List of two elements + * (first is javascript body CharSequence and second is id) as rendered. + * <li>Method <code>renderString</code> marks the whole string as + * rendered. + * <li>Method <code>markRendered</code> can be used to mark an arbitrary + * object as rendered + * </ul> + * + * @param object + * Object that is queried to be rendered + * @return Whether the object has been marked as rendered during the request + */ + public boolean wasRendered(Object object); + + /** + * Returns the response that can be used to write arbitrary text to the head + * section. + * <p> + * Note: This method is kind of dangerous as users are able to write to the + * output whatever they like. + * + * @return Reponse + */ + public Response getResponse(); +} Modified: incubator/wicket/trunk/wicket/src/main/java/wicket/markup/html/WebPage.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/markup/html/WebPage.java?view=diff&rev=475139&r1=475138&r2=475139 ============================================================================== --- incubator/wicket/trunk/wicket/src/main/java/wicket/markup/html/WebPage.java (original) +++ incubator/wicket/trunk/wicket/src/main/java/wicket/markup/html/WebPage.java Tue Nov 14 23:13:30 2006 @@ -25,7 +25,6 @@ import wicket.PageMap; import wicket.PageParameters; import wicket.ResourceReference; -import wicket.Response; import wicket.Session; import wicket.behavior.AbstractBehavior; import wicket.markup.MarkupFragment; @@ -261,7 +260,7 @@ // Create a body container, assuming that all HTML pages require a // <body> tag new HtmlBodyContainer(this, BodyOnLoadHandler.BODY_ID); - + // Add this little helper to the page this.bodyContainer = new BodyContainer(this, BodyOnLoadHandler.BODY_ID); @@ -347,8 +346,6 @@ */ public final void renderHead(final IHeaderResponse headResponse) { - Response response = headResponse.getResponse(); - final WebRequestCycle cycle = (WebRequestCycle)getRequestCycle(); final IRequestTarget target = cycle.getRequestTarget(); @@ -374,18 +371,21 @@ if (firstAccess) { + StringBuilder javascript = new StringBuilder(); // this is the first access to the pagemap, set window.name - JavascriptUtils.writeOpenTag(response); - response.write("if (window.name=='') { window.name=\""); - response.write(name); - response.write("\"; }"); - JavascriptUtils.writeCloseTag(response); + javascript.append("if (window.name=='') { window.name=\""); + javascript.append(name); + javascript.append("\"; }"); + + headResponse.renderJavascript(javascript.toString(), getClass().getName()); } else { - // Here is our trickery to detect whether the current request was + // Here is our trickery to detect whether the current request + // was // made in a new window/ tab, in which case it should go in a - // different page map so that we don't intermangle the history of + // different page map so that we don't intermangle the history + // of // those windows CharSequence url = null; if (target instanceof IBookmarkablePageRequestTarget) @@ -393,18 +393,20 @@ IBookmarkablePageRequestTarget current = (IBookmarkablePageRequestTarget)target; BookmarkablePageRequestTarget redirect = new BookmarkablePageRequestTarget( getSession().createAutoPageMapName(), current.getPageClass(), current - .getPageParameters()); + .getPageParameters()); url = cycle.urlFor(redirect); } else { url = urlFor(INewBrowserWindowListener.INTERFACE); } - JavascriptUtils.writeOpenTag(response); - response.write("if (window.name=='') { window.location=\""); - response.write(url); - response.write("\"; }"); - JavascriptUtils.writeCloseTag(response); + + StringBuilder javascript = new StringBuilder(); + javascript.append("if (window.name=='') { window.location=\""); + javascript.append(url); + javascript.append("\"; }"); + + headResponse.renderJavascript(javascript, getClass().getName()); } } }