<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>indiWiz.com &#187; portlet</title>
	<atom:link href="http://indiwiz.com/tag/portlet/feed/" rel="self" type="application/rss+xml" />
	<link>http://indiwiz.com</link>
	<description>Subhash&#039;s Tech Log</description>
	<lastBuildDate>Wed, 03 Mar 2010 13:24:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Serving Static and Dynamic Resources in JSR 286</title>
		<link>http://indiwiz.com/2009/02/20/serving-static-and-dynamic-resources-in-jsr-286/</link>
		<comments>http://indiwiz.com/2009/02/20/serving-static-and-dynamic-resources-in-jsr-286/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 11:45:08 +0000</pubDate>
		<dc:creator>Subhash Chandran</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jsr286]]></category>
		<category><![CDATA[portlet]]></category>

		<guid isPermaLink="false">http://indiwiz.com/?p=210</guid>
		<description><![CDATA[To serve static content packaged as part of the portlet WAR, we generally take this approach: &#60;%=response.encodeURL(request.getContextPath()+"/js/project.js")%&#62; For generating dynamic content what do we do? In JSR 168 this was not possible. Thankfully, JSR 286 introduced this important concept. For creating dynamic content, just override the void serveResource(ResourceRequest request, ResourceResponse response) method in javax.portlet.ResourceServingPortlet (implemented [...]]]></description>
			<content:encoded><![CDATA[<p>To serve static content packaged as part of the portlet WAR, we generally take this approach:</p>
<pre>
&lt;%=response.encodeURL(request.getContextPath()+"/js/project.js")%&gt;
</pre>
<p>For generating dynamic content what do we do? In JSR 168 this was not possible. Thankfully, JSR 286 introduced this important concept. For creating dynamic content, just override the <tt>void serveResource(ResourceRequest request, ResourceResponse response)</tt> method in <tt>javax.portlet.ResourceServingPortlet</tt> (implemented by <tt>javax.portlet.GenericPortlet</tt>). A simple example:</p>
<pre class="brush: java;">
    @Override
    public void serveResource(ResourceRequest request, ResourceResponse response)
            throws PortletException, IOException {
        String paramValue = request.getParameter(&quot;abc&quot;);
        System.out.println(paramValue);
        response.setCharacterEncoding(&quot;UTF-8&quot;);
        response.setContentType(&quot;text/plain&quot;);
        PrintWriter pw = response.getWriter();
        pw.println(paramValue);
        pw.close();
    }
</pre>
<p>To link to this dynamic content:</p>
<pre class="brush: xml;">
&lt;portlet:resourceURL var=&quot;url&quot;&gt;
  &lt;portlet:param name=&quot;abc&quot; value=&quot;Hello World&quot;/&gt;
&lt;/portlet:resourceURL&gt;

&lt;a href=&quot;&lt;%=url%&gt;&quot;&gt;Dynamic link&lt;/a&gt;
</pre>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://indiwiz.com/2009/02/20/serving-static-and-dynamic-resources-in-jsr-286/&amp;title=Serving+Static+and+Dynamic+Resources+in+JSR+286" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://indiwiz.com/2009/02/20/serving-static-and-dynamic-resources-in-jsr-286/&amp;title=Serving+Static+and+Dynamic+Resources+in+JSR+286" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://indiwiz.com/2009/02/20/serving-static-and-dynamic-resources-in-jsr-286/&amp;title=Serving+Static+and+Dynamic+Resources+in+JSR+286&amp;desc=To%20serve%20static%20content%20packaged%20as%20part%20of%20the%20portlet%20WAR%2C%20we%20generally%20take%20this%20approach%3A%0A%0A%0A%26lt%3B%25%3Dresponse.encodeURL%28request.getContextPath%28%29%2B%22%2Fjs%2Fproject.js%22%29%25%26gt%3B%0A%0A%0AFor%20generating%20dynamic%20content%20what%20do%20we%20do%3F%20In%20JSR%20168%20this%20was%20not%20possible.%20Thankfully%2C%20JSR%20286%20introduced%20this%20important%20con" rel="nofollow" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://indiwiz.com/2009/02/20/serving-static-and-dynamic-resources-in-jsr-286/&amp;t=Serving+Static+and+Dynamic+Resources+in+JSR+286" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://indiwiz.com/2009/02/20/serving-static-and-dynamic-resources-in-jsr-286/&amp;title=Serving+Static+and+Dynamic+Resources+in+JSR+286&amp;summary=To%20serve%20static%20content%20packaged%20as%20part%20of%20the%20portlet%20WAR%2C%20we%20generally%20take%20this%20approach%3A%0A%0A%0A%26lt%3B%25%3Dresponse.encodeURL%28request.getContextPath%28%29%2B%22%2Fjs%2Fproject.js%22%29%25%26gt%3B%0A%0A%0AFor%20generating%20dynamic%20content%20what%20do%20we%20do%3F%20In%20JSR%20168%20this%20was%20not%20possible.%20Thankfully%2C%20JSR%20286%20introduced%20this%20important%20con&amp;source=indiWiz.com" rel="nofollow" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://indiwiz.com/2009/02/20/serving-static-and-dynamic-resources-in-jsr-286/&amp;title=Serving+Static+and+Dynamic+Resources+in+JSR+286" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://indiwiz.com/2009/02/20/serving-static-and-dynamic-resources-in-jsr-286/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JSR-286: Adding Header Elements</title>
		<link>http://indiwiz.com/2008/11/19/jsr-286-adding-header-elements/</link>
		<comments>http://indiwiz.com/2008/11/19/jsr-286-adding-header-elements/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 15:23:25 +0000</pubDate>
		<dc:creator>Subhash Chandran</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[javaee]]></category>
		<category><![CDATA[jsr286]]></category>
		<category><![CDATA[portlet]]></category>

		<guid isPermaLink="false">http://indiwiz.wordpress.com/?p=20</guid>
		<description><![CDATA[Some HTML elements like &#60;link&#62;, &#60;script&#62; may need to be placed in the HTML&#8217;s &#60;head&#62; section. For such needs, JSR-286 defines a standard way: import javax.portlet.GenericPortlet; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import javax.portlet.MimeResponse; import org.w3c.dom.Element; ... public class MyPortlet extends GenericPortlet { @Override protected void doHeaders(RenderRequest request, RenderResponse response){ Element e = response.createElement(&#34;link&#34;); e.setAttribute(&#34;rel&#34;, &#34;stylesheet&#34;); e.setAttribute(&#34;type&#34;, [...]]]></description>
			<content:encoded><![CDATA[<p>Some HTML elements like <tt>&lt;link&gt;</tt>, <tt>&lt;script&gt;</tt> may need to be placed in the HTML&#8217;s <tt>&lt;head&gt;</tt> section. For such needs, JSR-286 defines a standard way:</p>
<pre class="brush: java;">
import javax.portlet.GenericPortlet;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.MimeResponse;
import org.w3c.dom.Element;

...

public class MyPortlet extends GenericPortlet {
  @Override
  protected void doHeaders(RenderRequest request, RenderResponse response){
    Element e = response.createElement(&quot;link&quot;);
    e.setAttribute(&quot;rel&quot;, &quot;stylesheet&quot;);
    e.setAttribute(&quot;type&quot;, &quot;text/css&quot;);
    e.setAttribute(&quot;href&quot;, &quot;abc.css&quot;);
    response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, e);
  }
}
</pre>
<p><tt>response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, ...)</tt> might be called for adding any number of headers.</p>
<p>We also have to add this in the <tt>portlet.xml</tt> (either in portlet scope or application scope):</p>
<pre class="brush: xml;">
&lt;container­-runtime­-option&gt;
  &lt;name&gt;javax.portlet.renderHeaders&lt;/name&gt;
  &lt;value&gt;true&lt;/value&gt;
&lt;/container­-runtime­-option&gt;
</pre>
<p>This is because <tt>javax.portlet.renderHeaders</tt> is set to <tt>false</tt> by default.</p>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://indiwiz.com/2008/11/19/jsr-286-adding-header-elements/&amp;title=JSR-286%3A+Adding+Header+Elements" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://indiwiz.com/2008/11/19/jsr-286-adding-header-elements/&amp;title=JSR-286%3A+Adding+Header+Elements" rel="nofollow" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://indiwiz.com/2008/11/19/jsr-286-adding-header-elements/&amp;title=JSR-286%3A+Adding+Header+Elements&amp;desc=Some%20HTML%20elements%20like%20%26lt%3Blink%26gt%3B%2C%20%26lt%3Bscript%26gt%3B%20may%20need%20to%20be%20placed%20in%20the%20HTML%27s%20%26lt%3Bhead%26gt%3B%20section.%20For%20such%20needs%2C%20JSR-286%20defines%20a%20standard%20way%3A%0A%0A%5Bsourcecode%20language%3D%27java%27%5D%0Aimport%20javax.portlet.GenericPortlet%3B%0Aimport%20javax.portlet.RenderRequest%3B%0Aimport%20javax.portlet.RenderResponse%3B%0Ai" rel="nofollow" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://indiwiz.com/2008/11/19/jsr-286-adding-header-elements/&amp;t=JSR-286%3A+Adding+Header+Elements" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://indiwiz.com/2008/11/19/jsr-286-adding-header-elements/&amp;title=JSR-286%3A+Adding+Header+Elements&amp;summary=Some%20HTML%20elements%20like%20%26lt%3Blink%26gt%3B%2C%20%26lt%3Bscript%26gt%3B%20may%20need%20to%20be%20placed%20in%20the%20HTML%27s%20%26lt%3Bhead%26gt%3B%20section.%20For%20such%20needs%2C%20JSR-286%20defines%20a%20standard%20way%3A%0A%0A%5Bsourcecode%20language%3D%27java%27%5D%0Aimport%20javax.portlet.GenericPortlet%3B%0Aimport%20javax.portlet.RenderRequest%3B%0Aimport%20javax.portlet.RenderResponse%3B%0Ai&amp;source=indiWiz.com" rel="nofollow" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://indiwiz.com/2008/11/19/jsr-286-adding-header-elements/&amp;title=JSR-286%3A+Adding+Header+Elements" rel="nofollow" title="Share this on Reddit">Share this on Reddit</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://indiwiz.com/2008/11/19/jsr-286-adding-header-elements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
