<?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>Devon Hillard Tech Blog &#187; Seam</title>
	<atom:link href="http://www.digitalsanctuary.com/tech-blog/tag/seam/feed" rel="self" type="application/rss+xml" />
	<link>http://www.digitalsanctuary.com/tech-blog</link>
	<description>Java, ATG, Seam, and related Technologies</description>
	<lastBuildDate>Thu, 01 Jul 2010 21:06:32 +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>10MinuteMail and Form Submission Charsets in Seam/JSF</title>
		<link>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/10minutemail-and-form-submission-charsets-in-seamjsf.html</link>
		<comments>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/10minutemail-and-form-submission-charsets-in-seamjsf.html#comments</comments>
		<pubDate>Thu, 04 Mar 2010 22:44:25 +0000</pubDate>
		<dc:creator>Devon</dc:creator>
				<category><![CDATA[10MinuteMail]]></category>
		<category><![CDATA[Seam]]></category>
		<category><![CDATA[internationalization]]></category>

		<guid isPermaLink="false">http://www.digitalsanctuary.com/tech-blog/?p=598</guid>
		<description><![CDATA[I launched a minor update to 10MinuteMail.com last night.  It contained:

Changed the mail domain to owlpic.com
Updated the Russian language translation (thanks to Vladimir)
Fixed a bug where replying to an e-mail using a non-latin character set would result in an unreadable e-mail (also thanks to Vladimir for pointing this out)

This last issue was an odd [...]]]></description>
			<content:encoded><![CDATA[<p>I launched a minor update to <a href="http://10minutemail.com">10MinuteMail.com</a> last night.  It contained:</p>
<ol>
<li>Changed the mail domain to owlpic.com</li>
<li>Updated the Russian language translation (thanks to Vladimir)</li>
<li>Fixed a bug where replying to an e-mail using a non-latin character set would result in an unreadable e-mail (also thanks to Vladimir for pointing this out)</li>
</ol>
<p>This last issue was an odd one to fix, so I wanted to document it here (although the same fix can be found elsewhere on the net).</p>
<p>10MinuteMail.com is pretty well internationalized.  The site content is translated into over 30 languages and the pages are served as UTF-8.  Incoming e-mails are also displayed using UTF-8 and display non-latin character sets correctly.  However, until this latest release, if you replied to an e-mail using non-latin characters, the resulting e-mail contained gibberish instead of the correct characters.</p>
<p>I started off by adding UTF-8 as the specified character set for outgoing e-mails.  That didn&#8217;t help.  I added UTF-8 encoding declaration attribute to the form element.  That didn&#8217;t help.  Finally after some frustration, googling, and trying a ton of things, I discovered that for some reason, and I&#8221;m not sure if the bug is in JBoss, JSF, Seam, or where exactly, but you have to set the request objects character encoding programmatically for each request, otherwise it will use the wrong encoding on the form contents and you end up with gibberish.  The easiest way to solve this that I&#8217;ve found so far is to create a small Servlet Filter that sets the encoding on the request, and add that filter in before your Seam filter in your web.xml.  It worked for me.</p>
<p>The filter:</p>
<pre class="brush: java;">
package com.digitalsanctuary.seam;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * The Class UTF8Filter.
 */
public class UTF8Filter implements Filter {

    /** The Constant UTF_8. */
    private static final String UTF_8 = &quot;UTF-8&quot;;

    /**
     * Destroy.
     *
     * @see javax.servlet.Filter#destroy()
     */
    public void destroy() {
    }

    /**
     * Do filter.
     *
     * @param pRequest
     *            the request
     * @param pResponse
     *            the response
     * @param pChain
     *            the chain
     * @throws IOException
     *             Signals that an I/O exception has occurred.
     * @throws ServletException
     *             the servlet exception
     * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse,
     *      javax.servlet.FilterChain)
     */
    public void doFilter(ServletRequest pRequest, ServletResponse pResponse, FilterChain pChain) throws IOException,
	    ServletException {
	pRequest.setCharacterEncoding(UTF_8);
	pChain.doFilter(pRequest, pResponse);
    }

    /**
     * Inits the.
     *
     * @param arg0
     *            the arg0
     * @throws ServletException
     *             the servlet exception
     * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
     */
    public void init(FilterConfig arg0) throws ServletException {
    }

}
</pre>
<p>An excerpt of web.xml:</p>
<pre class="brush: xml;">
....
	&lt;filter&gt;
		&lt;filter-name&gt;UTF8 Filter&lt;/filter-name&gt;
		&lt;filter-class&gt;com.digitalsanctuary.seam.UTF8Filter&lt;/filter-class&gt;
	&lt;/filter&gt;

	&lt;filter-mapping&gt;
		&lt;filter-name&gt;UTF8 Filter&lt;/filter-name&gt;
		&lt;url-pattern&gt;/*&lt;/url-pattern&gt;
	&lt;/filter-mapping&gt;

	&lt;filter&gt;
		&lt;filter-name&gt;Seam Filter&lt;/filter-name&gt;
		&lt;filter-class&gt;org.jboss.seam.servlet.SeamFilter&lt;/filter-class&gt;
	&lt;/filter&gt;

	&lt;filter-mapping&gt;
		&lt;filter-name&gt;Seam Filter&lt;/filter-name&gt;
		&lt;url-pattern&gt;/*&lt;/url-pattern&gt;
	&lt;/filter-mapping&gt;
....
</pre>
<p>Does anyone have a better fix or know exactly why this happens?  </p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/10minutemail-and-form-submission-charsets-in-seamjsf.html" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/10minutemail-and-form-submission-charsets-in-seamjsf.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Seam 2.x Web Development</title>
		<link>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/seam-2x-web-development.html</link>
		<comments>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/seam-2x-web-development.html#comments</comments>
		<pubDate>Wed, 03 Jun 2009 00:14:02 +0000</pubDate>
		<dc:creator>Devon</dc:creator>
				<category><![CDATA[Seam]]></category>
		<category><![CDATA[book]]></category>

		<guid isPermaLink="false">http://www.digitalsanctuary.com/tech-blog/?p=431</guid>
		<description><![CDATA[Packt Publishing just sent me a copy of their new Seam book entitled Seam 2.x Web Development.  Authored by David Salter, it seems to be a well laid out practical guide to building web apps with Seam 2.  I&#8217;ve only skimmed it so far, but will be posting an in-depth review once I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_432" class="wp-caption alignright" style="width: 160px"><a href="http://www.digitalsanctuary.com/tech-blog/wp-content/uploads/2009/06/184719592x.jpg"><img src="http://www.digitalsanctuary.com/tech-blog/wp-content/uploads/2009/06/184719592x-150x150.jpg" alt="Seam 2.x Web Development by David Salter" title="Seam 2.x Web Development" width="150" height="150" class="size-thumbnail wp-image-432" /></a><p class="wp-caption-text">Seam 2.x Web Development by David Salter</p></div>
<p>Packt Publishing just sent me a copy of their new Seam book entitled Seam 2.x Web Development.  Authored by David Salter, it seems to be a well laid out practical guide to building web apps with Seam 2.  I&#8217;ve only skimmed it so far, but will be posting an in-depth review once I&#8217;m able to read through it.  </p>
<p>It&#8217;s great to have a book that covers the new features of Seam 2 and provides examples of common Web 2.0 requirements such as OpenID integration, AJAX/RIA interfaces, and multi-tabbed browsing support using conversation scoped components.  Personally I&#8217;m interested in reading about the new(ish) Identity Manager API (which I haven&#8217;t played with yet) and trying to add OpenID support for the application I am currently building.</p>
<p>You can read the second chapter online here: <a href="http://www.packtpub.com/files/seam-2-x-web-development-sample-chapter-2-developing-seam-applications.pdf">Chapter 2: Developing Seam Applications</a> and let me know what you think of it!</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/seam-2x-web-development.html" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/seam-2x-web-development.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Environment specific mail auth and Seam&#8217;s MailSession</title>
		<link>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/environment-specific-mail-auth-and-seams-mailsession.html</link>
		<comments>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/environment-specific-mail-auth-and-seams-mailsession.html#comments</comments>
		<pubDate>Wed, 20 May 2009 02:13:32 +0000</pubDate>
		<dc:creator>Devon</dc:creator>
				<category><![CDATA[Seam]]></category>
		<category><![CDATA[email]]></category>

		<guid isPermaLink="false">http://www.digitalsanctuary.com/tech-blog/?p=416</guid>
		<description><![CDATA[If you are using Seam&#8217;s MailSession to send out going e-mail from your Seam application you can run into trouble if you have a mail server in any environment (dev, test, stage, prod) that allows outgoing mail based on the client&#8217;s IP address and does not use username and password based authentication.  
The standard [...]]]></description>
			<content:encoded><![CDATA[<p>If you are using Seam&#8217;s MailSession to send out going e-mail from your Seam application you can run into trouble if you have a mail server in any environment (dev, test, stage, prod) that allows outgoing mail based on the client&#8217;s IP address and does not use username and password based authentication.  </p>
<p>The standard configuration for the MailSession is in the components.xml file and looks like this (if you&#8217;ve used SeamGen to create your project):</p>
<pre class="brush: xml;">
	&lt;mail:mail-session host=&quot;@mailhost@&quot; port=&quot;@mailport@&quot; username=&quot;@mailusername@&quot; password=&quot;@mailpassword@&quot; /&gt;
</pre>
<p>Then each of your environments has a components-{env}.properties file, which is deployed out and used to populate the @variable@ placeholders in the components.xml file.  For instance your components.dev.properties file might look like this:</p>
<pre class="brush: plain;">
jndiPattern=YourApp/#{ejbName}/local
debug=true
mailhost=mail.mydomain.com
mailport=25
mailusername=mailus3r
mailpassword=mailp4ss
</pre>
<p>Which works great.  However, if for instance your production environment uses IP based mail authentication for outbound e-mail, you might try to set your components-prod.properties file to look like this:</p>
<pre class="brush: plain;">
jndiPattern=YourApp/#{ejbName}/local
debug=false
mailhost=prodmail.mydomain.com
mailport=25
mailusername=
mailpassword=
</pre>
<p>However, that ends up setting empty strings into the username and password member variables of the MailSession component, and unfortunately the logic which determines whether or not to authenticate with the mail server checks for nulls only.  So with empty strings, it attempts to authenticate with the mail server using a blank username and password.  Which fails, and causes an unhelpful Faces error (unless you turn on debug on the MailSession component).</p>
<p>I&#8217;ve logged a Jira ticket about it here: <a href="https://jira.jboss.org/jira/browse/JBSEAM-4176">JBSEAM-4176</a></p>
<p>You can do a simple workaround by overriding the MailSession component with your own sub-class of the MailSession class.  In your sub-class you can override the setUsername and setPassword methods, check for empty strings and set null into the member variable if the parameter is null or empty.  Luckily the Seam Install precedence system makes it very easy to override the default Seam component.</p>
<pre class="brush: java;">
package com.myapp.mail;

import static org.jboss.seam.ScopeType.APPLICATION;

import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.intercept.BypassInterceptors;

/**
 * The Class MailSession. This is an overriding class designed to work around
 * https://jira.jboss.org/jira/browse/JBSEAM-4176
 */
@Name(&quot;org.jboss.seam.mail.mailSession&quot;)
@Install(precedence = org.jboss.seam.annotations.Install.APPLICATION, classDependencies = &quot;javax.mail.Session&quot;)
@Scope(APPLICATION)
@BypassInterceptors
public class MailSession extends org.jboss.seam.mail.MailSession {

    @Override
    public void setPassword(String pPassword) {
	if (pPassword == null || pPassword.trim().length() == 0) {
	    super.setPassword(null);
	} else {
	    super.setPassword(pPassword);
	}
    }

    @Override
    public void setUsername(String pUsername) {
	if (pUsername == null || pUsername.trim().length() == 0) {
	    super.setUsername(null);
	} else {
	    super.setUsername(pUsername);
	}
    }

}
</pre>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/environment-specific-mail-auth-and-seams-mailsession.html" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/environment-specific-mail-auth-and-seams-mailsession.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Make A Custom RichFaces Skin</title>
		<link>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/make-a-custom-richfaces-skin.html</link>
		<comments>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/make-a-custom-richfaces-skin.html#comments</comments>
		<pubDate>Thu, 09 Apr 2009 23:40:52 +0000</pubDate>
		<dc:creator>Devon</dc:creator>
				<category><![CDATA[Seam]]></category>
		<category><![CDATA[richfaces]]></category>

		<guid isPermaLink="false">http://www.digitalsanctuary.com/tech-blog/?p=337</guid>
		<description><![CDATA[Using RichFaces in your application makes it easy to build great rich interfaces without spending a ton of time writing custom JavaScript for the front end and the back-end support for the JavaScript calls.  It ties into your JSF components easily and makes dynamic interaction easy to build.  It also comes with a [...]]]></description>
			<content:encoded><![CDATA[<p>Using RichFaces in your application makes it easy to build great rich interfaces without spending a ton of time writing custom JavaScript for the front end and the back-end support for the JavaScript calls.  It ties into your JSF components easily and makes dynamic interaction easy to build.  It also comes with a number of default skins which is great when you&#8217;re first starting to build out a new application because it gives it a nice polished look instead of just black and white unstyled elements.</p>
<p>However, once you you get your own site design in place, the RichFaces skins probably won&#8217;t match your design perfectly.  You can always override any of the particular element styles using CSS, but if you want to quickly change the global look and feel for all the RichFaces components, the easiest thing to do is to create a customized RichFaces skin.  </p>
<p>You should start with the RichFaces skin that most closely matches your design and build your custom skin based on that.  The skins are defined in properties files in the RichFaces jar file under /META-INF/skins/.  You can also just download them from here, to avoid having to unpack the jar file yourself: <a href='http://www.digitalsanctuary.com/tech-blog/wp-content/uploads/2009/04/richfaces-skins.zip'>richfaces-skins.zip</a>.</p>
<p>Copy the skin file that&#8217;s closest to your design into your project.  If you&#8217;re using a Seam project created with seam-gen, you&#8217;re in luck because the ant build file is already setup to deploy RichFaces skins if you have them.  Just drop the skinname.skin.properties file into the &#8220;resources&#8221; directory of your Seam project.  Rename it to a custom name for your site&#8217;s skin, i.e. mysite.skin.properties.  </p>
<p>Now you need to configure your application to use the new custom skin.  Edit /resources/WEB-INF/web.xml, and change the org.richfaces.SKIN param to the name of your new skin:</p>
<pre class="brush: xml;">
   &lt;context-param&gt;
      &lt;param-name&gt;org.richfaces.SKIN&lt;/param-name&gt;
      &lt;param-value&gt;mysite&lt;/param-value&gt;
   &lt;/context-param&gt;
</pre>
<p>Now you can edit the skin file to adjust the colors and look and feel of the skin to match your site&#8217;s design.  The ant build file will automatically deploy the custom skin file into the war file.</p>
<p>There are also other ways to customize RichFaces and build custom skins including extending an existing skin, or using the new <a href="http://www.jboss.org/file-access/default/members/jbossrichfaces/freezone/docs/devguide/en/html/ArchitectureOverview.html#PlugnSkin" target="_new">Plug-n-Skin</a> feature, or <a href="http://www.jboss.org/file-access/default/members/jbossrichfaces/freezone/docs/devguide/en/html/ArchitectureOverview.html#XCSSfileformat" target="_new">using XCSS,</a> etc&#8230;  But this should get you started!</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/make-a-custom-richfaces-skin.html" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/make-a-custom-richfaces-skin.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Free Seam Cheat Sheet</title>
		<link>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/free-seam-cheat-sheet.html</link>
		<comments>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/free-seam-cheat-sheet.html#comments</comments>
		<pubDate>Sun, 30 Nov 2008 22:50:45 +0000</pubDate>
		<dc:creator>Devon</dc:creator>
				<category><![CDATA[Seam]]></category>

		<guid isPermaLink="false">http://www.digitalsanctuary.com/tech-blog/?p=172</guid>
		<description><![CDATA[DZone has released a free Seam Cheat Sheet Refcard:
http://refcardz.dzone.com/refcardz/core-seam
If you&#8217;re using Seam it&#8217;s definitely worth a download.  It is a very quick way to look up all of the commonly used annotations you might want, the schema URIs for various libraries, etc&#8230;
Give it a look-see!
Share on Facebook]]></description>
			<content:encoded><![CDATA[<p>DZone has released a free Seam Cheat Sheet Refcard:</p>
<p><a href="http://refcardz.dzone.com/refcardz/core-seam">http://refcardz.dzone.com/refcardz/core-seam</a></p>
<p>If you&#8217;re using Seam it&#8217;s definitely worth a download.  It is a very quick way to look up all of the commonly used annotations you might want, the schema URIs for various libraries, etc&#8230;</p>
<p>Give it a look-see!</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/free-seam-cheat-sheet.html" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/free-seam-cheat-sheet.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Seam EntityHome Design Pattern</title>
		<link>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/seam-entityhome-design-pattern.html</link>
		<comments>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/seam-entityhome-design-pattern.html#comments</comments>
		<pubDate>Sat, 12 Apr 2008 02:17:40 +0000</pubDate>
		<dc:creator>Devon</dc:creator>
				<category><![CDATA[Seam]]></category>
		<category><![CDATA[conversations]]></category>
		<category><![CDATA[EntityHome]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[lazyloading]]></category>

		<guid isPermaLink="false">http://www.digitalsanctuary.com/tech-blog/?p=94</guid>
		<description><![CDATA[I&#8217;ve been using Seam for over a year.  At some point the &#8220;Home&#8221; object was introduced to the documentation (Chapter 11).  Reading the documentation didn&#8217;t convince me of the point.  Being an ATG guy at heart, I still prefer using &#8220;form handlers&#8221; for managing my important entities.  So I haven&#8217;t bothered.
However, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using Seam for over a year.  At some point the &#8220;Home&#8221; object was introduced to the documentation (Chapter 11).  Reading the documentation didn&#8217;t convince me of the point.  Being an ATG guy at heart, I still prefer using &#8220;form handlers&#8221; for managing my important entities.  So I haven&#8217;t bothered.</p>
<p>However, just recently I ran into a little problem with LazyInitializationExceptions.  I&#8217;m sure you&#8217;ve run into them yourself.  Basically, when Hibernate loads an entity for you, it&#8217;s loaded by an entity manager which is available to manage that object within a specific scope.  This effects persisting changes.  Also, if you have properties on that entity that have a fetchType.LAZY, those properties can only be lazily loaded while the same entity manager is available.  If it&#8217;s not, you get LazyInitializationExceptions.  No fun.</p>
<p>So in Seam, what I usually do to avoid this, is to create a long running conversation, and load the entity within the context of that conversation.  Then, as long as you&#8217;re still in that long running conversation, you can lazily load all the properties you want.</p>
<p>Normally this is fine.  However, in my latest project the application will send e-mails to users when they get a new inter-user message.  If they click on the link in the e-mail, they come to the site, but without the existing long running conversation query parameter.  Their user component is session scoped, so they&#8217;re still logged in, but the user object is now outside of it&#8217;s conversation, and if you attempt to access lazily loaded properties, for instance the user&#8217;s messages they are trying to see based on the e-mail, blammo: exception central.  Unhappy users.</p>
<p>I was pointed to this page:  <a href="http://www.seamframework.org/Documentation/UsingEntityHomeForEntitiesInLongrunningContexts" target="_new" >Using EntityHome for entities in long-running contexts</a></p>
<p>Which showed me how to use the EntityHome to avoid the whole problem.  Basically it works like this:</p>
<p>When the user logs in, set the user entity&#8217;s id into a session scoped component.  Don&#8217;t bother with long running conversations (at least not for the user).  The User Home component&#8217;s Factory method creates a user component using the session scoped user id, anytime the user component is referenced.  This component entity is loaded within the context of the current conversation (if it hasn&#8217;t already been loaded).  So, presto-magic, no lazy loading issues.</p>
<p>It let me fix the issue with about 20 lines of code, and little trouble.  It&#8217;s working perfectly so far.  </p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/seam-entityhome-design-pattern.html" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/seam-entityhome-design-pattern.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>10MinuteMail Updates</title>
		<link>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/10minutemail-updates.html</link>
		<comments>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/10minutemail-updates.html#comments</comments>
		<pubDate>Mon, 24 Mar 2008 07:30:31 +0000</pubDate>
		<dc:creator>Devon</dc:creator>
				<category><![CDATA[10MinuteMail]]></category>
		<category><![CDATA[Seam]]></category>
		<category><![CDATA[ad-aware]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[internationalization]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[richfaces]]></category>
		<category><![CDATA[Spam]]></category>

		<guid isPermaLink="false">http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/10minutemail-updates.html</guid>
		<description><![CDATA[I just pushed a new version of 10MinuteMail.  Here are the notable updates:

Removed the Ad-Aware links and text.  No one was clicking on them anyhow.
Added some translation fixes.
Implemented AJAX based (RichFaces) refreshing of the list of e-mails in your inbox.
Added smtp client throttling (in Postfix) to limit the number of messages accepted from [...]]]></description>
			<content:encoded><![CDATA[<p>I just pushed a new version of 10MinuteMail.  Here are the notable updates:</p>
<ol>
<li>Removed the Ad-Aware links and text.  No one was clicking on them anyhow.</li>
<li>Added some translation fixes.</li>
<li>Implemented AJAX based (RichFaces) refreshing of the list of e-mails in your inbox.</li>
<li>Added smtp client throttling (in Postfix) to limit the number of messages accepted from a single source within 60 seconds.  This seems to have already fixed the negative impact of high volume spammers on the function of the site.</li>
<li>Removed the &#8220;Get Another E-Mail&#8221; feature.  While this was a user request, I discovered that it was being abused by spammers.</li>
<li>Added a Forward feature to allow you to forward a received e-mail to your home account for storage.</li>
</ol>
<p>Enjoy!  If you have any issues with the AJAX refreshes, let me know, but I think it should work better now.</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/10minutemail-updates.html" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/10minutemail-updates.html/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>How To Resize Uploaded Images Using Java &#8211; Better Way</title>
		<link>http://www.digitalsanctuary.com/tech-blog/java/how-to-resize-uploaded-images-using-java-better-way.html</link>
		<comments>http://www.digitalsanctuary.com/tech-blog/java/how-to-resize-uploaded-images-using-java-better-way.html#comments</comments>
		<pubDate>Fri, 14 Mar 2008 01:23:39 +0000</pubDate>
		<dc:creator>Devon</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Seam]]></category>
		<category><![CDATA[BufferedImage]]></category>
		<category><![CDATA[Byte Array]]></category>
		<category><![CDATA[byte[]]]></category>
		<category><![CDATA[Image]]></category>
		<category><![CDATA[ImageIcon]]></category>
		<category><![CDATA[JAI]]></category>
		<category><![CDATA[JPG]]></category>
		<category><![CDATA[Resize]]></category>

		<guid isPermaLink="false">http://www.digitalsanctuary.com/tech-blog/java/how-to-resize-uploaded-images-using-java-better-way.html</guid>
		<description><![CDATA[Based on helpful comments from Matt on this previous post:
How To Resize Uploaded Images Using Java
I have upgraded the image resizing code.  The results are noticeably better in quality, even at thumbnail sizes.  I wanted to share the completed new code, in case anyone needs it.
Again, thanks to Matt S. for his pointers.

 [...]]]></description>
			<content:encoded><![CDATA[<p>Based on helpful comments from Matt on this previous post:</p>
<p><a href="http://www.digitalsanctuary.com/tech-blog/java/how-to-resize-uploaded-images-using-java.html">How To Resize Uploaded Images Using Java</a></p>
<p>I have upgraded the image resizing code.  The results are noticeably better in quality, even at thumbnail sizes.  I wanted to share the completed new code, in case anyone needs it.</p>
<p>Again, thanks to Matt S. for his pointers.</p>
<pre class="brush: java;">
    /**
     * The JAI.create action name for handling a stream.
     */
    private static final String JAI_STREAM_ACTION = &quot;stream&quot;;

    /**
     * The JAI.create action name for handling a resizing using a subsample averaging technique.
     */
    private static final String JAI_SUBSAMPLE_AVERAGE_ACTION = &quot;SubsampleAverage&quot;;

    /**
     * The JAI.create encoding format name for JPEG.
     */
    private static final String JAI_ENCODE_FORMAT_JPEG = &quot;JPEG&quot;;

    /**
     * The JAI.create action name for encoding image data.
     */
    private static final String JAI_ENCODE_ACTION = &quot;encode&quot;;

    /**
     * The http content type/mime-type for JPEG images.
     */
    private static final String JPEG_CONTENT_TYPE = &quot;image/jpeg&quot;;

    private int mMaxWidth = 800;

    private int mMaxWidthThumbnail = 150;

.....

    /**
     * This method takes in an image as a byte array (currently supports GIF, JPG, PNG and
     * possibly other formats) and
     * resizes it to have a width no greater than the pMaxWidth parameter in pixels.
     * It converts the image to a standard
     * quality JPG and returns the byte array of that JPG image.
     *
     * @param pImageData
     *                the image data.
     * @param pMaxWidth
     *                the max width in pixels, 0 means do not scale.
     * @return the resized JPG image.
     * @throws IOException
     *                 if the image could not be manipulated correctly.
     */
    public byte[] resizeImageAsJPG(byte[] pImageData, int pMaxWidth) throws IOException {
	InputStream imageInputStream = new ByteArrayInputStream(pImageData);
	// read in the original image from an input stream
	SeekableStream seekableImageStream = SeekableStream.wrapInputStream(imageInputStream, true);
	RenderedOp originalImage = JAI.create(JAI_STREAM_ACTION, seekableImageStream);
	((OpImage) originalImage.getRendering()).setTileCache(null);
	int origImageWidth = originalImage.getWidth();
	// now resize the image
	double scale = 1.0;
	if (pMaxWidth &gt; 0 &amp;&amp; origImageWidth &gt; pMaxWidth) {
	    scale = (double) pMaxWidth / originalImage.getWidth();
	}
	ParameterBlock paramBlock = new ParameterBlock();
	paramBlock.addSource(originalImage); // The source image
	paramBlock.add(scale); // The xScale
	paramBlock.add(scale); // The yScale
	paramBlock.add(0.0); // The x translation
	paramBlock.add(0.0); // The y translation

	RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_RENDERING,
		RenderingHints.VALUE_RENDER_QUALITY);

	RenderedOp resizedImage = JAI.create(JAI_SUBSAMPLE_AVERAGE_ACTION, paramBlock, qualityHints);

	// lastly, write the newly-resized image to an output stream, in a specific encoding
	ByteArrayOutputStream encoderOutputStream = new ByteArrayOutputStream();
	JAI.create(JAI_ENCODE_ACTION, resizedImage, encoderOutputStream, JAI_ENCODE_FORMAT_JPEG, null);
	// Export to Byte Array
	byte[] resizedImageByteArray = encoderOutputStream.toByteArray();
	return resizedImageByteArray;
    }
</pre>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.digitalsanctuary.com/tech-blog/java/how-to-resize-uploaded-images-using-java-better-way.html" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitalsanctuary.com/tech-blog/java/how-to-resize-uploaded-images-using-java-better-way.html/feed</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>login-required=&#8221;true&#8221; Will End Your Conversation</title>
		<link>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/login-requiredtrue-will-end-your-conversation.html</link>
		<comments>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/login-requiredtrue-will-end-your-conversation.html#comments</comments>
		<pubDate>Tue, 11 Mar 2008 06:04:03 +0000</pubDate>
		<dc:creator>Devon</dc:creator>
				<category><![CDATA[Seam]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[conversations]]></category>
		<category><![CDATA[identity]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[login]]></category>
		<category><![CDATA[login-required]]></category>

		<guid isPermaLink="false">http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/login-requiredtrue-will-end-your-conversation.html</guid>
		<description><![CDATA[In Seam, in the pages.xml or mypage.page.xml files, you note that a given page requires the user to be logged in to view the page.  It is a very easy way of handling simple security.  What happens is if a user attempts to access a page with the login-required="true" attribute and they are [...]]]></description>
			<content:encoded><![CDATA[<p>In Seam, in the pages.xml or mypage.page.xml files, you note that a given page requires the user to be logged in to view the page.  It is a very easy way of handling simple security.  What happens is if a user attempts to access a page with the <code>login-required="true"</code> attribute and they are not logged in, they are automatically redirected to your login page (as defined in your pages.xml).  Once they login, they are automatically redirected back to the page they had attempted to access initially.  Very elegant, and much easier than writing all that yourself.</p>
<p>There is however a &#8220;gotcha&#8221; you should be aware of in this flow.  If you use the login page, or logic, to start a long running conversation (I do this because my User entity object has some large binary properties which I want lazily loaded), the post-login redirection will kill that conversation.  In my case this led to lazy loading exceptions down the road.  </p>
<p>It took me a while to figure out the cause, as it only happened much later in the application, and most of the time it worked (when I logged in purposefully from the main page), but sometimes would break (when I&#8217;d had an expired session and gone through the login auto-redirection flow).  Eventually though I was able to track it down to those two scenarios.</p>
<p>What is happening is this: before the first redirection happens (to the login page), the Seam Redirect classes <code>captureCurrentView</code> method is called.  This basically saves the information about the page you were trying to view (it&#8217;s a little more complex than that- being all Faces like and whatnot, but that&#8217;s the gist of it).  This method creates a long running conversation in order to hold this state across the multiple pages.  If there was no previous long running conversation to join, and it had to create a new conversation, it stores a <code>conversationBegun</code> flag of <code>true</code>.</p>
<p>Then you hit the login page, where the page (or code) would <code>Begin</code> a long running conversation, except you almost certainly have <code>join=true</code>, so it joins the existing long running conversation, which was created by the <code>captureCurrentView</code> method.  This is the conversation your User entity was loaded up in.</p>
<p>After your login was successful, the Redirect classes <code>returnToCapturedView</code> method is called to send you back to where you&#8217;d tried to go initially.</p>
<p>This method has the following block:</p>
<pre lang="java">
if (conversationBegun) {
       Conversation.instance().end();
}
</pre>
<p>This ends the conversation you had loaded your User entity within, and when you hit your destination page, there is no long running conversation at all.  Then, a few minutes later, it&#8217;s lazy loading exception time.</p>
<p>The downside is there isn&#8217;t a really clean fix that I am aware of  yet.</p>
<p>The upside is there is a pretty simple hack: just add a <code>&lt;begin-conversation join="true" /&gt;</code> to all of your pages which have the <code>login-required="true"</code> attribute.  This creates a new long running conversation before the Redirect does it&#8217;s work, so it in turn joins that conversation instead of creating a new one, the <code>conversationBegun</code> flag is false, and the <code>returnToCapturedView</code> method doesn&#8217;t end your conversation.  It&#8217;s a hack, and you have to remember to add it to every page which requires a logged in state, but it does work.</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/login-requiredtrue-will-end-your-conversation.html" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/login-requiredtrue-will-end-your-conversation.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Resize Uploaded Images Using Java</title>
		<link>http://www.digitalsanctuary.com/tech-blog/java/how-to-resize-uploaded-images-using-java.html</link>
		<comments>http://www.digitalsanctuary.com/tech-blog/java/how-to-resize-uploaded-images-using-java.html#comments</comments>
		<pubDate>Thu, 06 Mar 2008 18:03:48 +0000</pubDate>
		<dc:creator>Devon</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Seam]]></category>
		<category><![CDATA[gallery]]></category>
		<category><![CDATA[Image]]></category>

		<guid isPermaLink="false">http://www.digitalsanctuary.com/tech-blog/java/how-to-resize-uploaded-images-using-java.html</guid>
		<description><![CDATA[Edit:  please read the better way here: Better way to Resize Images Using Java!
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;
I am building a Seam application which need to support users uploading images, and then the site displaying them.  I wanted to resize big images into something reasonable (say 1024 or 800 px wide) and generate a thumbnail, and I [...]]]></description>
			<content:encoded><![CDATA[<p>Edit:  please read the better way here: <a href="http://www.digitalsanctuary.com/tech-blog/java/how-to-resize-uploaded-images-using-java-better-way.html">Better way to Resize Images Using Java</a>!</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
I am building a Seam application which need to support users uploading images, and then the site displaying them.  I wanted to resize big images into something reasonable (say 1024 or 800 px wide) and generate a thumbnail, and I also wanted to standardize on a single image format just to make things easy and consistent.</p>
<p>So I needed method that would take an uploaded image as a byte array (byte[]) and would resize the image (if needed) and convert it to a fixed quality JPG, and give me back a byte array to store in the database.  I am using Seam, so I get a handy byte array, but this method should work fine for non-Seam applications as well.</p>
<pre lang="java">
    /**
     * This method takes in an image as a byte array (currently supports GIF, JPG, PNG and possibly other formats) and
     * resizes it to have a width no greater than the pMaxWidth parameter in pixels. It converts the image to a standard
     * quality JPG and returns the byte array of that JPG image.
     *
     * @param pImageData
     *                the image data.
     * @param pMaxWidth
     *                the max width in pixels, 0 means do not scale.
     * @return the resized JPG image.
     * @throws IOException
     *                 if the iamge could not be manipulated correctly.
     */
    public byte[] resizeImageAsJPG(byte[] pImageData, int pMaxWidth) throws IOException {
	// Create an ImageIcon from the image data
	ImageIcon imageIcon = new ImageIcon(pImageData);
	int width = imageIcon.getIconWidth();
	int height = imageIcon.getIconHeight();
	mLog.info("imageIcon width: #0  height: #1", width, height);
	// If the image is larger than the max width, we need to resize it
	if (pMaxWidth > 0 &#038;&#038; width > pMaxWidth) {
	    // Determine the shrink ratio
	    double ratio = (double) pMaxWidth / imageIcon.getIconWidth();
	    mLog.info("resize ratio: #0", ratio);
	    height = (int) (imageIcon.getIconHeight() * ratio);
	    width = pMaxWidth;
	    mLog.info("imageIcon post scale width: #0  height: #1", width, height);
	}
	// Create a new empty image buffer to "draw" the resized image into
	BufferedImage bufferedResizedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
	// Create a Graphics object to do the "drawing"
	Graphics2D g2d = bufferedResizedImage.createGraphics();
	g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
	// Draw the resized image
	g2d.drawImage(imageIcon.getImage(), 0, 0, width, height, null);
	g2d.dispose();
	// Now our buffered image is ready
	// Encode it as a JPEG
	ByteArrayOutputStream encoderOutputStream = new ByteArrayOutputStream();
	JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(encoderOutputStream);
	encoder.encode(bufferedResizedImage);
	byte[] resizedImageByteArray = encoderOutputStream.toByteArray();
	return resizedImageByteArray;
    }
</pre>
<p>In my application I call this method twice, once to convert the uploaded image into a limited size JPG, and then once again to generate a much smaller thumbnail.  I store both of these in the database and will use caching at the Apache layer to ensure performance.</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.digitalsanctuary.com/tech-blog/java/how-to-resize-uploaded-images-using-java.html" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.digitalsanctuary.com/tech-blog/java/how-to-resize-uploaded-images-using-java.html/feed</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
	</channel>
</rss>
