<?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>demetrio.it blog &#187; Tips</title>
	<atom:link href="http://blog.demetrio.it/category/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.demetrio.it</link>
	<description>nessun limite all'immaginazione</description>
	<lastBuildDate>Thu, 15 Jul 2010 15:42:55 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>RichFaces editor: move the caret position at the end after a reRender</title>
		<link>http://blog.demetrio.it/2010/02/12/richfaces-editor-move-the-caret-position-at-the-end-after-a-rerender/</link>
		<comments>http://blog.demetrio.it/2010/02/12/richfaces-editor-move-the-caret-position-at-the-end-after-a-rerender/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 20:28:41 +0000</pubDate>
		<dc:creator>Demetrio Filocamo</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[cursor]]></category>
		<category><![CDATA[editor]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[move caret]]></category>
		<category><![CDATA[position]]></category>
		<category><![CDATA[rich]]></category>
		<category><![CDATA[richfaces]]></category>

		<guid isPermaLink="false">http://blog.demetrio.it/?p=194</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>Some times it can happen you need to re-render a block that includes the RichFaces editor: if the user is using to edit a piece of text, after the re-rendering the caret goes back to the first place so if the user were writing he&#8217;d have to manually move it every time it happens.</p>
<p>The solution to this problem (that you can use also for other purposes) is a javascript piece of code found on the TinyMCE forum, adapted for the RichFaces specific case:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #003366; font-weight: bold;">function</span> moveCaretToTheEnd<span style="color: #009900;">&#40;</span>editor_jsf_id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> editor_id <span style="color: #339933;">=</span> editor_jsf_id <span style="color: #339933;">+</span> <span style="color: #3366CC;">'TextArea'</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> ed <span style="color: #339933;">=</span> tinyMCE.<span style="color: #660066;">getInstanceById</span><span style="color: #009900;">&#40;</span>editor_id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> root <span style="color: #339933;">=</span> ed.<span style="color: #660066;">dom</span>.<span style="color: #660066;">getRoot</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">// This gets the root node of the editor window</span>
        <span style="color: #003366; font-weight: bold;">var</span> lastnode <span style="color: #339933;">=</span> root.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span>root.<span style="color: #660066;">childNodes</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>tinymce.<span style="color: #660066;">isGecko</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">// But firefox places the selection outside of that tag, so we need to go one level deeper:</span>
            lastnode <span style="color: #339933;">=</span> lastnode.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span>lastnode.<span style="color: #660066;">childNodes</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #006600; font-style: italic;">// Now, we select the node</span>
        ed.<span style="color: #660066;">selection</span>.<span style="color: #660066;">select</span><span style="color: #009900;">&#40;</span>lastnode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #006600; font-style: italic;">// And collapse the selection to the end to put the caret there:</span>
        ed.<span style="color: #660066;">selection</span>.<span style="color: #660066;">collapse</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>The only change I had to do is on the first line of the script as the id of the component we have to pass to get the editor instance is <componentId>+&#8221;TextArea&#8221; so I had to compose the id passed to the js function with the &#8220;TextArea&#8221; string.</p>
