Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » Virgo Snaps: Templating via Fillter
Virgo Snaps: Templating via Fillter [message #981737] Mon, 12 November 2012 16:58 Go to next message
Markus Schmailzl is currently offline Markus SchmailzlFriend
Messages: 6
Registered: November 2012
Junior Member
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 22:04 Go to previous messageGo to next message
Chris Frost is currently offline Chris FrostFriend
Messages: 230
Registered: January 2010
Location: Southampton, England
Senior Member

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.


------------------------------------------------
Chris Frost, Twitter @cgfrost
Springsource, a divison of VMware.
Re: Virgo Snaps: Templating via Fillter [message #987728 is a reply to message #986843] Tue, 27 November 2012 19:01 Go to previous messageGo to next message
Dmitry Sklyut is currently offline Dmitry SklyutFriend
Messages: 279
Registered: January 2010
Senior Member
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 12:47 Go to previous message
Markus Schmailzl is currently offline Markus SchmailzlFriend
Messages: 6
Registered: November 2012
Junior Member
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: Thu Mar 28 13:06:52 GMT 2024

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

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

Back to the top