Skip to main content



      Home
Home » Eclipse Projects » Virgo » Virgo Snaps: Templating via Fillter
Virgo Snaps: Templating via Fillter [message #981737] Mon, 12 November 2012 11:58 Go to next message
Eclipse UserFriend
Hey,

Currently i am developing a pluggable Webapplication with virgo-server and virgo snaps. Therefore i would like to implement some kind of templating where the
host provides a general layout. If a snap is called the snap should integrate its output in the hosts template.

My approach so far is to use a filter which wrapps html around the response of every snap. My problem is that the filter that i have defined after the SnapHostFilter in the web.xml is not executed.

If i define my filter before the SnapHostFilter it gets executed but then the actual response to the client only contains the wrapping-html but not the output from the snap.

Does anybody have an idea why it is not working? or how i could implement some kind of templating that is controlled by the host?

Thanks very much


public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
						
		OutputStream out = response.getOutputStream();
		  out.write("<HR>PRE<HR>".getBytes());
		  GenericResponseWrapper wrapper = new GenericResponseWrapper((HttpServletResponse) response); 
		  chain.doFilter(request,wrapper);
		  out.write(wrapper.getData());
		  //out.write("<HR>POST<HR>".getBytes());
		  out.close(); 		
	}



web.xml

        <filter>
		<filter-name>springSecurityFilterChain</filter-name>
		<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
	</filter>

	<filter-mapping>
		<filter-name>springSecurityFilterChain</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

         <filter>
		<filter-name>templateFilter</filter-name>		
		<filter-class>de.project.bai.webapp.templating.TemplateFilter</filter-class>
	</filter>

        <filter-mapping>
		<filter-name>templateFilter</filter-name>
		<url-pattern>/base/web/*</url-pattern>		
		<dispatcher>INCLUDE</dispatcher>
		<dispatcher>FORWARD</dispatcher>
		<dispatcher>REQUEST</dispatcher>
	</filter-mapping>
	
	<filter>
		<filter-name>host-filter</filter-name>
		<filter-class>org.eclipse.virgo.snaps.core.SnapHostFilter</filter-class>
	</filter>

	<filter-mapping>
		<filter-name>host-filter</filter-name>
		<url-pattern>/*</url-pattern>
		<dispatcher>INCLUDE</dispatcher>
		<dispatcher>FORWARD</dispatcher>
		<dispatcher>REQUEST</dispatcher>
	</filter-mapping>
Re: Virgo Snaps: Templating via Fillter [message #986843 is a reply to message #981737] Wed, 21 November 2012 17:04 Go to previous messageGo to next message
Eclipse UserFriend
If you look at the 'animals' sample application that comes with Snaps it does what you're looking for but in a different way. It uses JSPs to import a header and footer file from the host to all of the Snaps JSP files. I can't see anything obvious wrong with your web.xml but I also don't know much about their syntax. Should the template and host filters not have the same mapping to ensure that all content from snaps gets wrapped.

Hope that is of some help.
Chris.
Re: Virgo Snaps: Templating via Fillter [message #987728 is a reply to message #986843] Tue, 27 November 2012 14:01 Go to previous messageGo to next message
Eclipse UserFriend
You could also use sitemesh. That worked fine.

Re: Virgo Snaps: Templating via Fillter [message #987866 is a reply to message #987728] Wed, 28 November 2012 07:47 Go to previous message
Eclipse UserFriend
Thanks for the suggestions!!

@ Chris Frost
I had alread checked out the animal-example. As far as I remember with this approach i would have to include the header and the bottom in every jsp file in every snap manually. My requirement is that the template is injected automatically without giving a snap the ability to mess around with it. I dont think with the animal-approach that is not possible right? With the filter you are right. I will change that.

@Dmitry Sklyut
Just looked at an example of sitemesh. looks promising! i will give it a try!
Previous Topic:SpringDM Managed Service List is not updated with new services
Next Topic:Virgo 3.6.0.M04
Goto Forum:
  


Current Time: Wed Jul 16 09:57:04 EDT 2025

Powered by FUDForum. Page generated in 0.30994 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top