<p>To discover the id of the component we can use the built-in RichFaces function <em>rich:clientId</em> in this way (example in a poll component):</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a:poll</span> <span style="color: #000066;">reRender</span>=<span style="color: #ff0000;">&quot;currentChatMsgs,recipientList,threadFoldedSection&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">oncomplete</span>=<span style="color: #ff0000;">&quot;moveCaretToTheEnd('#{rich:clientId('myEditorJsfId')}')&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>Demetrio Filocamo</p>
<p>&#8212;&#8212;</p>
<p>JBoss RichFaces 3.3 (book) &#8211; <a href="http://www.packtpub.com/jboss-richfaces-3-3">http://www.packtpub.com/jboss-richfaces-3-3</a></p>
<p>Learn RichFaces step by step developing a sample application.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.demetrio.it/2010/02/12/richfaces-editor-move-the-caret-position-at-the-end-after-a-rerender/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RichFaces editor: how to intercept the &#8220;return&#8221; key to submit a form</title>
		<link>http://blog.demetrio.it/2010/02/12/richfaces-editor-how-to-intercept-the-return-key-to-submit-a-form/</link>
		<comments>http://blog.demetrio.it/2010/02/12/richfaces-editor-how-to-intercept-the-return-key-to-submit-a-form/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 19:06:35 +0000</pubDate>
		<dc:creator>Demetrio Filocamo</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[editor]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[intercept]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[onkeypress]]></category>
		<category><![CDATA[return key]]></category>
		<category><![CDATA[rich]]></category>
		<category><![CDATA[richfaces]]></category>

		<guid isPermaLink="false">http://blog.demetrio.it/?p=156</guid>
		<description><![CDATA[Hello,
I&#8217;ll try to write more on my blog and keep you update about every technique I use and that can be very useful to you as well.
Today I needed to submit a form with an editor element when the user pressed the &#8220;return&#8221; key (instead of creating a new line).
The code is not so complicate [...]]]></description>
			<content:encoded><![CDATA[<p>Hello,<br />
I&#8217;ll try to write more on my blog and keep you update about every technique I use and that can be very useful to you as well.</p>
<p>Today I needed to submit a form with an editor element when the user pressed the &#8220;return&#8221; key (instead of creating a new line).</p>
<p>The code is not so complicate but as the rich:editor uses the TinyMCE component you have to search all around to find the right way. Better to have a complete solution.</p>
<p>It consists on creating an handler onKeyPress and call a javascript function (created by a:jsFunction) to submit our form. Simpler doing then saying it.</p>
<p>Let&#8217;s start by including the editor in the standard way (form, editor, submit button):</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rich:editor</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{editorBean.myValue}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a:commandButton</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Send&quot;</span> <span style="color: #000066;">reRender</span>=<span style="color: #ff0000;">&quot;something&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h:form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>I&#8217;ve kept it simple (stripped out all the params and attribute I use) to target only our problem.</p>
<p>Let&#8217;s define a javascript function handler for our use case:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #003366; font-weight: bold;">function</span> returnSubmit<span style="color: #009900;">&#40;</span>ed<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        ed.<span style="color: #660066;">onKeyPress</span>.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>ed<span style="color: #339933;">,</span> e<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> keyCode <span style="color: #339933;">=</span> e.<span style="color: #660066;">keyCode</span> <span style="color: #339933;">||</span> e.<span style="color: #660066;">which</span> <span style="color: #339933;">||</span> e.<span style="color: #660066;">charCode</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>keyCode <span style="color: #339933;">==</span> <span style="color: #CC0000;">13</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #006600; font-style: italic;">// My return key handler code here </span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>The <em>ed</em> variable will be passed by the editor; let&#8217;s configure our new function to the onsetup editor event:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rich:editor</span> </span>
<span style="color: #009900;">                <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{editorBean.myValue}&quot;</span> </span>
<span style="color: #009900;">                <span style="color: #000066;">onsetup</span>=<span style="color: #ff0000;">&quot;returnSubmit(ed)&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a:commandButton</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Send&quot;</span> <span style="color: #000066;">reRender</span>=<span style="color: #ff0000;">&quot;something&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h:form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Now we have a function that is called for each keyPress event, and inside it we can execute something on &#8220;return&#8221; key press.</p>
<p>What we have to do is to submit the form, the best way is to create an Ajax javascript function using a:jsFunction: in this way we can do standard Ajax updates also reRendering elements, submitting params and all the thing we are used to <img src='http://blog.demetrio.it/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Let&#8217;s create the function:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rich:editor</span> </span>
<span style="color: #009900;">                <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{editorBean.myValue}&quot;</span> </span>
<span style="color: #009900;">                <span style="color: #000066;">onsetup</span>=<span style="color: #ff0000;">&quot;returnSubmit(ed)&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a:commandButton</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Send&quot;</span> <span style="color: #000066;">reRender</span>=<span style="color: #ff0000;">&quot;something&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a:jsFunction</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;submitForm&quot;</span> <span style="color: #000066;">reRender</span>=<span style="color: #ff0000;">&quot;something&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h:form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Now we have to insert it into the handler and it&#8217;s done!</p>
<p>Here it is the whole code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #003366; font-weight: bold;">function</span> returnSubmit<span style="color: #009900;">&#40;</span>ed<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        ed.<span style="color: #660066;">onKeyPress</span>.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>ed<span style="color: #339933;">,</span> e<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> keyCode <span style="color: #339933;">=</span> e.<span style="color: #660066;">keyCode</span> <span style="color: #339933;">||</span> e.<span style="color: #660066;">which</span> <span style="color: #339933;">||</span> e.<span style="color: #660066;">charCode</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>keyCode <span style="color: #339933;">==</span> <span style="color: #CC0000;">13</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #006600; font-style: italic;">// My return key handler code here </span>
                submitForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rich:editor</span> </span>
<span style="color: #009900;">                <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{editorBean.myValue}&quot;</span> </span>
<span style="color: #009900;">                <span style="color: #000066;">onsetup</span>=<span style="color: #ff0000;">&quot;returnSubmit(ed)&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a:commandButton</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Send&quot;</span> <span style="color: #000066;">reRender</span>=<span style="color: #ff0000;">&quot;something&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a:jsFunction</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;submitForm&quot;</span> <span style="color: #000066;">reRender</span>=<span style="color: #ff0000;">&quot;something&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h:form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>Another tip</strong><br />
If with the js function you reRender components, do some action, set some property etc., to avoid duplication of code in the commandButton you can use the same js function into the button using the <em>onclick</em> attribute:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rich:editor</span> </span>
<span style="color: #009900;">                <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{editorBean.myValue}&quot;</span> </span>
<span style="color: #009900;">                <span style="color: #000066;">onsetup</span>=<span style="color: #ff0000;">&quot;returnSubmit(ed)&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a:commandButton</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Send&quot;</span> <span style="color: #000066;">onclick</span>=<span style="color: #ff0000;">&quot;submitForm();&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a:jsFunction</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;submitForm&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;#{myBean.myAction}&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">oncomplete</span>=<span style="color: #ff0000;">&quot;doSomething();&quot;</span></span>
<span style="color: #009900;">                  <span style="color: #000066;">reRender</span>=<span style="color: #ff0000;">&quot;first,second&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:setPropertyActionListener</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;valueToSet&quot;</span> <span style="color: #000066;">target</span>=<span style="color: #ff0000;">&quot;#{myBean.firstValue}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a:jsFunction<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h:form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Demetrio Filocamo</p>
<p>&#8212;&#8212;</p>
<p>JBoss RichFaces 3.3 (book) &#8211; <a href="http://www.packtpub.com/jboss-richfaces-3-3">http://www.packtpub.com/jboss-richfaces-3-3</a></p>
<p>Learn RichFaces step by step developing a sample application.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.demetrio.it/2010/02/12/richfaces-editor-how-to-intercept-the-return-key-to-submit-a-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Cache support to a seam-gen generated EAR project</title>
		<link>http://blog.demetrio.it/2009/04/03/adding-cache-support-to-a-seam-gen-generated-ear-project/</link>
		<comments>http://blog.demetrio.it/2009/04/03/adding-cache-support-to-a-seam-gen-generated-ear-project/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 00:08:33 +0000</pubDate>
		<dc:creator>Demetrio Filocamo</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[ear]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jboss cache]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[seam]]></category>
		<category><![CDATA[seam-gen]]></category>

		<guid isPermaLink="false">http://blog.demetrio.it/?p=110</guid>
		<description><![CDATA[Adding Cache support to a Seam project (Seam 2.1.x) it&#8217;s very simple and it is described in the official Seam developer documentation, anyways it doesn&#8217;t explain the exact steps to accomplish the task into an EAR project, I&#8217;m writing them to make your life even more simple  

Add treecache.xml (you can find it into the [...]]]></description>
			<content:encoded><![CDATA[<p>Adding Cache support to a Seam project (Seam 2.1.x) it&#8217;s very simple and it is described in the<a title="JBoss Seam Cache documentation" href="http://docs.jboss.com/seam/2.1.1.GA/reference/en-US/html/cache.html" target="_blank"> official Seam developer documentation</a>, anyways it doesn&#8217;t explain the exact steps to accomplish the task into an EAR project, I&#8217;m writing them to make your life even more simple <img src='http://blog.demetrio.it/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<ul>
<li>Add treecache.xml (you can find it into the seam blog example) to /resources/META-INF/</li>
<li>Open build.xml for editing, go to the &#8220;ear&#8221; target and tell to copy the treecache.xml file:<br />
&lt;target name=&#8221;ear&#8221; description=&#8221;Build the EAR structure in a staging directory&#8221;&gt;<br />
&#8230;<br />
    &lt;copy todir=&#8221;${ear.dir}/META-INF&#8221;&gt;<br />
        &lt;fileset dir=&#8221;${basedir}/resources/META-INF&#8221;&gt;<br />
            &lt;include name=&#8221;application.xml&#8221;/&gt;<br />
            &lt;include name=&#8221;jboss-app.xml&#8221;/&gt;<br />
            &lt;include name=&#8221;seam-deployment.properties&#8221;/&gt;<br />
            &lt;include name=&#8221;treecache.xml&#8221;/&gt;<br />
        &lt;/fileset&gt;<br />
    &lt;/copy&gt;<br />
&lt;/target&gt;</li>
<li>Edit components.xml, add the following XMLNS:<br />
xmlns:cache=&#8221;http://jboss.com/products/seam/cache&#8221;The following schema location:<br />
http://jboss.com/products/seam/cache http://jboss.com/products/seam/cache-2.1.xsd </p>
<p>And the following declaration:<br />
&lt;cache:jboss-cache-provider configuration=&#8221;META-INF/treecache.xml&#8221; /&gt;</li>
<li>Edit deployed-jars-ear.list and add the required JARs, I used the JBoss Cache 1.x for JBoss AS 4.2.X:<br />
jboss-cache.jar<br />
jgroups.jarHere there is the <a href="http://docs.jboss.com/seam/2.1.1.GA/reference/en-US/html/cache.html#d0e21178">list</a> of jars (and versions) for other configurations.</li>
</ul>
<p>And <a href="http://docs.jboss.com/seam/2.1.1.GA/reference/en-US/html/cache.html#d0e21343">here</a> you find the way how to use it in your projects.</p>
<p>Hope you liked it.</p>
<p>Demetrio</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.demetrio.it/2009/04/03/adding-cache-support-to-a-seam-gen-generated-ear-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>One-to-one relationship with auto-generated key using JPA/Hibernate using annotations</title>
		<link>http://blog.demetrio.it/2009/04/03/one-to-one-relationship-with-auto-generated-key-using-jpahibernate-using-annotations/</link>
		<comments>http://blog.demetrio.it/2009/04/03/one-to-one-relationship-with-auto-generated-key-using-jpahibernate-using-annotations/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 01:18:52 +0000</pubDate>
		<dc:creator>Demetrio Filocamo</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[auto generated key]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[one-to-one]]></category>
		<category><![CDATA[one2one]]></category>
		<category><![CDATA[seam]]></category>

		<guid isPermaLink="false">http://blog.demetrio.it/?p=115</guid>
		<description><![CDATA[ 
Adding a one-to-one relationship with shared primary key can become a difficult task if the main table key is an auto-generated one.
Even the Hibernate Annotations documentation example only works with not auto-generated id, if you try to use an auto incremental id, for example, 
it&#8217;s impossible to persist the 2 tables at the same time.
Surfing on [...]]]></description>
			<content:encoded><![CDATA[<p> </p>
<p>Adding a one-to-one relationship with shared primary key can become a difficult task if the main table key is an auto-generated one.</p>
<p>Even the Hibernate Annotations documentation example only works with not auto-generated id, if you try to use an auto incremental id, for example, </p>
<p>it&#8217;s impossible to persist the 2 tables at the same time.</p>
<p>Surfing on the net I&#8217;ve seen some ppl with this kind of problem (I suppose one-to-one relationships are not so common, don&#8217;t know why) and most of ppl use the foreign-key approach that works ok but it&#8217;s not clean from my point of view, so I wanted to find a solution for my case.</p>
<p>The original example from the Hibernate Annotations Documentation is:</p>
<p>@Entity<br />
public class Body {</p>
<p>    @Id<br />
    public Long getId() { return id; }</p>
<p>    @OneToOne(cascade = CascadeType.ALL)<br />
    @PrimaryKeyJoinColumn<br />
    public Heart getHeart() {<br />
        return heart;<br />
    }</p>
<p>    &#8230;</p>
<p>}</p>
<p> </p>
<p>@Entity<br />
public class Heart {</p>
<p>    @Id<br />
    public Long getId() { &#8230; }</p>
<p>}</p>
<p>As you can see this as not auto generated id and will not work just putting the <em>@GeneratedValue</em> annotation.</p>
<p>The final solution is:</p>
<p>@Entity<br />
public class Body {</p>
<p>    @Id<br />
    <strong>@GeneratedValue(strategy = IDENTITY)</strong><br />
    public Long getId() { return id; }</p>
<p>    @OneToOne(cascade = CascadeType.ALL)<br />
    @PrimaryKeyJoinColumn<br />
    public Heart getHeart() {<br />
        return heart;<br />
    }</p>
<p>    &#8230;</p>
<p>}</p>
<p>@Entity<br />
public class Heart {</p>
<p>    @Id<br />
<strong>    @GeneratedValue(generator=&#8221;foreign&#8221;) <br />
    @GenericGenerator(name=&#8221;foreign&#8221;, strategy = &#8220;foreign&#8221;, parameters = {@Parameter(name=&#8221;property&#8221;, value=&#8221;body&#8221;)})<br />
<span style="font-weight: normal; ">    public Long getId() { &#8230;}</span></strong></p>
<p><strong>    @OneToOne(mappedBy=&#8221;heart&#8221;)<br />
    public Body getBody() { &#8230; }</strong></p>
<p>}</p>
<div>Now all works fine for me.</div>
<div>Thanks</div>
<div>Demetrio</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.demetrio.it/2009/04/03/one-to-one-relationship-with-auto-generated-key-using-jpahibernate-using-annotations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hibernate hbm2java and generated BigDecimal from MySQL decimal(10,2) type</title>
		<link>http://blog.demetrio.it/2009/02/02/hibernate-hbm2java-and-generated-bigdecimal-from-mysql-decimal102-type/</link>
		<comments>http://blog.demetrio.it/2009/02/02/hibernate-hbm2java-and-generated-bigdecimal-from-mysql-decimal102-type/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 12:19:12 +0000</pubDate>
		<dc:creator>Demetrio Filocamo</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[java mysql seam jpa bigdecimal decimal hbm2java tips]]></category>

		<guid isPermaLink="false">http://blog.demetrio.it/?p=106</guid>
		<description><![CDATA[I had a little problem while working on a JBoss Seam project: I used the MySQL decimal(10,2) type for price value but, while running seam tests, the hbm2ddl schema validator gave me this error:
Caused by: org.hibernate.HibernateException: Wrong column type: shippingCost, expected: numeric(10,0)
[testng]     at org.hibernate.mapping.Table.validateColumns(Table.java:261)
[testng]     at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1083)
[testng]     at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:116)
[testng]     at org.hibernate.impl.SessionFactoryImpl.&#60;init&#62;(SessionFactoryImpl.java:317)
[testng]     [...]]]></description>
			<content:encoded><![CDATA[<p>I had a little problem while working on a JBoss Seam project: I used the MySQL decimal(10,2) type for price value but, while running seam tests, the hbm2ddl schema validator gave me this error:</p>
<p style="padding-left: 30px;">Caused by: org.hibernate.HibernateException: Wrong column type: shippingCost, expected: numeric(10,0)<br />
[testng]     at org.hibernate.mapping.Table.validateColumns(Table.java:261)<br />
[testng]     at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1083)<br />
[testng]     at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:116)<br />
[testng]     at org.hibernate.impl.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:317)<br />
[testng]     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)<br />
[testng]     at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:918)<br />
[testng]     at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:656)<br />
[testng]     &#8230; 68 more</p>
<p>The problem is that hbm2java usa a wrong column definition for the entity property, in fact the @Column annotation on the property was:</p>
<p style="padding-left: 30px;">@Column(name = &#8220;shippingCost&#8221;, nullable = false, precision = 10)</p>
<p>The solution is simple, just change it to:</p>
<p style="padding-left: 30px;">@Column(name = &#8220;shippingCost&#8221;, nullable = false, precision = 10<strong>, scale=2, columnDefinition=&#8221;decimal(10,2)&#8221;</strong>)</p>
<p>Now the type is correctly defined and the schema validator doesn&#8217;t return any error.</p>
<p>Demetrio</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.demetrio.it/2009/02/02/hibernate-hbm2java-and-generated-bigdecimal-from-mysql-decimal102-type/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
