<?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>UKoom &#187; Struts2</title>
	<atom:link href="http://www.ukoom.com/tag/struts2/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ukoom.com</link>
	<description>Documentum, SharePoint, Alfresco, ECM...</description>
	<lastBuildDate>Tue, 25 Oct 2011 15:11:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Upload files by using Struts2</title>
		<link>http://www.ukoom.com/upload-files-by-using-struts2.htm</link>
		<comments>http://www.ukoom.com/upload-files-by-using-struts2.htm#comments</comments>
		<pubDate>Mon, 29 Dec 2008 07:23:04 +0000</pubDate>
		<dc:creator>ukoom</dc:creator>
				<category><![CDATA[Web MVC]]></category>
		<category><![CDATA[Struts2]]></category>

		<guid isPermaLink="false">http://www.ukoom.com/?p=365</guid>
		<description><![CDATA[The Struts 2 framework provides built-in support for processing file uploads that conform to RFC 1867, &#8220;Form-based File Upload in HTML&#8221;. When correctly configured the framework will pass uploaded file(s) into your Action class. Support for individual and multiple file uploads are provided. When a file is uploaded it will typically be stored in a [...]]]></description>
			<content:encoded><![CDATA[<p>The Struts 2 framework provides built-in support for processing file uploads that conform to <span class="nobr"><a title="Visit page outside Confluence" rel="nofollow" href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867<sup><img class="rendericon" src="http://cwiki.apache.org/confluence/images/icons/linkext7.gif" border="0" alt="" width="7" height="7" align="absmiddle" /></sup></a></span>, &#8220;Form-based File Upload in HTML&#8221;. When correctly configured the framework will pass uploaded file(s) into your Action class. Support for individual and multiple file uploads are provided. When a file is uploaded it will typically be stored in a temporary directory. Uploaded files should be processed or moved by your Action class to ensure the data is not lost. Be aware that servers may have a security policy in place that prohibits you from writing to directories other than the temporary directory and the directories that belong to your web application.</p>
<h2>Dependencies</h2>
<p>The Struts 2 framework leverages add-on libraries to handle the parsing of uploaded files. These libraries are not included in the Struts distribution, you must add them into your project. The libraries needed are:</p>
<table class="confluenceTable" border="0">
<tbody>
<tr>
<th class="confluenceTh"> Library</th>
<th class="confluenceTh"> URL</th>
<th class="confluenceTh"> Struts 2.0.x</th>
<th class="confluenceTh"> Struts 2.1.x</th>
</tr>
<tr>
<td class="confluenceTd">Commons-FileUpload</td>
<td class="confluenceTd"><span class="nobr"><a title="Visit page outside Confluence" rel="nofollow" href="http://commons.apache.org/fileupload/">http://commons.apache.org/fileupload/<sup><img class="rendericon" src="http://cwiki.apache.org/confluence/images/icons/linkext7.gif" border="0" alt="" width="7" height="7" align="absmiddle" /></sup></a></span></td>
<td class="confluenceTd">1.1.1</td>
<td class="confluenceTd">1.2.1</td>
</tr>
<tr>
<td class="confluenceTd">Commons-IO</td>
<td class="confluenceTd"><span class="nobr"><a title="Visit page outside Confluence" rel="nofollow" href="http://commons.apache.org/io/">http://commons.apache.org/io/<sup><img class="rendericon" src="http://cwiki.apache.org/confluence/images/icons/linkext7.gif" border="0" alt="" width="7" height="7" align="absmiddle" /></sup></a></span></td>
<td class="confluenceTd">1.0</td>
<td class="confluenceTd">1.3.2</td>
</tr>
</tbody>
</table>
<p>References:</p>
<p>http://www.struts2.org/ajax-file-upload-in-struts2-using-ajax-file-upload-plugin/</p>
<p>http://www.javaeye.com/problems/1818</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ukoom.com/upload-files-by-using-struts2.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interceptors of Struts 2</title>
		<link>http://www.ukoom.com/interceptors-of-struts-2.htm</link>
		<comments>http://www.ukoom.com/interceptors-of-struts-2.htm#comments</comments>
		<pubDate>Mon, 29 Dec 2008 07:18:38 +0000</pubDate>
		<dc:creator>ukoom</dc:creator>
				<category><![CDATA[Web MVC]]></category>
		<category><![CDATA[Struts2]]></category>

		<guid isPermaLink="false">http://www.ukoom.com/?p=362</guid>
		<description><![CDATA[Many Actions share common concerns. Some Actions need input validated. Other Actions may need a file upload to be pre-processed. Another Action might need protection from a double submit. Many Actions need drop-down lists and other controls pre-populated before the page displays. The framework makes it easy to share solutions to these concerns using an [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ukoom.com/wp-content/uploads/2008/12/action-lifecycle.png"><img class="alignnone size-medium wp-image-363" title="action-lifecycle" src="http://www.ukoom.com/wp-content/uploads/2008/12/action-lifecycle-300x201.png" alt="" width="300" height="201" /></a></p>
<p>Many Actions share common concerns. Some Actions need input validated. Other Actions may need a file upload to be pre-processed. Another Action might need protection from a double submit. Many Actions need drop-down lists and other controls pre-populated before the page displays.</p>
<p>The framework makes it easy to share solutions to these concerns using an &#8220;Interceptor&#8221; strategy. When you request a resource that maps to an &#8220;action&#8221;, the framework invokes the Action object. But, before the Action is executed, the invocation can be intercepted by another object. After the Action executes, the invocation could be intercepted again. Unsurprisingly, we call these objects &#8220;Interceptors.&#8221;</p>
<p>Interceptors can execute code before and after an Action is invoked. Most of the framework&#8217;s core functionality is implemented as Interceptors. Features like double-submit guards, type conversion, object population, validation, file upload, page preparation, and more, are all implemented with the help of Interceptors. Each and every Interceptor is pluggable, so you can decide exactly which features an Action needs to support.</p>
<p>Interceptors can be configured on a per-action basis. Your own custom Interceptors can be mixed-and-matched with the Interceptors bundled with the framework. Interceptors &#8220;set the stage&#8221; for the Action classes, doing much of the &#8220;heavy lifting&#8221; before the Action executes.</p>
<p>In some cases, an Interceptor might keep an Action from firing, because of a double-submit or because validation failed. Interceptors can also change the state of an Action before it executes.</p>
<p>The Interceptors are defined in a stack that specifies the execution order. In some cases, the order of the Interceptors on the stack can be very important.</p>
<p>References:</p>
<p>http://docs.huihoo.com/apache/struts/apache-struts-2-document/interceptors.html</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ukoom.com/interceptors-of-struts-2.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Formatting Dates and Numbers in Struts2</title>
		<link>http://www.ukoom.com/formatting-dates-and-numbers-in-struts2.htm</link>
		<comments>http://www.ukoom.com/formatting-dates-and-numbers-in-struts2.htm#comments</comments>
		<pubDate>Fri, 19 Dec 2008 00:32:13 +0000</pubDate>
		<dc:creator>ukoom</dc:creator>
				<category><![CDATA[Web MVC]]></category>
		<category><![CDATA[Struts2]]></category>

		<guid isPermaLink="false">http://www.ukoom.com/?p=324</guid>
		<description><![CDATA[Defining Formats Struts2 supports localization (l10n) aware formatting of dates, times and numbers very easily, utilizing Java&#8217;s built-in date formatting features. As seen in the Localization chapter, it is quite easy to define hierarchical resource bundles with Struts2, giving the developer the opportunity to define locale dependent message formats. This is the entry point to [...]]]></description>
			<content:encoded><![CDATA[<h2>Defining Formats</h2>
<p>Struts2 supports localization (l10n) aware formatting of dates, times and numbers very easily, utilizing Java&#8217;s built-in date formatting features.</p>
<p>As seen in the <a title="Localization" href="http://struts.apache.org/2.x/docs/localization.html">Localization</a> chapter, it is quite easy to define hierarchical resource bundles with Struts2, giving the developer the opportunity to define locale dependent message formats. This is the entry point to define the needed date, time and number formats. Your default properties could contain the following generic formats:</p>
<div class="code">
<div class="codeContent">
<pre class="code-java">format.time = {0,time}
format.number = {0,number,#0.0##}
format.percent = {0,number,##0.00'%'}
format.money = {0,number,\u00A4##0.00}</pre>
</div>
</div>
<p>An appropriate en_US format definition extension could look like this:</p>
<div class="code">
<div class="codeContent">
<pre class="code-java">format.date = {0,date,MM/dd/yy}</pre>
</div>
</div>
<p>In parallel, you could add the following to your de_DE bundle:</p>
<div class="code">
<div class="codeContent">
<pre class="code-java">format.date = {0,date,dd.MM.yyyy}</pre>
</div>
</div>
<p>Read more on how to define message formats in Sun&#8217;s Java API docs for <span class="nobr"><a title="Visit page outside Confluence" rel="nofollow" href="http://java.sun.com/j2se/1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat<sup><img class="rendericon" src="http://cwiki.apache.org/confluence/images/icons/linkext7.gif" border="0" alt="" width="7" height="7" align="absmiddle" /></sup></a></span>.</p>
<p>Now that we have our formats set up, it is quite easy to use them in our views.</p>
<h2><a name="FormattingDatesandNumbers-Formattingoutputusingthes:texttag"></a>Formatting output using the s:text tag</h2>
<p>Given you had a Float value myMoneyValue, accessible through the getter getMyMoneyValue in your action, the following code would print out localized representation of the value as a currency amount, using the format.money message format defined above with a <a title="text" href="http://struts.apache.org/2.x/docs/text.html">s:text</a> tag:</p>
<div class="code">
<div class="codeContent">
<pre class="code-java">&lt;s:text name=<span class="code-quote">"format.money"</span>&gt;
    &lt;s:param name=<span class="code-quote">"value"</span> value=<span class="code-quote">"myMoneyValue"</span>/&gt;

References:

http://struts.apache.org/2.x/docs/formatting-dates-and-numbers.html

&lt;/s:text&gt;</pre>
</div>
</div>
<p>The (first) parameter defines the value which is to replace the &#8217;0&#8242; placeholder in the defined message format.<br />
Another example, formatting a date value:</p>
<div class="code">
<div class="codeContent">
<pre class="code-java">&lt;s:text name=<span class="code-quote">"format.date"</span>&gt;&lt;s:param value=<span class="code-quote">"dueDate"</span>/&gt;&lt;/s:text&gt;</pre>
</div>
</div>
<table class="noteMacro" border="0" cellspacing="8" cellpadding="5" width="85%" align="center">
<colgroup>
<col width="24"></col>
<col></col>
</colgroup>
<tbody>
<tr>
<td valign="top"><img src="http://cwiki.apache.org/confluence/images/icons/emoticons/warning.gif" border="0" alt="" width="16" height="16" align="absmiddle" /></td>
<td>While the s:text tag is very useful to format numbers, date formatting has become a lot easier thanks to the <a title="date" href="http://struts.apache.org/2.x/docs/date.html">s:date</a> tag.</td>
</tr>
</tbody>
</table>
<h2><a name="FormattingDatesandNumbers-LocalizingformdatawithgetText"></a>Localizing form data with getText</h2>
<p>Placing a textfield in a form like this</p>
<div class="code">
<div class="codeContent">
<pre class="code-java">&lt;s:textfield key=<span class="code-quote">"orderItem.price"</span> /&gt;</pre>
</div>
</div>
<p>to input a number, one might have noticed that the number is always shown in the Java default number format. Not only that this is not &#8220;nice&#8221;, if you are in a non-en locale, it will also cause trouble when submitting the form since type conversion is locale aware. The solution is to again use the message formats as defined above, by using the getText Method of ActionSupport:</p>
<div class="code">
<div class="codeContent">
<pre class="code-java">&lt;s:textfield key=<span class="code-quote">"orderItem.price"</span> value=<span class="code-quote">"%{getText('format.number',{'orderItem.price'})}"</span> /&gt;</pre>
</div>
</div>
<p>This maps to the method signature getText( String key, Object[] params ) in ActionSupport.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ukoom.com/formatting-dates-and-numbers-in-struts2.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Accessing application, session, request objects in Struts2</title>
		<link>http://www.ukoom.com/accessing-application-session-request-objects-in-struts.htm</link>
		<comments>http://www.ukoom.com/accessing-application-session-request-objects-in-struts.htm#comments</comments>
		<pubDate>Fri, 19 Dec 2008 00:29:49 +0000</pubDate>
		<dc:creator>ukoom</dc:creator>
				<category><![CDATA[Web MVC]]></category>
		<category><![CDATA[Struts2]]></category>

		<guid isPermaLink="false">http://www.ukoom.com/?p=322</guid>
		<description><![CDATA[The framework provides several access helpers to access Session, Application, Request scopes. Accessing from Java All the JEE scope attribute maps can be accessed via ActionContext. Accessing servlet scopes Map attr = (Map) ActionContext.getContext().get("attr"); attr.put("myId",myProp); Map application = (Map) ActionContext.getContext().get("application"); application.put("myId",myProp); Map session = (Map) ActionContext.getContext().get("session"); session.put("myId", myProp); Map request = (Map) ActionContext.getContext().get("request"); request.put("myId",myProp); Do [...]]]></description>
			<content:encoded><![CDATA[<div class="pagecontent">
<div class="wiki-content">
<p>The framework provides several access helpers to access Session, Application, Request scopes.</p>
<h2><a name="Accessingapplication,session,requestobjects-AccessingfromJava"></a>Accessing from Java</h2>
<p>All the JEE scope attribute maps can be accessed via <tt>ActionContext</tt>.</p>
<div class="code">
<div class="codeHeader"><strong>Accessing servlet scopes</strong></div>
<div class="codeContent">
<pre class="code-java">Map attr = (Map) ActionContext.getContext().get(<span class="code-quote">"attr"</span>);
attr.put(<span class="code-quote">"myId"</span>,myProp);

Map application = (Map) ActionContext.getContext().get(<span class="code-quote">"application"</span>);
application.put(<span class="code-quote">"myId"</span>,myProp);

Map session = (Map) ActionContext.getContext().get(<span class="code-quote">"session"</span>);
session.put(<span class="code-quote">"myId"</span>, myProp);

Map request = (Map) ActionContext.getContext().get(<span class="code-quote">"request"</span>);
request.put(<span class="code-quote">"myId"</span>,myProp);</pre>
</div>
</div>
<table class="warningMacro" border="0" cellspacing="8" cellpadding="5" width="85%" align="center">
<colgroup>
<col width="24"></col>
<col></col>
</colgroup>
<tbody>
<tr>
<td valign="top"><img src="http://cwiki.apache.org/confluence/images/icons/emoticons/forbidden.gif" border="0" alt="" width="16" height="16" align="absmiddle" /></td>
<td>Do not use <tt>ActionContext.getContext()</tt> in the constructor of your Action class. The values may not be set up, and the call may return null for <tt>getSession()</tt>.</td>
</tr>
</tbody>
</table>
<p>We can also access the <tt>HttpServletRequest</tt> and <tt>HttpServletResponse</tt> objects themselves through <tt>ServletActionContext</tt>. In general this isn&#8217;t recommended as it will tie our action to the servlet specification.</p>
<div class="code">
<div class="codeHeader"><strong>Setting session attribute through session object</strong></div>
<div class="codeContent">
<pre class="code-java">ServletActionContext.getRequest().getSession().put(<span class="code-quote">"myId"</span>, myProp);</pre>
</div>
</div>
<p>Implementing <tt>ServletRequestAware</tt> or <tt>ServletResponseAware</tt>, combined with the <tt><a title="Servlet Config Interceptor" href="http://struts.apache.org/2.x/docs/servlet-config-interceptor.html">"servletConfig" interceptor</a></tt>, is an alternative way to access the request and response objects, with the same caveat.</p>
<h2><a name="Accessingapplication,session,requestobjects-Accessingfromtheview(JSP,FreeMarker,etc.)"></a>Accessing from the view (JSP, FreeMarker, etc.)</h2>
<p>Request and session attributes are accessed via OGNL using the <tt>#session</tt> and <tt>#request</tt> stack values.</p>
<p>The <tt>#attr</tt> stack value will search the <tt>javax.servlet.jsp.PageContext</tt> for the specified key. If the <tt>PageContext</tt> doean&#8217;t exist, it will search the request, session, and application scopes, in that order.</p>
<div class="code">
<div class="codeHeader"><strong>Accessing the Session or Request from a JSP</strong></div>
<div class="codeContent">
<pre class="code-java">&lt;s:property value=<span class="code-quote">"#session.myId"</span> /&gt;

&lt;s:property value=<span class="code-quote">"#request.myId"</span> /&gt;

&lt;s:property value=<span class="code-quote">"#attr.myId"</span> /&gt;

References:

http://struts.apache.org/2.x/docs/accessing-application-session-request-objects.html</pre>
</div>
</div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.ukoom.com/accessing-application-session-request-objects-in-struts.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

