<?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&#039;s Digital Sanctuary &#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>Mon, 30 Jan 2012 23:04:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Seam Identity Management</title>
		<link>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/seam-identity-management.html</link>
		<comments>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/seam-identity-management.html#comments</comments>
		<pubDate>Mon, 11 Jul 2011 15:34:32 +0000</pubDate>
		<dc:creator>Devon</dc:creator>
				<category><![CDATA[Seam]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.digitalsanctuary.com/tech-blog/?p=761</guid>
		<description><![CDATA[During a recent coding getaway to Maine (see my post on the 2011 HackFestaThon) I decided to write a basic Seam project as a starting point for my future Seam based web applications.  The idea is to provide common features &#8230; <a href="http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/seam-identity-management.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>During a recent coding getaway to Maine (see my post on the <a title="Coding Weekend in Maine 2011" href="http://www.digitalsanctuary.com/blog/uncategorized/weekend-in-maine.html" target="_blank">2011 HackFestaThon</a>) I decided to write a basic Seam project as a starting point for my future Seam based web applications.  The idea is to provide common features such as Login, Logout, Registration, Forgot Password, User Management, Audit Logging, Image Upload Handling, Video Upload Handling, etc&#8230; so next time I have an idea that I want to hack together I won&#8217;t have to re-write or copy-paste in basic functionality like that.</p>
<p>I spent about a day working on things before I discovered that I really should be using the <a title="Seam 2.2 Identity Management" href="http://docs.jboss.org/seam/2.2.2.Final/reference/en-US/html/security.html#d0e9101" target="_blank">Seam framework&#8217;s Identity Management</a> feature.  So I threw out everything I&#8217;d done, and started by re-reading the docs, and went from there.  Seam&#8217;s Identity Management framework is VERY powerful, but is also a little complicated to get going and in many cases it seems like it would easier to just write stuff from scratch.  I&#8217;m banking on the powerful stuff being worth the initial learning curve and a little extra pain.</p>
<p>When I get the starter project in a more complete state I will be open sourcing the whole thing to help others along, but I wanted to share a few things I&#8217;ve learned so far:</p>
<p>In order to use the Email address as the login instead of a username, you need to remove the username property from your UserAccount entity and annotate the Email address property like so:</p>
<pre class="brush: java; title: ; notranslate">
@NotNull
@UserPrincipal
@Email
public String getEmail() {
    return email;
}
</pre>
<p>Actions like Registration need a RunAsOperation inner class to handle the fine grained security controls that the Identity Management framework enforces:</p>
<pre class="brush: java; title: ; notranslate">
    public void register() {
	verified = (confirm != null &amp;&amp; confirm.equals(password));

	if (!verified) {
	    FacesMessages.instance().addToControl(&quot;confirmPassword&quot;, &quot;Passwords do not match&quot;);
	}
	new RunAsOperation() {
	    public void execute() {
		try {
		    // Check if email address has already been used
		    if (identityManager.userExists(getEmail())) {
			FacesMessages.instance().addToControl(&quot;email&quot;, &quot;Email has already been used.&quot;);
			return;
		    }
		    identityManager.createUser(email, password, mFirstName, mLastName);
		} catch (IdentityManagementException e) {
		    // TODO Auto-generated catch block
		    e.printStackTrace();
		}
		identityManager.grantRole(email, &quot;member&quot;);
	    }
	}.addRole(&quot;admin&quot;).run();

	// Login the user
	identity.getCredentials().setUsername(email);
	identity.getCredentials().setPassword(password);
	identity.login();
    }
</pre>
<p>Populating custom properties on the User during things like registration requires observing events:</p>
<pre class="brush: java; title: ; notranslate">
    @Observer(JpaIdentityStore.EVENT_PRE_PERSIST_USER)
    public void prePersistUser(UserAccount pNewUser) {
	// Setup additional UserAccount properties before the user is created
	pNewUser.setRegistrationDate(new Date());
	pNewUser.setOptIn(isOptIn());
    }
</pre>
<p>You can log audit events with the user&#8217;s IP address by doing things like this:</p>
<pre class="brush: java; title: ; notranslate">
@Scope(ScopeType.EVENT)
@Name(&quot;userEvents&quot;)
public class UserEvents {
    @Logger
    private Log mLog;

    @Observer(JpaIdentityStore.EVENT_USER_AUTHENTICATED)
    public void loginSuccessful(UserAccount pUser) {
	mLog.info(&quot;User logged in with email: #0&quot;, pUser.getEmail());
	pUser.setLastLoginDate(new Date());
	Contexts.getSessionContext().set(&quot;currentUser&quot;, pUser);
	AuditEvent loginEvent = new AuditEvent(((ServletRequest) FacesContext.getCurrentInstance().getExternalContext()
		.getRequest()).getRemoteAddr(), pUser.getId(), &quot;Login Success&quot;, null);
	Events.instance().raiseEvent(&quot;auditEvent&quot;, loginEvent);
    }
}
</pre>
<p>Hopefully I&#8217;ll have the starter project ready soon and will share it with you all.  In the meantime, happy hacking!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/seam-identity-management.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>First brush with Ruby On Rails</title>
		<link>http://www.digitalsanctuary.com/tech-blog/general/first-brush-with-ruby-on-rails.html</link>
		<comments>http://www.digitalsanctuary.com/tech-blog/general/first-brush-with-ruby-on-rails.html#comments</comments>
		<pubDate>Tue, 31 May 2011 03:31:22 +0000</pubDate>
		<dc:creator>Devon</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Seam]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.digitalsanctuary.com/tech-blog/?p=732</guid>
		<description><![CDATA[Earlier this week I was hanging out with a friend talking about a project he was working on and I decided to poke at it a bit with him, and as such got my first hands on experience with Ruby &#8230; <a href="http://www.digitalsanctuary.com/tech-blog/general/first-brush-with-ruby-on-rails.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Earlier this week I was hanging out with a friend talking about a project he was working on and I decided to poke at it a bit with him, and as such got my first hands on experience with Ruby on Rails.</p>
<p>Ruby on Rails or RoR obviously has huge buzz and is a very popular web application development framework lately.  Lots of people have praised it and lots of great sites have been built using it.  I&#8217;ve never bothered to learn it myself for a few reasons.  First I&#8217;m a Java guy (ATG and Seam) and have been for years.  Given limited time and limited brain capacity I&#8217;d rather learn more Java/Java Frameworks/etc&#8230; than try to learn a whole new language.  Secondly many trusted friends advised me that while RoR does somethings REALLY well and makes some things REALLY easy, once you need to try to break outside of the pre-imagined structure/features that RoR provides out of the box, things rapidly go downhill.  Those reasons aside, the high level of buzz has meant I&#8217;ve always been somewhat curious, so this opportunity to finally get my hands a little dirty with RoR was welcome.</p>
<p>Getting started with RoR on Mac OS X is very easy.  It&#8217;s pre-installed and works right out of the box.  However after upgrading Rails and the gems I ran into a known blocking bug which after some Googling I was able to fix by downgrading rake to 0.8.7 in the Gemfile.  So not a 100% smooth start, but not too bad.</p>
<p>The Rails generate scaffold commands make it very easy to create a data object, the related schema changes (managed through the rake migration mechanism), and related CRUD pages and controllers.  You can be up and running very quickly and creating, browsing, editing, and deleting records.  This can make it very easy to get a basic application laid out, and provides lots of plumbing automatically.</p>
<p>I didn&#8217;t get much farther than some simple controller modifications, outbound e-mail sending, etc&#8230;  so I&#8217;m far from a real RoR developer.  However I ran into enough pain points so far that I don&#8217;t think RoR is for me.  I don&#8217;t want to start any language/framework wars, but here is what I ran into:</p>
<p>A lot of the &#8220;magic&#8221; seems great at first, but as soon as you want go outside of the box or tweak how things are working, it becomes a massive liability.  For instance when using the generate scaffold command to create data objects you can setup relationships/foreign keys by passing in a column name that matches the form OtherClass_id:integer, which will be interpreted to be a FK association to the other class&#8217;s id column to join the objects.  This is great.  However, what if you want to add two relationships to the same Other class?  For instance an Message has a Sender and a Recipient, both of which are Users.  I can use user_id:integer for one, but how do I do the other?  How do I use column/property names that don&#8217;t fit that naming convention, for instance I&#8217;d want sender_id and recipient_id.  None of the getting started guides I was able to find covered that.  Googling for things like &#8220;scaffold multiple foreign keys&#8221; didn&#8217;t answer the question, etc&#8230;  I&#8217;m sure it&#8217;s possible, but finding out how wasn&#8217;t easy, and the default way hides and obscures the actual plumbing so it&#8217;s not easy to figure out how to make simple changes or additions.</p>
<p>Data object classes in the app/model area all extend ActiveRecord::Base and as generated by generate scaffold are completely empty.  There&#8217;s no clue or indication of the fields, any logic available, any relationships, property types, etc&#8230;</p>
<p>Emailer classes use magic mappings between method names and e-mail templates.  Because it&#8217;s &#8220;magic&#8221; I have no idea how to change a template file name if I wanted to.  App/helper classes are created, but they&#8217;re empty, so I have no idea what they are doing, or meant to do.  And so on.  If I was an expert RoR developer I&#8217;m sure I&#8217;d know, or if I read a few books I&#8217;d understand, but starting from scratch and trying to learn as I go, it proved very frustrating.</p>
<p>The much touted RoR Community proved to be more of a liability than an asset to me.  Especially when combined with the many, rapid, backwards incompatible, RoR releases that have come out so far.  When looking for information, guides, and answers related to RoR you end up finding things spread all over: blogs, forums, mailing lists, Ruby sites, RoR sites, groups, etc&#8230;  Most of these posts/documents refer to older versions of RoR.  Most of them don&#8217;t have dates or specify which version they are working with.  Many questions on forums are unanswered.  The end result is you find what you hope is a reasonable solution for an issue only to find that the code sample or directions are written for a previous version of RoR, and trying to follow the instructions or paste the code in the current RoR version results in weird errors or worse.</p>
<p>Each new version of RoR seems to massively change and/or break common APIs and change how things are supposed to be done, etc&#8230;  I ran into several situations where it seems like a method was renamed, with no backwards compatible alias left in place, for no other reason than they wanted to change the name, which breaks older code for  no real purpose.</p>
<p>I&#8217;m also not a fan of weakly typed languages.  Strongly typed languages provide compile time validation, IDE auto-completion, and easy to navigate API documentation.  With larger, more complex projects, or projects involving many developers, or projects utilizing many 3rd party libraries, these advantages become significant in my opinion.</p>
<p>So from my standpoint, JBoss Seam provides most of the advantages of RoR, including several improvements, without many of the liabilities.  Plus it&#8217;s in Java which is my strongest programming language.  I&#8217;ll stick with Seam, but I&#8217;ll still respect the creations of folks who use other tools, including RoR.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digitalsanctuary.com/tech-blog/general/first-brush-with-ruby-on-rails.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<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 &#8230; <a href="http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/10minutemail-and-form-submission-charsets-in-seamjsf.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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; title: ; notranslate">
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; title: ; notranslate">
....
	&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>
]]></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>3</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 &#8230; <a href="http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/seam-2x-web-development.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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>
]]></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 &#8230; <a href="http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/environment-specific-mail-auth-and-seams-mailsession.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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; title: ; notranslate">
	&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; title: ; notranslate">
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; title: ; notranslate">
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; title: ; notranslate">
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>
]]></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 &#8230; <a href="http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/make-a-custom-richfaces-skin.html">Continue reading <span class="meta-nav">&#8594;</span></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; title: ; notranslate">
   &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>
]]></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 &#8230; <a href="http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/free-seam-cheat-sheet.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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>
]]></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 &#8230; <a href="http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/seam-entityhome-design-pattern.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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>
]]></content:encoded>
			<wfw:commentRss>http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/seam-entityhome-design-pattern.html/feed</wfw:commentRss>
		<slash:comments>6</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 &#8230; <a href="http://www.digitalsanctuary.com/tech-blog/java/jboss/seam/10minutemail-updates.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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>
]]></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 &#8230; <a href="http://www.digitalsanctuary.com/tech-blog/java/how-to-resize-uploaded-images-using-java-better-way.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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; title: ; notranslate">
    /**
     * 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>
]]></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>54</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 1/43 queries in 0.009 seconds using disk: basic
Object Caching 836/937 objects using disk: basic

Served from: www.digitalsanctuary.com @ 2012-02-04 12:04:09 -->
