To include JSP files in your Wicket templates with much of the same flexibility as jsp:include, we will create a custom Wicket component that will take care of thisThis version allows you to use custom tag <wicket:jsp file="/foo.jsp"/> as a wicket container, and you can add some attributes to the request before JSP file is processed.
Code Block | ||
---|---|---|
| ||
public class WicketJspResolver implements IComponentResolver { private static final long serialVersionUID = 1L; private static final Logger log = LoggerFactory.getLogger(WicketJspResolver.class); static { // Register the jsp tag within the wicket tag namespace WicketTagIdentifier.registerWellKnownTagName("jsp"); } public boolean resolve(final MarkupContainer container, final MarkupStream markupStream, final ComponentTag tag) { if (tag instanceof WicketTag) { WicketTag wtag = (WicketTag)tag; if ("jsp".equalsIgnoreCase(wtag.getName())) { String file = wtag.getAttributes().getString("file"); if (file == null || file.trim().length() == 0) { throw new MarkupException("Wrong format of <wicket:jsp file='foo.jsp'>: attribute 'file' is missing"); } // Add the jsp component to the component hierarchy container.autoAdd(new JspFileContainer(file), markupStream); // We did process the tag return true; } } // We did not process the tag return false; } |
...