java - render whole Wicket Header in Body -
java - render whole Wicket Header in Body -
i rendering wicket pages (version 6.x) portletcontainer - works fine (with restrictions).
one of them is, cannot utilize ajax because html markup has no html , head tag, content of body tag rendering.
i tried utilize headerresponsecontainer works - long there head tag in markup. when there isn't iheaderresponsedecorator not set requestcycle.
i not sure best way render rendered in head tag container in body if there no head tag.
any ideas how come around this?
it seems hack works. if can come cleaner solution please post here.
otherwise might help in similar cases:
in application class:
@override protected webresponse newwebresponse(webrequest webrequest, httpservletresponse httpservletresponse) { homecoming new mywebresponse((servletwebrequest) webrequest, httpservletresponse); } implementation of mywebresponse:
public class mywebresponse extends servletwebresponse { static pattern bodycontentpattern = pattern.compile("<body[^>]*>((?s).*)</body>"); static pattern headcontentpattern = pattern.compile("<head[^>]*>((?s).*)</head>"); public mywebresponse(servletwebrequest webrequest, httpservletresponse httpservletresponse) { super(webrequest, httpservletresponse); } @override public void write(charsequence sequence) { string string = sequence.tostring(); // if there html tag, take body content, append header content in // div tag , write output stream if (string.contains("</html>")) { stringbuilder sb = new stringbuilder(); sb.append(findcontent(string, bodycontentpattern)); string headcontent = findcontent(string, headcontentpattern); if (headcontent != null && headcontent.length() > 0) { sb.append("<div class=\"head\">"); sb.append(headcontent); sb.append("</div>"); } super.write(sb.tostring()); } else { super.write(sequence); } } private string findcontent(string sequence, pattern p) { matcher m = p.matcher(sequence); if (m.find()) { homecoming m.group(1); } homecoming sequence; } } java wicket wicket-6
Comments
Post a Comment