<?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>usefulfor.com/java</title>
	<atom:link href="http://usefulfor.com/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://usefulfor.com/java</link>
	<description>On J2EE and Java web technologies</description>
	<lastBuildDate>Thu, 24 Jun 2010 14:43:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Maven profiles</title>
		<link>http://usefulfor.com/java/2010/06/24/maven-profiles/</link>
		<comments>http://usefulfor.com/java/2010/06/24/maven-profiles/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 14:24:48 +0000</pubDate>
		<dc:creator>ruth</dc:creator>
				<category><![CDATA[Java World]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[profiles]]></category>

		<guid isPermaLink="false">http://usefulfor.com/java/?p=146</guid>
		<description><![CDATA[We all work in different environments, development, test (maybe integration) and production servers or, maybe a set of servers that run the same application with different configurations. 
Maven helps us build our jar and war components for different environments configuring profiles.
We are going to see here how we can use Maven profiles to build and [...]]]></description>
			<content:encoded><![CDATA[<p>We all work in different environments, development, test (maybe integration) and production servers or, maybe a set of servers that run the same application with different configurations. </p>
<p>Maven helps us build our jar and war components for different environments configuring <a href="http://maven.apache.org/guides/introduction/introduction-to-profiles.html">profiles</a>.</p>
<p>We are going to see here how we can use Maven profiles <strong>to build and package Java jar files</strong> configured for specific environments. </p>
<p><span id="more-146"></span></p>
<h3>Environment dependencies</h3>
<p>Let&#8217;s say we are working with <a href="http://java.sun.com/developer/technicalArticles/J2EE/jpa/">JPA</a> and we have a <code>persistence.xml</code> file. This file has specific information about the database to connect to set in properties like: </p>
<p><code>hibernate.connection.url</code><br />
<code>hibernate.connection.username</code><br />
<code>hibernate.connection.password</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;?</span>xml version<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1.0&quot;</span> encoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">?&gt;</span>
<span style="color: #339933;">&lt;</span>persistence version<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1.0&quot;</span> xmlns<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://java.sun.com/xml/ns/persistence&quot;</span> xmlns<span style="color: #339933;">:</span>xsi<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span> xsi<span style="color: #339933;">:</span>schemaLocation<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>persistence<span style="color: #339933;">-</span>unit name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;specificmedia&quot;</span> transaction<span style="color: #339933;">-</span>type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;RESOURCE_LOCAL&quot;</span><span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>class<span style="color: #339933;">&gt;</span>com.<span style="color: #006633;">persistence</span>.<span style="color: #006633;">Account</span><span style="color: #339933;">&lt;/</span>class<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>class<span style="color: #339933;">&gt;</span>com.<span style="color: #006633;">persistence</span>.<span style="color: #006633;">User</span><span style="color: #339933;">&lt;/</span>class<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>class<span style="color: #339933;">&gt;</span>com.<span style="color: #006633;">persistence</span>.<span style="color: #006633;">Client</span><span style="color: #339933;">&lt;/</span>class<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>class<span style="color: #339933;">&gt;</span>com.<span style="color: #006633;">persistence</span>.<span style="color: #006633;">Product</span><span style="color: #339933;">&lt;/</span>class<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>properties<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>property name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hibernate.dialect&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;org.hibernate.dialect.MySQL5Dialect&quot;</span><span style="color: #339933;">/&gt;</span>
		<span style="color: #339933;">&lt;</span>property name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hibernate.connection.driver_class&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;com.mysql.jdbc.Driver&quot;</span><span style="color: #339933;">/&gt;</span>
		<span style="color: #339933;">&lt;</span>property name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hibernate.connection.username&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${db.username}&quot;</span><span style="color: #339933;">/&gt;</span>
		<span style="color: #339933;">&lt;</span>property name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hibernate.connection.password&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${db.password}&quot;</span><span style="color: #339933;">/&gt;</span>
		<span style="color: #339933;">&lt;</span>property name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hibernate.connection.url&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${db.connectionURL}/database&quot;</span><span style="color: #339933;">/&gt;</span>
		........................................................................
	<span style="color: #339933;">&lt;/</span>properties<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>persistence<span style="color: #339933;">-</span>unit<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>persistence<span style="color: #339933;">&gt;</span></pre></div></div>

<p>You can assign <code>placeholders</code> to every property that is bound to change depending on the environment you are deploying this <code>artifact</code> to.<br />
These <code>placeholders</code> will be replaced with the correct value for each environment when you package your <code>artifact</code> to deploy it.</p>
<p>For instance, if you are deploying it to the test environment the <code>placeholder</code> will get replaced with the connection details to your test database.</p>
<h3>Configuring the pom.xml</h3>
<p>There are two things that you need to do in the <code>pom.xml</code></p>
<h4>Define the Profiles</h4>
<p>Define the values for the <code>placeholders</code> in every environment using the <code>profiles</code> tag:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>profiles<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>profile<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>id<span style="color: #339933;">&gt;</span>development<span style="color: #339933;">&lt;/</span>id<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>activation<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>activeByDefault<span style="color: #339933;">&gt;</span>true<span style="color: #339933;">&lt;/</span>activeByDefault<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;/</span>activation<span style="color: #339933;">&gt;</span>
&nbsp;
		<span style="color: #339933;">&lt;</span>properties<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>db.<span style="color: #006633;">connectionURL</span><span style="color: #339933;">&gt;</span>jdbc<span style="color: #339933;">:</span>mysql<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//localhost:3306&lt;/db.connectionURL&gt;</span>
			<span style="color: #339933;">&lt;</span>db.<span style="color: #006633;">username</span><span style="color: #339933;">&gt;</span>root<span style="color: #339933;">&lt;/</span>db.<span style="color: #006633;">username</span><span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>db.<span style="color: #006633;">password</span><span style="color: #339933;">&gt;</span>your_password<span style="color: #339933;">&lt;/</span>db.<span style="color: #006633;">password</span><span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;/</span>properties<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>profile<span style="color: #339933;">&gt;</span>
&nbsp;
	<span style="color: #339933;">&lt;</span>profile<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>id<span style="color: #339933;">&gt;</span>integration<span style="color: #339933;">&lt;/</span>id<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>activation<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>property<span style="color: #339933;">&gt;</span>
				<span style="color: #339933;">&lt;</span>name<span style="color: #339933;">&gt;</span>env<span style="color: #339933;">&lt;/</span>name<span style="color: #339933;">&gt;</span>
				<span style="color: #339933;">&lt;</span>value<span style="color: #339933;">&gt;</span>eu<span style="color: #339933;">-</span>integration<span style="color: #339933;">&lt;/</span>value<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;/</span>property<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;/</span>activation<span style="color: #339933;">&gt;</span>
&nbsp;
		<span style="color: #339933;">&lt;</span>properties<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>db.<span style="color: #006633;">connectionURL</span><span style="color: #339933;">&gt;</span>jdbc<span style="color: #339933;">:</span>mysql<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//integration.server.ip:3306&lt;/db.connectionURL&gt;</span>
			<span style="color: #339933;">&lt;</span>db.<span style="color: #006633;">username</span><span style="color: #339933;">&gt;</span>root<span style="color: #339933;">&lt;/</span>db.<span style="color: #006633;">username</span><span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>db.<span style="color: #006633;">password</span><span style="color: #339933;">&gt;&lt;/</span>db.<span style="color: #006633;">password</span><span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;/</span>properties<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>profile<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>profiles<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Every profile has to be identified by an unique id: <code>integration</code>. This id is required to indicate the profile when you build your project using the <code>-P</code> option:</p>
<blockquote><p>mvn -P integration clean package</p></blockquote>
<h4>Resource Filtering</h4>
<p>Activate <a href="http://maven.apache.org/guides/getting-started/index.html#How_do_I_filter_resource_files">maven filtering</a> for the resources containing <code>placeholders</code>.</p>
<p>We are indicating where are the resources containing <code>placeholders</code>. So <em>Maven</em> knows where are the files with <code>placeholders </code>to be replaced (at built time) by the information defined in the <code></code> tag in the <code>pom.xml</code></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>build<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>resources<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>resource<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>directory<span style="color: #339933;">&gt;</span>src<span style="color: #339933;">/</span>main<span style="color: #339933;">/</span>resources<span style="color: #339933;">&lt;/</span>directory<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>filtering<span style="color: #339933;">&gt;</span>true<span style="color: #339933;">&lt;/</span>filtering<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;/</span>resource<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>resources<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>build<span style="color: #339933;">&gt;</span></pre></div></div>

<h3>Maven Profiles Activation</h3>
<p>Just to explain a bit the <code><a href="http://maven.apache.org/pom.html#Activation|Maven Profiles Activation">activation</a></code> section in the pom.xml. <em>Maven activation</em> is a very powerful tool that lets you activate a profile only under certain circumstances.</p>
<p>Here, you can see <code>activeByDefault=true</code>, that is used to indicate the default profile (the one that gets triggered by default when no other conditions are set).</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>id<span style="color: #339933;">&gt;</span>development<span style="color: #339933;">&lt;/</span>id<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>activation<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>activeByDefault<span style="color: #339933;">&gt;</span>true<span style="color: #339933;">&lt;/</span>activeByDefault<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>activation<span style="color: #339933;">&gt;</span></pre></div></div>

<p>So you these two will get the environment &#8216;<em>development</em>&#8216; properties:</p>
<blockquote><p>
mvn clean package<br />
mvn -P development clean package
</p></blockquote>
<p>I have also added an activation property (<em>env</em>) that, when set to a given value, chooses the profile:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>id<span style="color: #339933;">&gt;</span>eu<span style="color: #339933;">-</span>integration<span style="color: #339933;">&lt;/</span>id<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>activation<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>property<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>name<span style="color: #339933;">&gt;</span>env<span style="color: #339933;">&lt;/</span>name<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>value<span style="color: #339933;">&gt;</span>eu<span style="color: #339933;">-</span>integration<span style="color: #339933;">&lt;/</span>value<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>property<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>activation<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Therefore, the following two statements are equivalents:</p>
<blockquote><p>
mvn -Denv=integration clean package<br />
mvn -P integration clean package
</p></blockquote>
<h3>Resources</h3>
<ul>
<li><a href="http://maven.apache.org/guides/introduction/introduction-to-profiles.html">Introduction to Build Profiles</a></li>
<li><a href="http://maven.apache.org/guides/mini/guide-building-for-different-environments.html">Building For Different Environments</a>
</li>
<li><a href="http://maven.apache.org/guides/getting-started/index.html#How_do_I_filter_resource_files">How_do_I_filter_resource_files|Maven Filtering</a></li>
</ul>
<img src="http://usefulfor.com/java/?ak_action=api_record_view&id=146&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://usefulfor.com/java/2010/06/24/maven-profiles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery enable-disable elements</title>
		<link>http://usefulfor.com/java/2010/04/19/jquery-enable-disable-elements/</link>
		<comments>http://usefulfor.com/java/2010/04/19/jquery-enable-disable-elements/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 16:48:59 +0000</pubDate>
		<dc:creator>ruth</dc:creator>
				<category><![CDATA[Java World]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://usefulfor.com/java/?p=136</guid>
		<description><![CDATA[Let&#8217;s summarise here how to disable, enable, check, assign values and get selected values from your html document.

1
2
3
4
5
&#60;select name=&#34;client.idClient&#34; id=&#34;idClient&#34;&#62;
	&#60;option value=&#34;1&#34;&#62;CLIENT 1&#60;/option&#62;
	&#60;option value=&#34;2&#34;&#62;CLIENT 2&#60;/option&#62;
	&#60;option value=&#34;3&#34;&#62;CLIENT 3&#60;/option&#62;
&#60;/select&#62;

You can disable an element by setting the disabled attribute to disabled:

1
jQuery&#40;&#34;#idClient&#34;&#41;.attr&#40;&#34;disabled&#34;,&#34;disabled&#34;&#41;;

And enable the element by removing the disabled attribute:

1
jQuery&#40;&#34;#idClient&#34;&#41;.removeAttr&#40;&#34;disabled&#34;&#41;;

If the element is an input:

1
&#60;input type=&#34;checkbox&#34; id=&#34;yes&#34;/&#62;

then you have to [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s summarise here how to disable, enable, check, assign values and get selected values from your html document.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;select</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;client.idClient&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;idClient&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>CLIENT 1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>CLIENT 2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;3&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>CLIENT 3<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/select<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>You can disable an element by setting the <code>disabled</code> attribute to <code>disabled</code>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#idClient&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;disabled&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;disabled&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>And enable the element by removing the <code>disabled</code> attribute:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#idClient&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeAttr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;disabled&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>If the element is an input:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;yes&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

<p>then you have to set the <code>checked </code>attribute to <code>checked</code>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#yes&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;checked&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;checked&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#yes&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeAttr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;checked&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>If you want to set a value for an element in your document:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#idClient&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>will set the selected option in the dropdown to the value 1.</p>
<p>To get the selected <code>value</code>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#idClient&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>and the selected <code>text</code>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#idClient option:selected&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Very useful link: <a href="http://docs.jquery.com/Frequently_Asked_Questions">jQuery &#8211; FAQ</a></p>
<img src="http://usefulfor.com/java/?ak_action=api_record_view&id=136&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://usefulfor.com/java/2010/04/19/jquery-enable-disable-elements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Liferay.PortletURL</title>
		<link>http://usefulfor.com/java/2010/04/16/javascript-liferay-portleturl/</link>
		<comments>http://usefulfor.com/java/2010/04/16/javascript-liferay-portleturl/#comments</comments>
		<pubDate>Fri, 16 Apr 2010 16:44:21 +0000</pubDate>
		<dc:creator>ruth</dc:creator>
				<category><![CDATA[Java World]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[liferay]]></category>

		<guid isPermaLink="false">http://usefulfor.com/java/?p=66</guid>
		<description><![CDATA[Liferay Portal has a JavaScript library that allows the creation of portletURLs inside your JavaScript code. Something like:

&#60;input type=&#34;button&#34; value=&#34;&#60;liferay-ui:message key=&#34;cancel&#34; /&#62;&#34; 
onclick=&#34;&#60;portlet:namespace/&#62;_back();&#34;/&#62;
&#160;
&#60;script type=&#34;text/javascript&#34;&#62;
&#160;
      function &#60;portlet:namespace/&#62;_back&#40;&#41; &#123;
&#160;
            var backURL = Liferay.PortletURL.createRenderURL&#40;&#41;;
         [...]]]></description>
			<content:encoded><![CDATA[<p>Liferay Portal has a JavaScript library that allows the creation of <code>portletURLs</code> inside your JavaScript code. Something like:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;button&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;liferay-ui:message key=&quot;</span>cancel<span style="color: #0000ff;">&quot; /&gt;&quot;</span> 
onclick<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;portlet:namespace/&gt;_back();&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
      function <span style="color: #339933;">&lt;</span>portlet<span style="color: #339933;">:</span>namespace<span style="color: #339933;">/&gt;</span>_back<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            var backURL <span style="color: #339933;">=</span> Liferay.<span style="color: #006633;">PortletURL</span>.<span style="color: #006633;">createRenderURL</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            backURL.<span style="color: #006633;">setPortletId</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            backURL.<span style="color: #006633;">setParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;networkId&quot;</span>, $<span style="color: #009900;">&#123;</span>networkId<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            backURL.<span style="color: #006633;">setPortletMode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;view&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            location.<span style="color: #006633;">href</span> <span style="color: #339933;">=</span> backURL<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>All the available methods are (as in Liferay 5.2.3):</p>
<ul>
<li>setCopyCurrentRenderParameters: function(copyCurrentRenderParameters);</li>
<li>setDoAsUserId: function(doAsUserId);</li>
<li>setEncrypt: function(encrypt);</li>
<li>setEscapeXML: function(escapeXML);</li>
<li>setLifecycle: function(lifecycle);</li>
<li>setName: function(name);</li>
<li>setParameter: function(key, value);</li>
<li>setPlid: function(plid);</li>
<li>setPortletConfiguration: function(portletConfiguration);</li>
<li>setPortletId: function(portletId);</li>
<li>setPortletMode: function(portletMode);</li>
<li>setResourceId: function(resourceId);</li>
<li>setSecure: function(secure);</li>
<li>setWindowState: function(windowState);</li>
<li>toString: function();</li>
</ul>
<p>And you can create any portlet URL:</p>
<ul>
<li>var actionURL = Liferay.PortletURL.createActionURL(); // (&#8216;ACTION_PHASE&#8217;);</li>
<li>var renderURL = Liferay.PortletURL.createRenderURL(); // (&#8216;RENDER_PHASE&#8217;);</li>
<li>var resourceURL = Liferay.PortletURL.createResourceURL(); // (&#8216;RESOURCE_PHASE&#8217;);
<li>var permissionURL = Liferay.PortletURL.createPermissionURL(portletResource, modelResource, modelResourceDescription, resourcePrimKey);</li>
</ul>
<p>Have a look at the library in </p>
<blockquote><p><a href="http://svn.liferay.com/browse/portal/branches/5.2.x/portal-web/docroot/html/js/liferay/portlet_url.js?r=HEAD">liferay-portal-src-5.2.3/portal-web/docroot/html/js/liferay/portlet_url.js</a></p></blockquote>
<img src="http://usefulfor.com/java/?ak_action=api_record_view&id=66&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://usefulfor.com/java/2010/04/16/javascript-liferay-portleturl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Liferay hook war</title>
		<link>http://usefulfor.com/java/2010/04/06/liferay-hook-war/</link>
		<comments>http://usefulfor.com/java/2010/04/06/liferay-hook-war/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 11:13:10 +0000</pubDate>
		<dc:creator>ruth</dc:creator>
				<category><![CDATA[Java World]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[liferay]]></category>

		<guid isPermaLink="false">http://usefulfor.com/java/?p=64</guid>
		<description><![CDATA[Liferay Hooks are plugins that let you customise some of the Portal functionality. 
In this post we are creating a simple Liferay hook to change the value of a property in the portal.properties, override one of the Portal jsps and handling an event.

Not all portal.properties can be overridden, the liferay-hook_5_2_0.dtd describes the supported properties in [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Portal+Hook+Plugins">Liferay Hooks</a> are plugins that let you customise some of the Portal functionality. </p>
<p>In this post we are creating a simple Liferay hook to change the value of a property in the portal.properties, override one of the Portal jsps and handling an event.</p>
<p><span id="more-64"></span></p>
<p>Not all <code>portal.properties</code> can be overridden, the <a href="http://www.liferay.com/dtd/liferay-hook_5_2_0.dtd">liferay-hook_5_2_0.dtd</a> describes the supported properties in a hook.</p>
<p>The hook plugin that we are building here is for Liferay 5.2 version. For 5.1 have a look at the DTD <a href="http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/liferay-hook.xml+%285.1.0%29">here</a></p>
<h3>Create war</h3>
<p>Create a new empty war project and include the <code>liferay-plugin-package.properties</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">change<span style="color: #339933;">-</span>log<span style="color: #339933;">=</span>
module<span style="color: #339933;">-</span>incremental<span style="color: #339933;">-</span>version<span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span>
tags<span style="color: #339933;">=</span>hook
name<span style="color: #339933;">=</span>Example Hook
module<span style="color: #339933;">-</span>group<span style="color: #339933;">-</span>id<span style="color: #339933;">=</span>usefulfor
short<span style="color: #339933;">-</span>description<span style="color: #339933;">=</span>customise liferay portal to adapt it to my needs</pre></div></div>

<p>The <code>web.xml</code> includes the <code>HookContextListener</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;?</span>xml version<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1.0&quot;</span> encoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">?&gt;</span>
<span style="color: #339933;">&lt;!</span>DOCTYPE web<span style="color: #339933;">-</span>app <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;</span> <span style="color: #0000ff;">&quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>web<span style="color: #339933;">-</span>app<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>display<span style="color: #339933;">-</span>name<span style="color: #339933;">&gt;</span>example<span style="color: #339933;">-</span>hook<span style="color: #339933;">&lt;/</span>display<span style="color: #339933;">-</span>name<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>listener<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>listener<span style="color: #339933;">-</span>class<span style="color: #339933;">&gt;</span>com.<span style="color: #006633;">liferay</span>.<span style="color: #006633;">portal</span>.<span style="color: #006633;">kernel</span>.<span style="color: #006633;">servlet</span>.<span style="color: #006633;">HookContextListener</span><span style="color: #339933;">&lt;/</span>listener<span style="color: #339933;">-</span>class<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>listener<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>web<span style="color: #339933;">-</span>app<span style="color: #339933;">&gt;?</span></pre></div></div>

<p>In your <code>WEB-INF</code> directory create the file <code>liferay-hook.xml</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;?</span>xml version<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;1.0&quot;</span> encoding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #339933;">?&gt;</span>
<span style="color: #339933;">&lt;!</span>DOCTYPE hook <span style="color: #000000; font-weight: bold;">PUBLIC</span>
	<span style="color: #0000ff;">&quot;-//Liferay//DTD Hook 5.2.0//EN&quot;</span>
	<span style="color: #0000ff;">&quot;http://www.liferay.com/dtd/liferay-hook_5_2_0.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>hook<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>portal<span style="color: #339933;">-</span>properties<span style="color: #339933;">&gt;</span>portal.<span style="color: #006633;">properties</span><span style="color: #339933;">&lt;/</span>portal<span style="color: #339933;">-</span>properties<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>custom<span style="color: #339933;">-</span>jsp<span style="color: #339933;">-</span>dir<span style="color: #339933;">&gt;/</span>WEB<span style="color: #339933;">-</span>INF<span style="color: #339933;">/</span>jsp<span style="color: #339933;">&lt;/</span>custom<span style="color: #339933;">-</span>jsp<span style="color: #339933;">-</span>dir<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>hook<span style="color: #339933;">&gt;</span></pre></div></div>

<p>indicating the location of your <code>portal.properties</code> and also the path in your war where the portal will go to pick the overridden jsps. </p>
<p>Override the properties (the allowed ones <img src='http://usefulfor.com/java/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ) with your values in the portal.properties, including the classes that will be called when the events are triggered:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"># No terms of use
terms.<span style="color: #006633;">of</span>.<span style="color: #006633;">use</span>.<span style="color: #006633;">required</span><span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">false</span>
&nbsp;
#
# Login event
#
login.<span style="color: #006633;">events</span>.<span style="color: #006633;">pre</span><span style="color: #339933;">=</span>com.<span style="color: #006633;">custom</span>.<span style="color: #006633;">hook</span>.<span style="color: #006633;">events</span>.<span style="color: #006633;">login</span>.<span style="color: #006633;">CustomPreLogin</span>
login.<span style="color: #006633;">events</span>.<span style="color: #006633;">post</span><span style="color: #339933;">=</span>com.<span style="color: #006633;">custom</span>.<span style="color: #006633;">hook</span>.<span style="color: #006633;">events</span>.<span style="color: #006633;">login</span>.<span style="color: #006633;">CustomPostLogin</span>
&nbsp;
#
# Logout event
#
logout.<span style="color: #006633;">events</span>.<span style="color: #006633;">pre</span><span style="color: #339933;">=</span>com.<span style="color: #006633;">custom</span>..<span style="color: #006633;">hook</span>.<span style="color: #006633;">events</span>.<span style="color: #006633;">logout</span>.<span style="color: #006633;">CustomPreLogout</span></pre></div></div>

<p>Your events have to extends the abstract class <code>com.liferay.portal.kernel.events.Action</code> and implement the run method that will be called on the event happening:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.liferay.portal.kernel.events.Action</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.liferay.portal.kernel.events.ActionException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletRequest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletResponse</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CustomPreLogin <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399;">Action</span> <span style="color: #009900;">&#123;</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span>HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ActionException <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">//do something before the login</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Every jsp in your specified <code>custom-jsp-dir</code> will be picked up to replace the relevant one in the portal as long as it has the same name and it has exactly the same path.</p>
<p>So if your jsp folder is in <code>/WEB-INF/jsp</code> and you want to override the <code>portlet_messages.jspf</code> jsp located in <code>liferay-portal-src-5.2.3/portal-web/docroot/html/common/themes/portlet_messages.jspf</code> you will need that file in <code>/WEB-INF/jsp/html/common/themes/portlet_messages.jspf</code></p>
<p>image</p>
<p>Build and deploy your hook plugin into your Liferay server and you are done! </p>
<img src="http://usefulfor.com/java/?ak_action=api_record_view&id=64&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://usefulfor.com/java/2010/04/06/liferay-hook-war/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maven useful links</title>
		<link>http://usefulfor.com/java/2010/04/06/maven-useful-links/</link>
		<comments>http://usefulfor.com/java/2010/04/06/maven-useful-links/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 11:11:49 +0000</pubDate>
		<dc:creator>ruth</dc:creator>
				<category><![CDATA[Java World]]></category>
		<category><![CDATA[links]]></category>
		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://usefulfor.com/java/?p=61</guid>
		<description><![CDATA[Some Maven useful links:
Maven lifecycle:
http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
Maven create web app
http://maven.apache.org/plugins/maven-archetype-plugin/examples/webapp.html
Maven plugins
http://maven.apache.org/plugins/
Work on progress&#8230; any suggestions?
]]></description>
			<content:encoded><![CDATA[<p>Some Maven useful links:</p>
<p>Maven lifecycle:<br />
<a href="http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html">http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html</a></p>
<p>Maven create web app<br />
<a href="http://maven.apache.org/plugins/maven-archetype-plugin/examples/webapp.html">http://maven.apache.org/plugins/maven-archetype-plugin/examples/webapp.html</a></p>
<p>Maven plugins<br />
<a href="http://maven.apache.org/plugins/">http://maven.apache.org/plugins/</a></p>
<p>Work on progress&#8230; any suggestions?</p>
<img src="http://usefulfor.com/java/?ak_action=api_record_view&id=61&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://usefulfor.com/java/2010/04/06/maven-useful-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get month name from Calendar.MONTH field</title>
		<link>http://usefulfor.com/java/2010/03/18/get-month-name-from-calendar-month-field/</link>
		<comments>http://usefulfor.com/java/2010/03/18/get-month-name-from-calendar-month-field/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 20:30:39 +0000</pubDate>
		<dc:creator>ruth</dc:creator>
				<category><![CDATA[Java World]]></category>
		<category><![CDATA[calendar]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[month]]></category>

		<guid isPermaLink="false">http://usefulfor.com/java/?p=13</guid>
		<description><![CDATA[Here&#8217;s a method to get the month name from the Calendar.MONTH field:

public String getMonthFromInt&#40;int iMonth&#41; &#123;
  String month = &#34;invalid&#34;;
  DateFormatSymbols dfs = new DateFormatSymbols&#40;&#41;;
  String&#91;&#93; months = dfs.getMonths&#40;&#41;;
 if &#40;iMonth &#62;= 0 &#38;&#38; iMonth &#60;= 11&#41;
    month = months&#91;iMonth&#93;;
  return month;
&#125;

]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a method to get the month name from the <code>Calendar.MONTH</code> field:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getMonthFromInt<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> iMonth<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003399;">String</span> month <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;invalid&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #003399;">DateFormatSymbols</span> dfs <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">DateFormatSymbols</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> months <span style="color: #339933;">=</span> dfs.<span style="color: #006633;">getMonths</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>iMonth <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">&amp;&amp;</span> iMonth <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">11</span><span style="color: #009900;">&#41;</span>
    month <span style="color: #339933;">=</span> months<span style="color: #009900;">&#91;</span>iMonth<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">return</span> month<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<img src="http://usefulfor.com/java/?ak_action=api_record_view&id=13&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://usefulfor.com/java/2010/03/18/get-month-name-from-calendar-month-field/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Displaytag library in your portlet</title>
		<link>http://usefulfor.com/java/2010/03/18/displaytag-library-portlet/</link>
		<comments>http://usefulfor.com/java/2010/03/18/displaytag-library-portlet/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 20:28:52 +0000</pubDate>
		<dc:creator>ruth</dc:creator>
				<category><![CDATA[Java World]]></category>
		<category><![CDATA[displaytag]]></category>
		<category><![CDATA[liferay]]></category>
		<category><![CDATA[paginatedList]]></category>
		<category><![CDATA[portlet]]></category>

		<guid isPermaLink="false">http://usefulfor.com/java/?p=40</guid>
		<description><![CDATA[These are &#8211; roughly &#8211; the steps that you need to follow if you are planing to use the displaytag library in your portlet.

First of all, we are going to include the libraries in our portlet war. Download them from http://displaytag.sourceforge.net and include them in your WEB-INF/lib or, if you are using maven, include the [...]]]></description>
			<content:encoded><![CDATA[<p>These are &#8211; roughly &#8211; the steps that you need to follow if you are planing to use the <a title="Displaytag Library" href="http://displaytag.sourceforge.net">displaytag</a> library in your portlet.<br />
<span id="more-40"></span><br />
First of all, we are going to include the libraries in our portlet war. Download them from <a title="Displaytag - Download" href="http://displaytag.sourceforge.net/1.2/download.html">http://displaytag.sourceforge.net</a> and include them in your <code>WEB-INF/lib</code> or, if you are using maven, include the dependencies in your <code>pom.xml</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>displaytag<span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>displaytag<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>version<span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">1.2</span><span style="color: #339933;">&lt;/</span>version<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>dependency<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>groupId<span style="color: #339933;">&gt;</span>displaytag<span style="color: #339933;">&lt;/</span>groupId<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>artifactId<span style="color: #339933;">&gt;</span>displaytag<span style="color: #339933;">-</span>portlet<span style="color: #339933;">&lt;/</span>artifactId<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;</span>version<span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">1.2</span><span style="color: #339933;">&lt;/</span>version<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>dependency<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Using the <a href="http://displaytag.sourceforge.net/1.2/tut_externalSortAndPage.html">Valuelist pattern</a> we are going to implement the <tt>org.displaytag.pagination.PaginatedList </tt>interface, not without extending it first to adapt it to our needs, of course <img src='http://usefulfor.com/java/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  like adding the <code>PortletRequest</code> to get access to the attributes in there.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">interface</span> ExtendedPaginatedList <span style="color: #000000; font-weight: bold;">extends</span> PaginatedList <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> DEFAULT_PAGE_SIZE <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * set results list
     *
     * @param resultList
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setList<span style="color: #009900;">&#40;</span><span style="color: #003399;">List</span> resultList<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Set the Total
     *
     * @param total
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setFullListSize<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> total<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * set the Page Size
     *
     * @param pageSize
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setObjectsPerPage<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> pageSize<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Set the page number
     *
     * @param pageNumber
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setPageNumber<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> pageNumber<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * get the first record index
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getFirstRecordIndex<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * PortletRequest
     *
     * @return
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> PortletRequest getPortletRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And the implementation:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"> <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ExtendedPaginatedListImpl <span style="color: #000000; font-weight: bold;">implements</span> ExtendedPaginatedList, <span style="color: #003399;">Serializable</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> Log _log <span style="color: #339933;">=</span> LogFactory.<span style="color: #006633;">getLog</span><span style="color: #009900;">&#40;</span>ExtendedPaginatedListImpl.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Request params as constants.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> PAGE_NUMBER <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;page&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> SORT_DIRECTION <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;dir&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> SORT_FIELD <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;sort&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> SORT_ASC <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;asc&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> SORT_DESC <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;desc&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * current page index, starts at 0
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> pageNumber<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * number of results per page 
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> objectsPerPage<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * total number of results 
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> fullListSize<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * list for the current page
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">List</span> list<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * PortletRequest
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> PortletRequest portletRequest<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * sort criteria
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> sortCriterion<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * default sorting order
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> SortOrderEnum sortDirection <span style="color: #339933;">=</span> SortOrderEnum.<span style="color: #006633;">ASCENDING</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * default constructor 
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> ExtendedPaginatedListImpl<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> ExtendedPaginatedListImpl<span style="color: #009900;">&#40;</span>PortletRequest portletRequest, <span style="color: #000066; font-weight: bold;">int</span> pageSize<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#40;</span>SortOrderEnum.<span style="color: #006633;">ASCENDING</span>, portletRequest, pageSize<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> ExtendedPaginatedListImpl<span style="color: #009900;">&#40;</span>SortOrderEnum sortDirection, PortletRequest portletRequest, <span style="color: #000066; font-weight: bold;">int</span> pageSize<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        setPortletRequest<span style="color: #009900;">&#40;</span>portletRequest<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>pageSize <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            setObjectsPerPage<span style="color: #009900;">&#40;</span>DEFAULT_PAGE_SIZE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            setObjectsPerPage<span style="color: #009900;">&#40;</span>pageSize<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">int</span> pageN <span style="color: #339933;">=</span> getParamPageNumber<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> <span style="color: #cc66cc;">1</span> <span style="color: #339933;">:</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>getParamPageNumber<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        setPageNumber<span style="color: #009900;">&#40;</span>pageN<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">sortCriterion</span> <span style="color: #339933;">=</span> portletRequest.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span>SORT_FIELD<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003399;">String</span> sortDirRequested <span style="color: #339933;">=</span> StringUtils.<span style="color: #006633;">trimToNull</span><span style="color: #009900;">&#40;</span>portletRequest.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span>SORT_DIRECTION<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>sortDirRequested <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> StringUtils.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>sortDirRequested, SORT_ASC<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            sortDirection <span style="color: #339933;">=</span> SortOrderEnum.<span style="color: #006633;">ASCENDING</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>sortDirRequested <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> StringUtils.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>sortDirRequested, SORT_DESC<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            sortDirection <span style="color: #339933;">=</span> SortOrderEnum.<span style="color: #006633;">DESCENDING</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">sortDirection</span> <span style="color: #339933;">=</span> sortDirection<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_log.<span style="color: #006633;">isDebugEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            _log.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getParamPageNumber<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #003399;">String</span> paramPageNumber <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>portletRequest <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            paramPageNumber <span style="color: #339933;">=</span> portletRequest.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span>PAGE_NUMBER<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span>
                    <span style="color: #339933;">?</span> portletRequest.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span>PAGE_NUMBER<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> StringUtils.<span style="color: #006633;">trimToNull</span><span style="color: #009900;">&#40;</span>paramPageNumber<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setPortletRequest<span style="color: #009900;">&#40;</span>PortletRequest portletRequest<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">portletRequest</span> <span style="color: #339933;">=</span> portletRequest<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> PortletRequest getPortletRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">portletRequest</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// More get and set methods</span></pre></div></div>

<p>Now we can get the list of objects that you are planing to fill the table with and set it in your portlet request (or session in this case) to access it from the JSP:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    @RenderMapping<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> view<span style="color: #009900;">&#40;</span>RenderRequest renderRequest<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> PortalException, <span style="color: #003399;">SystemException</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #003399;">Integer</span> networkId <span style="color: #339933;">=</span> setAndGetNetworkId<span style="color: #009900;">&#40;</span>renderRequest<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        setBehavioursList<span style="color: #009900;">&#40;</span>renderRequest, networkId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> ViewKeys.<span style="color: #006633;">MANAGEMENT_VIEW</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> setBehavioursList<span style="color: #009900;">&#40;</span>PortletRequest portletRequest, <span style="color: #003399;">Integer</span> networkId<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        ExtendedPaginatedList behavioursPaginatedList <span style="color: #339933;">=</span> paginatedListFactory.<span style="color: #006633;">getPaginatedListInstance</span><span style="color: #009900;">&#40;</span>portletRequest<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003399;">Long</span> total <span style="color: #339933;">=</span> behaviourManagerService.<span style="color: #006633;">countBehaviours</span><span style="color: #009900;">&#40;</span>DeletedType.<span style="color: #006633;">no</span>, networkId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        behavioursPaginatedList.<span style="color: #006633;">setFullListSize</span><span style="color: #009900;">&#40;</span>total.<span style="color: #006633;">intValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        behavioursPaginatedList.<span style="color: #006633;">setList</span><span style="color: #009900;">&#40;</span>
                behaviourManagerService.<span style="color: #006633;">getBehaviours</span><span style="color: #009900;">&#40;</span>
                        DeletedType.<span style="color: #006633;">no</span>, networkId,
                        behavioursPaginatedList.<span style="color: #006633;">getFirstRecordIndex</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, behavioursPaginatedList.<span style="color: #006633;">getObjectsPerPage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        portletRequest.<span style="color: #006633;">getPortletSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span>RequestKeys.<span style="color: #006633;">BEHAVIOURS_LIST</span>, behavioursPaginatedList, PortletSession.<span style="color: #006633;">PORTLET_SCOPE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Include the tld in your JSP:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%--</span> Displaytag <span style="color: #339933;">--%&gt;</span>
<span style="color: #339933;">&lt;%</span>@ taglib uri<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://displaytag.sf.net&quot;</span> prefix<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;display&quot;</span> <span style="color: #339933;">%&gt;</span></pre></div></div>

<p>And access the paginatedList in the session to fill in the table:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>liferay<span style="color: #339933;">-</span>portlet<span style="color: #339933;">:</span>renderURL var<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;viewListURL&quot;</span><span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>display<span style="color: #339933;">:</span>table id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;behaviour&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${portletSessionScope.paginatedBehaviourList}&quot;</span>
      requestURI<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;${viewListURL}&quot;</span>
      sort<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;external&quot;</span>
      htmlId<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;behavioursListTable&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
      <span style="color: #339933;">&lt;</span>display<span style="color: #339933;">:</span>column property<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;idNetwork&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Network&quot;</span><span style="color: #339933;">/&gt;</span>
      <span style="color: #339933;">&lt;</span>display<span style="color: #339933;">:</span>column property<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;idBehaviour&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Behaviour&quot;</span><span style="color: #339933;">/&gt;</span>
      <span style="color: #339933;">&lt;</span>display<span style="color: #339933;">:</span>column property<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;name&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Name&quot;</span><span style="color: #339933;">/&gt;</span>
      <span style="color: #339933;">&lt;</span>display<span style="color: #339933;">:</span>column property<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;category.name&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Category&quot;</span><span style="color: #339933;">/&gt;</span>
      <span style="color: #339933;">&lt;</span>display<span style="color: #339933;">:</span>column property<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;client.name&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Client&quot;</span><span style="color: #339933;">/&gt;</span>
      <span style="color: #339933;">&lt;</span>display<span style="color: #339933;">:</span>column property<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;type.type&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Type&quot;</span><span style="color: #339933;">/&gt;</span>
&nbsp;
      <span style="color: #339933;">&lt;</span>display<span style="color: #339933;">:</span>column title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Actions&quot;</span> autolink<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">'&lt;portlet:renderURL windowState=&quot;MAXIMIZED&quot;&gt;
                        &lt;portlet:param name=&quot;action&quot; value=&quot;UPDATE&quot;/&gt;
                        &lt;portlet:param name=&quot;idBehaviour&quot; value=&quot;${behaviour.idBehaviour}&quot;/&gt;
                  &lt;/portlet:renderURL&gt;'</span><span style="color: #339933;">&gt;</span>
                  Update
            <span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">&lt;/</span>display<span style="color: #339933;">:</span>column<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>display<span style="color: #339933;">:</span>table<span style="color: #339933;">&gt;</span></pre></div></div>

<p>To customise your table you can add a <code>displaytag.properties</code> to your classpath:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">factory.<span style="color: #006633;">requestHelper</span><span style="color: #339933;">=</span>org.<span style="color: #006633;">displaytag</span>.<span style="color: #006633;">portlet</span>.<span style="color: #006633;">PortletRequestHelperFactory</span>
&nbsp;
paging.<span style="color: #006633;">banner</span>.<span style="color: #006633;">placement</span><span style="color: #339933;">=</span>bottom
&nbsp;
css.<span style="color: #006633;">table</span><span style="color: #339933;">=</span>taglib<span style="color: #339933;">-</span>search<span style="color: #339933;">-</span>iterator
css.<span style="color: #006633;">tr</span>.<span style="color: #006633;">even</span><span style="color: #339933;">=</span>portlet<span style="color: #339933;">-</span>section<span style="color: #339933;">-</span>body results<span style="color: #339933;">-</span>row
css.<span style="color: #006633;">tr</span>.<span style="color: #006633;">odd</span><span style="color: #339933;">=</span>portlet<span style="color: #339933;">-</span>section<span style="color: #339933;">-</span>alternate results<span style="color: #339933;">-</span>row alt
css.<span style="color: #006633;">th</span>.<span style="color: #006633;">sorted</span><span style="color: #339933;">=</span>sort<span style="color: #339933;">-</span>column
css.<span style="color: #006633;">th</span>.<span style="color: #006633;">ascending</span><span style="color: #339933;">=</span>sort<span style="color: #339933;">-</span>asc
css.<span style="color: #006633;">th</span>.<span style="color: #006633;">descending</span><span style="color: #339933;">=</span>sort<span style="color: #339933;">-</span>desc</pre></div></div>

<p>Have a look at the configuration properties here: <a href="http://displaytag.sourceforge.net/1.2/configuration.html">displaytag configuration</a></p>
<p>And also, customise the appearance including a <code>displaytag.css</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">div<span style="color: #6666ff;">.exportlinks</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#EEEEEE</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">dotted</span> <span style="color: #cc00cc;">#999999</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">99</span>%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
span<span style="color: #6666ff;">.export</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> inline-<span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">4px</span> <span style="color: #933;">1px</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
span<span style="color: #6666ff;">.excel</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../img/ico_file_excel.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
span<span style="color: #6666ff;">.csv</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../img/ico_file_csv.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
span<span style="color: #6666ff;">.xml</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../img/ico_file_xml.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
span<span style="color: #6666ff;">.pdf</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../img/ico_file_pdf.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
span<span style="color: #6666ff;">.rtf</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../img/ico_file_rtf.png</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
span<span style="color: #6666ff;">.pagebanner</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#EEEEEE</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">border-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#999999</span> <span style="color: #cc00cc;">#999999</span> -moz-use-text-<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">border-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">dotted</span> <span style="color: #993333;">dotted</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">border-width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #993333;">medium</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">99</span>%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
span<span style="color: #6666ff;">.pagelinks</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#EEEEEE</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">border-color</span><span style="color: #00AA00;">:</span> -moz-use-text-<span style="color: #000000; font-weight: bold;">color</span> <span style="color: #cc00cc;">#999999</span> <span style="color: #cc00cc;">#999999</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">border-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span> <span style="color: #993333;">dotted</span> <span style="color: #993333;">dotted</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">border-width</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">medium</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-5px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">99</span>%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.group-1</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">border-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #000000; font-weight: bold;">black</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.group-2</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">border-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #000000; font-weight: bold;">black</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">italic</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.subtotal-sum</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.grandtotal-sum</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.subtotal-header</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">border-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #993333;">white</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.subtotal-label</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.grandtotal-label</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">border-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #993333;">white</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.grouped-table</span> tr<span style="color: #6666ff;">.even</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#FFFFFF</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.grouped-table</span> tr<span style="color: #6666ff;">.odd</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#FFFFFF</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.grandtotal-row</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">border-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span> <span style="color: #993333;">solid</span> <span style="color: #000000; font-weight: bold;">black</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>If you are using Liferay you can include the css file in your portlet war and then, in the <code>liferay-portlet.xml</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>portlet<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>portlet<span style="color: #339933;">-</span>name<span style="color: #339933;">&gt;</span>BehaviourManagementPortlet<span style="color: #339933;">&lt;/</span>portlet<span style="color: #339933;">-</span>name<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>instanceable<span style="color: #339933;">&gt;</span>true<span style="color: #339933;">&lt;/</span>instanceable<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>private<span style="color: #339933;">-</span>request<span style="color: #339933;">-</span>attributes<span style="color: #339933;">&gt;</span>false<span style="color: #339933;">&lt;/</span>private<span style="color: #339933;">-</span>request<span style="color: #339933;">-</span>attributes<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>private<span style="color: #339933;">-</span>session<span style="color: #339933;">-</span>attributes<span style="color: #339933;">&gt;</span>false<span style="color: #339933;">&lt;/</span>private<span style="color: #339933;">-</span>session<span style="color: #339933;">-</span>attributes<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>ajaxable<span style="color: #339933;">&gt;</span>true<span style="color: #339933;">&lt;/</span>ajaxable<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>header<span style="color: #339933;">-</span>portlet<span style="color: #339933;">-</span>css<span style="color: #339933;">&gt;/</span>css<span style="color: #339933;">/</span>displaytag.<span style="color: #006633;">css</span><span style="color: #339933;">&lt;/</span>header<span style="color: #339933;">-</span>portlet<span style="color: #339933;">-</span>css<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>portlet<span style="color: #339933;">&gt;</span></pre></div></div>

<img src="http://usefulfor.com/java/?ak_action=api_record_view&id=40&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://usefulfor.com/java/2010/03/18/displaytag-library-portlet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
