<?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>JAVA How to</title>
	<atom:link href="http://www.javahowto.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javahowto.net</link>
	<description>JAVA Development tutorials and how to</description>
	<lastBuildDate>Tue, 24 Aug 2010 22:02:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>JavaZone Java 4-ever trailer</title>
		<link>http://www.javahowto.net/java-events/javazone-java-4-ever-trailer/</link>
		<comments>http://www.javahowto.net/java-events/javazone-java-4-ever-trailer/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 22:01:16 +0000</pubDate>
		<dc:creator>Oskar</dc:creator>
				<category><![CDATA[JAVA Events]]></category>
		<category><![CDATA[JAVA]]></category>
		<category><![CDATA[JavaZone]]></category>

		<guid isPermaLink="false">http://www.javahowto.net/?p=279</guid>
		<description><![CDATA[I readed a little bit about JavaZone that will be in September's 8-9th, but some days ago a friend shared me the link to "official" trailer of JavaZone, about a movie called "Java 4-Ever" that's so funny XD . Check the video . Source: http://jz10.java.no/java-4-ever-trailer.html]]></description>
			<content:encoded><![CDATA[<p>I readed a little bit about JavaZone that will be in September's 8-9th, but some days ago a friend shared me the link to "official" trailer of JavaZone, about a movie called "Java 4-Ever" that's so funny XD . Check the video <img src='http://www.javahowto.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  .<br />
<center><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="350" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.youtube.com/v/yl1f1-Da0OI" /><embed type="application/x-shockwave-flash" width="425" height="350" src="http://www.youtube.com/v/yl1f1-Da0OI"></embed></object></center><br />
<br />
Source: <a title="Java 4-Ever trailer - JavaZone" href="http://jz10.java.no/java-4-ever-trailer.html" target="_blank">http://jz10.java.no/java-4-ever-trailer.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.javahowto.net/java-events/javazone-java-4-ever-trailer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to monitor your Oracle DB (Part 2)</title>
		<link>http://www.javahowto.net/oracle/how-to-monitor-your-oracle-db-part-2/</link>
		<comments>http://www.javahowto.net/oracle/how-to-monitor-your-oracle-db-part-2/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 21:32:34 +0000</pubDate>
		<dc:creator>Oskar</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[connection]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[monitor]]></category>
		<category><![CDATA[oracle]]></category>

		<guid isPermaLink="false">http://www.javahowto.net/?p=266</guid>
		<description><![CDATA[Again, writting a little bit about Oracle administration. Imagine the next situation: Database sessions are INACTIVE after a while and doesn't dissapear neither close, what can we do? We can use Oracle profiles. Basically, a profile is a set of limits that you can establish for resources in a schema. For our problem, we need [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" title="Oracle - JAVA How to" src="http://www.javahowto.net/images/planeoracle.jpg" alt="Oracle - JAVA How to" />Again, writting a little bit about Oracle administration.</p>
<p>Imagine the next situation: Database sessions are INACTIVE after a while and doesn't dissapear neither close, what can we do? We can use Oracle profiles. Basically, a profile is a set of limits that you can establish for resources in a schema. For our problem, we need to establish a profile that allow us to kill the INACTIVE sessions after some amount of time to clean the stuff.</p>
<p>To create and define profiles you need to have ALTER SYSTEM privileges. First of all you need to tell Oracle that you're able to establish limits to some system resources, to do that you have to modify RESOURCE_LIMIT parameter in the next way:</p>
<pre class="brush: sql;">alter system set resource_limit=true;</pre>
<p>Next, we have to create the profile and set it to specified schema. The syntax to do that is the next:(Continue reading)<span id="more-266"></span></p>
<pre class="brush: sql;">CREATE PROFILE profileName LIMIT
RESOURCE_PARAMETER VALUE
RESOURCE_PARAMETER2 VALUE2
RESOURCE_PARAMETER3 VALUE3
...
;</pre>
<p>For example, if i wanna limit the max number of sessions in a schema to 100 and set the number of days that an account is locked when maxim failed login attempts to 6 days i create a profile like this:</p>
<pre class="brush: sql;">
CREATE PROFILE REALLYBAD_PROFILE
LIMIT PASSWORD_LOCK_TIME 6
SESSIONS_PER_USER  100;
</pre>
<p>In order to solve our situation (INACTIVE sessions) we have to create a profile like this (idle time is in minutes):</p>
<pre class="brush: sql;">create profile poorSessionsProfile
limit idle_time 10;</pre>
<p>After that, we have to set the profile to schema, to do this the syntax is the next:</p>
<pre class="brush: sql;">ALTER USER schemaName PROFILE nameOfProfileAlreadyDefined;</pre>
<p>To define our profile the statement is this:</p>
<pre class="brush: sql;">alter user WBK profile poorSessionsProfile;</pre>
<p>Solved!! If you want more information about profiles in Oracle, check this link:<br />
<strong><a href="http://download.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_6010.htm">http://download.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_6010.htm</a></strong></p>
<p>Another tip: What if you wanna know the database version? Just query the table V$VERSION that contains info like Oracle database version, PL/SQL version and more:</p>
<pre class="brush: sql;">SELECT * FROM v$version;
/*DATA*/
BANNER
-----------
Oracle9i Release 9.2.0.5.0 - Production
PL/SQL Release 9.2.0.5.0 - Production
&quot;CORE    9.2.0.3.0    Production&quot;
TNS for Linux: Version 9.2.0.5.0 - Production
NLSRTL Version 9.2.0.5.0 - Production
</pre>
<p>Enjoy it <img src='http://www.javahowto.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.javahowto.net/oracle/how-to-monitor-your-oracle-db-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to monitor your Oracle DB (Part 1)</title>
		<link>http://www.javahowto.net/oracle/how-to-monitor-your-oracle-db-part-1/</link>
		<comments>http://www.javahowto.net/oracle/how-to-monitor-your-oracle-db-part-1/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 14:56:21 +0000</pubDate>
		<dc:creator>Oskar</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[connection]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[monitor]]></category>
		<category><![CDATA[oracle]]></category>

		<guid isPermaLink="false">http://www.javahowto.net/?p=257</guid>
		<description><![CDATA[Sometimes, you are developing some application that connects to Oracle database and you need to monitor the database to know something about processes, open sessions/cursors and so on, so is necessary to know a little bit about Oracle administration. Basically, Oracle provides us with a set of fixed tables that allow us to check database [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="Oracle - JAVA How to" src="http://www.javahowto.net/images/ironmanoracle.jpg" alt="Oracle - JAVA How to" width="228" height="164" />Sometimes, you are developing some application that connects to Oracle database and you need to monitor the database to know something about processes, open sessions/cursors and so on, so is necessary to know a little bit about Oracle administration.</p>
<p>Basically, Oracle provides us with a set of fixed tables that allow us to check database settings, processes, parameters, open sessions and so on that gives us important information. Some of these tables are the next:</p>
<pre class="brush: sql;">
V$SESSION /*Allows us to see open sessions and details about them*/
V$DATABASE /*Show us database information*/
V$FIXED_TABLE /*IMPORTANT because this shows a list of all fixed tables, learn that and you can get access all*/
V$LOCKED_OBJECT /*Shows us locked objects on the database*/
V$SQLAREA /*Show sql queries executed related to v$session*/
</pre>
<p>You can check a list of those views in the next link:<br />
<strong><a title="Oracle's V$ Views" href="http://www.adp-gmbh.ch/ora/misc/dynamic_performance_views.html" target="_blank">http://www.adp-gmbh.ch/ora/misc/dynamic_performance_views.html</a></strong><br />
Now, how to use that information to do different stuff on the database?<br />
<br />
<span id="more-257"></span><strong>First situation: </strong>Suppose that you're developing an application and you want to checking out what's going on. You suppose that is something related to database. Well, in this case, whe are going to check the open sessions. To do that we can use the next query:</p>
<pre class="brush: sql;">
SELECT * FROM V$SESSION WHERE  MACHINE = 'MACHINE_NAME';
--OR TO BE MORE SPECIFIC, JUST THE COLUMNS THAT WE'RE INTERESTED
SELECT SID, SERIAL#,  command, SCHEMANAME, PROGRAM, MODULE, STATUS,
FROM V$SESSION WHERE MACHINE = 'MY_MACHINE' ORDER BY MODULE, status;
/*This show us something like this:*/
SID   SERIAL# COMMAND  SCHEMANAME    PROGRAM            MODULE          STATUS
-------------------------------------------------------------------------------
99    3436    3        WBK            SQL Developer    SQL Developer    ACTIVE
77    8968    0        WBK            SQL Developer    SQL Developer    SNIPED
39    7610    0        WBK            AppOne           AppOne           INACTIVE
136    301    0        WBK            AppOne           AppOne           INACTIVE
98    2574    0        WBK            AppOne           AppOne           SNIPED
47    7179    0        WBK            JAVAJob          JAVAJob          INACTIVE
78    8462    0        WBK            JAVAJob          JAVAJob          INACTIVE
</pre>
<p>Now you can see your connections (filtered by machine in case that more than one machine are connected to database) and see the connection status or the program that opened that session (in my case you can see SQL Developer that i use  to query database and other applications).</p>
<p>I wanna close some some of those sessions, what i have to do? To do that you have to kill the sessions. To do that you can use the next statement:</p>
<pre class="brush: sql;">
ALTER SYSTEM KILL SESSION 'SESSION NUMBER,SERIAL# NUMBER';
/*For example, if i wanna kill the ACTIVE session of my SQL Developer,
you can see that SID is 99 and SERIAL# is 3436, so the statement will look like this */
ALTER SYSTEM KILL SESSION '99,3436';
</pre>
<p>You can check more information about kill Oracle sessions here:<br />
<a title="Managing Oracle Sessions" href="http://download.oracle.com/docs/cd/B10501_01/server.920/a96521/manproc.htm#1960" target="_blank"><strong>http://download.oracle.com/docs/cd/B10501_01/server.920/a96521/manproc.htm#1960</strong></a><br />
<strong>Another situation: </strong>Let's suppose that you have a statement that takes a looong time to run or something like that, or a query that leaves inactive the session for any reason, or a procedure call that freezes. Well, in this case we have to see the last query that executed in session, so we use V$SQLAREA joining with V$SESSION using sql_address field, in the next way:</p>
<pre class="brush: sql;">
select a.sid, a.serial#, b.sql_text from v$session a, v$sqlarea b
where a.sql_address=b.address and a.MACHINE = 'MY_MACHINE';
/*You will see something like this*/
SID    SERIAL#    SQL_TEXT
---------------------------------
37    10446    select wbkopcione0_.IDOPC_PADRE as IDOPC9_1_, wbkopcione0_.IDOPC as IDOPC1_,...
39    7610     select wbkpermiso0_.IDUSROPC as IDUSROPC44_, wbkpermiso0_.ACCESOS as ...
75    404      BEGIN    LBACSYS.lbac_events.logon(dbms_standard.login_user);   END;
77    8968     BEGIN    LBACSYS.lbac_events.logon(dbms_standard.login_user);   END;
102   8890     BEGIN    LBACSYS.lbac_events.logon(dbms_standard.login_user);   END;
99    3436     select a.sid, a.serial#, b.sql_text from v$session a, v$sqlarea b ...
</pre>
<p>Now you can see the last query that was executed on the session. It's important to clarify that you need to have privileges over V$ fixed tables in order to query them and also ALTER SYSTEM privilege to kill sessions. There's a lot of stuff that you can do in Oracle administration side, so we are going to write another post talking about this. Right now, i hope that you enjoy this post and find useful <img src='http://www.javahowto.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.javahowto.net/oracle/how-to-monitor-your-oracle-db-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to set ARITHABORT from JAVA &#8211; SQL Server</title>
		<link>http://www.javahowto.net/jdbc/how-to-set-arithabort-from-java-sql-server/</link>
		<comments>http://www.javahowto.net/jdbc/how-to-set-arithabort-from-java-sql-server/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 17:04:59 +0000</pubDate>
		<dc:creator>Oskar</dc:creator>
				<category><![CDATA[JDBC]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[JAVA]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.javahowto.net/?p=252</guid>
		<description><![CDATA[I had a problem yesterday. I was developing a RESTful web service where i have to run an UPDATE to SQL Server 2005 table, but when i do that i have the next problem: UPDATE failed because the following SET options have incorrect settings: 'ARIHABORT' Damn! What the hell is that? Googling i found this: [...]]]></description>
			<content:encoded><![CDATA[<p>I had a problem yesterday. I was developing a RESTful web service where i have to run an UPDATE to SQL Server 2005 table, but when i do that i have the next problem:</p>
<pre class="brush: sql;">
UPDATE failed because the following SET options have incorrect settings: 'ARIHABORT'
</pre>
<p>Damn! What the hell is that? Googling i found this:</p>
<p><strong><a title="INSERT failed because the following SET options have incorrect settings: 'ARITHABORT'" href="http://j2eeframeworks.blogspot.com/2008/10/insert-failed-because-following-set.html">http://j2eeframeworks.blogspot.com/2008/10/insert-failed-because-following-set.html</a></strong></p>
<p>And i understood that the table that i want to update is related to indexed views so the UPDATE or INSERT proccess isn't as simple because i had to set the parameter ARIHABORT = ON to do my operations.</p>
<p>So, how to do that?<span id="more-252"></span> Whe need to execute the next statement:</p>
<pre class="brush: sql;">
SET ARIHABORT ON;
</pre>
<p>From JAVA. As you can see in the link, the guy recommends to execute the statement using Statement object, like the next code:</p>
<pre class="brush: java;">
 Connection sqlsConn = myManager.getSQLSConnection();
 Statement stmt = sqlsConn.createStatement();
 stmt.execute(&quot;SET ARITHABORT ON&quot;);
</pre>
<p>And that's it!! <img src='http://www.javahowto.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  . An important advice is that, if you use PreparedStatement or something like that, it doesn't work!! I throws an exception.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javahowto.net/jdbc/how-to-set-arithabort-from-java-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use ModelDriven in Struts 2</title>
		<link>http://www.javahowto.net/struts2/how-to-use-modeldriven-in-struts-2/</link>
		<comments>http://www.javahowto.net/struts2/how-to-use-modeldriven-in-struts-2/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 22:52:47 +0000</pubDate>
		<dc:creator>Oskar</dc:creator>
				<category><![CDATA[Struts2]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Howto]]></category>

		<guid isPermaLink="false">http://www.javahowto.net/?p=219</guid>
		<description><![CDATA[Talking about Struts 2 again . I wanna talk (or write) about this because is very interesting, for me it remembers me the way of work on Struts 1. For those that doesn't know what am i talking about, i'm going to explain you. In Struts 1, the way of work with Action and form [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="aligncenter" style="display:block" title="Struts 2 Logo" src="http://mohamadsubhan.files.wordpress.com/2009/06/struts2.jpg" alt="Struts 2 Logo" width="257" height="135" /></p>
<p>Talking about Struts 2 again <img src='http://www.javahowto.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  . I wanna talk (or write) about this because is very interesting, for me it remembers me the way of work on Struts 1. For those that doesn't know what am i talking about, i'm going to explain you. In Struts 1, the way of work with Action and form properties is a little bit different of default Struts 2 way. In struts 1 we have the actions that doesn't contain any form property or getter/setter method, like this:</p>
<pre class="brush: java;">
import....
public class LoginAction extends LookupDispatchAction {
    public ActionForward logMeIn(HttpServletRequest request,
            HttpServletResponse response,
            ActionMapping mapping,
            ActionForm form) {
        LoginForm loginForm = (LoginForm) form;
        if (loginForm.getUsername().equals(&quot;admin&quot;) &amp;&amp;
                loginForm.getPassword().equals(&quot;admin&quot;)) {
            return mapping.findForward(&quot;enter&quot;);
        } else {
            return mapping.findForward(&quot;fail&quot;);
        }
    }
}
</pre>
<p>And, in other class, the Action Form where we can find the properties with respective getter/setter methods and optionally, struts 1 server side validation:</p>
<p>But, in Struts 2 it changes a little bit because properties, getter/setter methods and validation are in the action. For the previous example, it's version on Struts 2 will look like this:</p>
<pre class="brush: java;">
public class LoginAction {
        private String username;
        private String password;

        public void setUsername(String username) {
            this.username = username;
        }

        public String getUsername() {
            return username;
        }

        public void setPassword(String password) {
            this.password = password;
        }

        public String getPassword() {
            return password;
        }

        public String logMeIn() {
        if (getUsername().equals(&quot;admin&quot;) &amp;&amp;
                getPassword().equals(&quot;admin&quot;)) {
            return &quot;enter&quot;;
        } else {
            return &quot;fail&quot;;
        }
}
</pre>
<p>Free from extends and strange return types in methods but more charged with properties and getter/setter methods, for some people it's better, for another people it sucks. In my case i like the fact that i don´t need to extend my actions from some classes (altought you have to do that if you want to inject additional funcionality to your action like validation, prepare scripts and so on) and a simpler way to declare action methods, but i dislike the fact that all is inside the action.</p>
<p>But don't worry people, Struts 1 developer that migrated to Struts 2 can still use the same model Action - Action Form like Struts 1 in struts 2  <img src='http://www.javahowto.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  , how to do that?<span id="more-219"></span></p>
<p>First, your action must implement ModelDriven interface  and your interceptor stack must include ModelDrivenInterceptor, that is already included in default stack. This will allow to Struts 2 engine to fill a pojo with the data of a form or something like that instead fill the fields of the action. Following with the same example, our Struts 2 action will look like this:</p>
<pre class="brush: java;">
public class LoginAction {
    private User user;

    public Object getModel() {
        return user;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String logMeIn() {
    if (user.getUsername().equals(&quot;admin&quot;) &amp;&amp;
            user.getPassword().equals(&quot;admin&quot;)) {
        return &quot;enter&quot;;
    } else {
        return &quot;fail&quot;;
    }
}
</pre>
<p>Now our action is free of anoying properties and those are in a separate class named User.java:</p>
<pre class="brush: java;">
public class User {
    private String username;
    private String password;

    public void setUsername(String username) {
        this.username = username;
    }

    public String getUsername() {
        return username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPassword() {
        return password;
    }
}
</pre>
<p>In the front-end side, you don't have to alter any. What i'm talking about? For example, a textfield will look like this:</p>
<pre class="brush: java;">
&lt;s:textfield name=&quot;username&quot; id=&quot;username&quot; /&gt;
</pre>
<p>And that's it!! Enjoy it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javahowto.net/struts2/how-to-use-modeldriven-in-struts-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to validate through annotations: Struts 2</title>
		<link>http://www.javahowto.net/struts2/how-to-validate-through-annotations-struts-2/</link>
		<comments>http://www.javahowto.net/struts2/how-to-validate-through-annotations-struts-2/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 22:09:26 +0000</pubDate>
		<dc:creator>Oskar</dc:creator>
				<category><![CDATA[Struts2]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[JAVA]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://www.javahowto.net/?p=215</guid>
		<description><![CDATA[Hi to all. I've studied some stuff about struts 2 those days so i've learn a lot of new things like this post topic. Normally, what do you do when you want to implement a basic validation on Struts 2? The steps about how to do that are: Assure that you're using defaultStack interceptor stack [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="aligncenter" style="display: block;" title="Struts 2 validation - JAVA How to" src="http://www.javahowto.net/images/validateStruts.gif" alt="Struts 2 validation - JAVA How to" /></p>
<p>Hi to all. I've studied some stuff about struts 2 those days so i've learn a lot of new things like this post topic. Normally, what do you do when you want to implement a basic validation on Struts 2? The steps about how to do that are:</p>
<ul>
<li>Assure that you're using defaultStack interceptor stack because inside it are workflow and validation interceptors that are responsible of execute validation logic and redirect to appropiate result when validation triggers.</li>
<li>Define a result named "input" in action's declaration on struts.xml . This is the result where validation must redirect automatically if exists validation errors. If input result is not defined it will give an error of result not found.</li>
<li>Override validate() method on your action.</li>
<li>Write your own validation logic inside it, that must add error messages when it fails to properly validation mechanism. For example, if i validate that a field must be a number and greater than 1000, if it doesn't pass the validation it must add a error message using addActionError() or addFieldError() (To follow standards you should use addFieldError() ), like this:
<pre>if (fieldOne == null || fieldOne.equals("")) {
 addFieldError("fieldOne", "Field one must not be empty.");
 }
 if (fieldTwo == null || Integer.valueOf(fieldTwo) &lt; 30) {
 addFieldError("fieldTwo", "Field two must be greater or equal than 30.");
 }</pre>
</li>
<li>(Optional) in your jsp you can define &lt;s:fielderror&gt; or &lt;s:actionerror&gt; tags to print your validation messages. As you can guess, &lt;s:fielderror&gt; prints validation errors added with addFieldError() and &lt;s:actionerror&gt; to print action error messages added with addActionError(). To print validation errors from fieldOne and fieldTwo you have to define &lt;s:fielderror&gt; like this:
<pre>&lt;s:fielderror cssClass="cssClassForUllistwithLi" &gt;
 &lt;s:param&gt;fieldOne&lt;/s:param&gt;
 &lt;s:param&gt;fieldTwo&lt;/s:param&gt;
 &lt;/s:fielderror&gt;</pre>
</li>
<li>Run your app <img src='http://www.javahowto.net/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </li>
</ul>
<p>This is the basic way. But if you want to validate through annotations is easier and faster, you have to do this:<span id="more-215"></span></p>
<ul>
<li>The first three bullets from previous list.</li>
<li>One line before getter method of field that you want to validate, you can use one of the next annotations depending of the kind of validation that you wanna do:
<ul>
<li><strong><a title="class in com.opensymphony.xwork2.validator.validators" href="http://struts.apache.org/2.0.6/struts2-core/apidocs/com/opensymphony/xwork2/validator/validators/RequiredStringValidator.html">RequiredStringValidator</a></strong></li>
<li><strong><a title="class in com.opensymphony.xwork2.validator.validators" href="http://struts.apache.org/2.0.6/struts2-core/apidocs/com/opensymphony/xwork2/validator/validators/RequiredFieldValidator.html">RequiredFieldValidator</a></strong></li>
<li><strong><a title="class in com.opensymphony.xwork2.validator.validators" href="http://struts.apache.org/2.0.6/struts2-core/apidocs/com/opensymphony/xwork2/validator/validators/EmailValidator.html">EmailValidator</a></strong></li>
<li><strong>.... </strong>You can see the list of validation annotations avaliable<strong> &gt;&gt;&gt; <a title="Struts 2 validation annotations - JAVA How To" href="http://struts.apache.org/2.1.8/struts2-core/apidocs/com/opensymphony/xwork2/validator/validators/package-summary.html" target="_blank">HERE IN JAVADOC</a>&lt;&lt;&lt;</strong></li>
</ul>
</li>
<li>Define the message parameter of annotation, that is like you write addFieldError("fieldOne", "Field one must not be empty") . We can convert our previous example to annotations and it will look like this:
<pre>public void validate() {}

@RequiredStringValidator(message="Field one must not be empty.")
public String getFieldOne() {...

@IntRangeFieldValidator(message="Field two must be greater or equal than 30.", min="30")
public String getFieldTwo() {...</pre>
</li>
</ul>
<p>That's it!! Even when annotations-way looks better than default validation definition, in some cases is better to do in the default way and in other cases using annotations, none is better than the other. Enjoy it <img src='http://www.javahowto.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javahowto.net/struts2/how-to-validate-through-annotations-struts-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to avoid validation on Action call &#8211; Struts 2</title>
		<link>http://www.javahowto.net/struts2/how-to-avoid-validation-on-action-call-struts-2/</link>
		<comments>http://www.javahowto.net/struts2/how-to-avoid-validation-on-action-call-struts-2/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 16:33:58 +0000</pubDate>
		<dc:creator>Oskar</dc:creator>
				<category><![CDATA[Struts2]]></category>
		<category><![CDATA[annotation]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[JAVA]]></category>

		<guid isPermaLink="false">http://www.javahowto.net/?p=207</guid>
		<description><![CDATA[As you know, like Struts 1, Struts 2 allow us to define server side validations when you call an action. This is very useful because sometimes javascript client side validation is not enought when we want to validate input entries against data from DB or do complex validations. How to define validations in JAVA Struts 2? [...]]]></description>
			<content:encoded><![CDATA[<p>As you know, like Struts 1, Struts 2 allow us to define server side validations when you call an action. This is very useful because sometimes javascript client side validation is not enought when we want to validate input entries against data from DB or do complex validations.</p>
<p>How to define validations in JAVA Struts 2? First your action must extend ActionSupport class, and override it's method validate that has te following signature:</p>
<pre>public void validate() {}</pre>
<p>Inside validate() you define your validations and, if you add messages to ActionErrors or FieldErrors, Struts 2 automatically detects that it must redirect to input result defined in action's declaration in struts.xml, like this:</p>
<pre> &lt;action name="login"&gt;
            &lt;interceptor-ref name="defaultStack" /&gt;

            &lt;result name="homePage"&gt;/login/login.jsp&lt;/result&gt;
            <strong>&lt;result name="input"&gt;/login/login.jsp&lt;/result&gt;
</strong>...
            &lt;result name="backToLoginPer"&gt;/login/login.jsp&lt;/result&gt;
        &lt;/action&gt;</pre>
<p>The problem is that sometimes you want that validation applies only on certain action calls, that is, avoid validation on certain action calls. How to do this?<span id="more-207"></span></p>
<p>There are 2 ways to do that: Through xml configuration and annotations.</p>
<p><strong>XML Configuration:</strong> This is defined in action's declaration in struts.xml. You have to use defaultStack interceptor stack because it provides <strong><a title="AnnotationValidationInterceptor" href="http://struts.apache.org/2.0.11/struts2-core/apidocs/org/apache/struts2/interceptor/validation/AnnotationValidationInterceptor.html" target="_blank">AnnotationValidationInterceptor</a></strong> a.k.a. validation and <strong><a title="DefaultWorkflowInterceptor" href="http://struts.apache.org/2.1.2/struts2-core/apidocs/com/opensymphony/xwork2/interceptor/DefaultWorkflowInterceptor.html" target="_blank">DefaultWorkflowInterceptor</a></strong> a.k.a. workflow that both handles validation and redirection when you use validation. Both can receive a parameter that indicates the methods that you don't want to be validated. In this example i have an action that i use to handle login actions like log in, log out, and so on. The common behavior is to validate login form to avoid get an empty user and password, so i define a validation like this in mi login action:</p>
<pre>@Override
    public void validate() {
        if (getCodusr().trim().length() == 0) {
            addFieldError("codusr", "You must have to enter a user code");
        }
        if (getClave().trim().length() == 0) {
            addFieldError("clave", "You must have to enter a password");
        }
    }</pre>
<p>But, i have the method of logout(), but i don't wanna validation when i call it because i just wannt destroy session and redirect user out of application, so i have to pass it as parameter to the two interceptors (workflow and validate) to avoid to execute validate() when i call logout(), so i define my action in this way:</p>
<pre>&lt;action name="login"&gt;
            &lt;interceptor-ref name="defaultStack" &gt;
                &lt;param name="workflow.excludeMethods"&gt;homePage,logout&lt;/param&gt;
                &lt;param name="validation.excludeMethods"&gt;homePage,logout&lt;/param&gt;
            &lt;/interceptor-ref&gt;
            &lt;result name="homePage"&gt;/login/login.jsp&lt;/result&gt;
            &lt;result name="input"&gt;/login/login.jsp&lt;/result&gt;

            &lt;result name="backToLogin" type="redirectAction"&gt;login!homePage.action&lt;/result&gt;

        &lt;/action&gt;</pre>
<p>As you can see, when i set this i say "Please guys (workflow and validation) don't execute validation when i call homePage() or logout()!!".</p>
<p><strong>Annotations:</strong> Second way (and easiest for me) is to specify methods that skip validation through annotations. To do that simply use <a title="SkipValidation annotation" href="http://struts.apache.org/2.1.2/struts2-core/apidocs/org/apache/struts2/interceptor/validation/SkipValidation.html" target="_blank"><strong>org.apache.struts2.interceptor.validation.SkipValidation</strong></a> annotation, that does the same that i did on struts.xml but a loot more simple. So, to replicate the same that i did in struts.xml i simply do this:</p>
<pre> ...//More code
 import org.apache.struts2.interceptor.validation.SkipValidation;
 ...//More code
 @SkipValidation
 public String logout() {
      //Method logic
      return "someResult";
 }

 @SkipValidation
 public String homePage() {
      //Method logic
      return "someResult";
 }
 ... //More code</pre>
<p>And that's it. Personally i prefeer the second way (Annotations), but that's a choice of each one. Enjoy it!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javahowto.net/struts2/how-to-avoid-validation-on-action-call-struts-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>JAVA Singleton Pattern</title>
		<link>http://www.javahowto.net/pattern-design/java-singleton-pattern/</link>
		<comments>http://www.javahowto.net/pattern-design/java-singleton-pattern/#comments</comments>
		<pubDate>Mon, 03 May 2010 04:20:13 +0000</pubDate>
		<dc:creator>Oskar</dc:creator>
				<category><![CDATA[Pattern design]]></category>
		<category><![CDATA[JAVA]]></category>
		<category><![CDATA[Pattern]]></category>
		<category><![CDATA[singleton]]></category>

		<guid isPermaLink="false">http://www.javahowto.net/?p=197</guid>
		<description><![CDATA[Hello again, after 3 weeks of posts absense, i'm back . Back with JAVA design patterns stuff, this time about How to apply Singleton Pattern, basically a pattern that allows you to restrict to instantiate more than one instance of a class in your application. The requirements that you satisfy with Singleton Pattern are: Only [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="aligncenter" style="vertical-align: middle; display: block;" title="Singleton Pattern - JAVA How to" src="http://www.javahowto.net/images/singletonPattern.jpg" alt="Singleton Pattern - JAVA How to" width="192" height="271" /></p>
<p>Hello again, after 3 weeks of posts absense, i'm back  <img src='http://www.javahowto.net/wp-includes/images/smilies/icon_cool.gif' alt='8-)' class='wp-smiley' /> . Back with JAVA design patterns stuff, this time about How to apply Singleton Pattern, basically a pattern that allows you to restrict to instantiate more than one instance of a class in your application. The requirements that you satisfy with Singleton Pattern are:</p>
<ul>
<li>Only one instance of a class per application</li>
<li>If you try to instantiate a second object from singleton class, you'll get the original instance</li>
</ul>
<p>I decided to write about it because i had a requirement in a project where i'm working right now that involves to handle an object to mantain the user state and other data in a single object, without possibility of instantiate another one and access easily to current object, so i decided to implement the pattern. First, you need to restrict the constructor of the class to avoid to instantiate object in the usual way so we have to declare the constructor as private. next you have to declare a method that, if an object isn't created yet, instantiate a new object and returns it, or, if object is already created, return a reference to that object...<span id="more-197"></span></p>
<p>To do that you have to mantain the state (object's instantiated or not) and an object's reference in the class. Let's code. Suppose that you have my requirement about the user data, so create a class named UserData like this:</p>
<pre>public class UserData
 {
 private String codUsr;
 private String status;
 private UserData userData;

 private UserData() {}

 static UserData getUserData() {
 if(userData == null)
 userData = new UserData();

 return userData;
 }

 public void setCodUsr(String codUsr) {
 this.codUsr = codUsr;
 }

 public void setStatus(String status) {
 this.status = status;
 }

 public void getCodUsr() {
 return this.codUsr;
 }

 public void getStatus() {
 return this.status;
 }
 }</pre>
<p>As you can see, we have the basics:</p>
<ul>
<li>Properties</li>
<li>Accessors and Mutators following JavaBeans conventions</li>
</ul>
<p>But, you can see something different:</p>
<ul>
<li>private property the same type as class: Is used to mantain a reference to the single object that is instantiated.</li>
<li>private constructor: To avoid external code to instantiate objects in the normal way</li>
<li>static method with return type as the class: This method is the heart of singleton class, because if instance isn't created, instantiates a new object and assigns the reference to class property, and finally returns the class field.</li>
</ul>
<p>This is a simple singleton pattern implementation because could be more complex implementation that involves singleton subclasses or something like that, but this is a good beginning. I also recommend that you read the book of patterns desing of Gang of fours. Enjoy it, and if you want the source code of UserData class, you can download it <strong><a title="UserData class - JAVA How To" href="http://javahowto.net/descargas/UserData.java" target="_blank">&gt;&gt;HERE&lt;&lt;</a></strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javahowto.net/pattern-design/java-singleton-pattern/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SCJP 6: Done!!</title>
		<link>http://www.javahowto.net/scjp/scjp-6-done/</link>
		<comments>http://www.javahowto.net/scjp/scjp-6-done/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 14:36:32 +0000</pubDate>
		<dc:creator>Oskar</dc:creator>
				<category><![CDATA[SCJP]]></category>
		<category><![CDATA[JavaRanch]]></category>

		<guid isPermaLink="false">http://www.javahowto.net/?p=193</guid>
		<description><![CDATA[Hi to all, and sorry for post absence. Those last weeks i've been working in some projects and studying for SCJP exam that i re-scheduled to past saturday. Fortunately, i've passed the exam with 85% woohoo . God helped me with the exam giving me the intelligence to remember JAVA programming rules about OOP, Threads, [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="aligncenter" style="display: block;" title="SCJP Official Logo" src="http://javahowto.net/images/scjpLogo.jpg" alt="SCJP Official Logo" width="277" height="185" /></p>
<p>Hi to all, and sorry for post absence. Those last weeks i've been working in some projects and studying for SCJP exam that i re-scheduled to past saturday. Fortunately, i've passed the exam with 85% <img src='http://www.javahowto.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  woohoo . God helped me with the exam giving me the intelligence to remember JAVA programming rules about OOP, Threads, serialization, inner classes, and soo on. So i feel very well, taking easy those days (is something like a "vacation") and thinking about next certification. I have a dilemma: I don't know if study for:</p>
<ul>
<li>SCBCD - Sun Certified Business Component Developer (EJB) or</li>
<li>SCDJWS - Sun Certified Developer for Java Web Services (web services)</li>
</ul>
<p>Because i don't know anything or a little bit (in web services) but both technologies are very interesting. Actually i been working with RESTful web services and i like to complement that with EJB 3 but unfortunately current SCBCD is about EJB 2 so i haven't take my desicion yet. But doesn't matter, i wanna rest some days (5 maximum XD) and after that start to sdudying something.</p>
<p>Also i can say that Big Moose Salon Forums helped me a lot. In that forum i found a page with links to mock exams that are very useful to practice after study some topic, and the forum to search my doubts or publish them to receive an answer from most experimented forum members.</p>
<p>Also i going to share some key topics of SCJP in future posts, so keep reading us!!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javahowto.net/scjp/scjp-6-done/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to solve &#8220;cannot find javac&#8221; with JAVA SDK App Engine</title>
		<link>http://www.javahowto.net/google-app-engine/how-to-solve-cannot-find-javac-with-java-sdk-app-engine/</link>
		<comments>http://www.javahowto.net/google-app-engine/how-to-solve-cannot-find-javac-with-java-sdk-app-engine/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 20:59:18 +0000</pubDate>
		<dc:creator>Oskar</dc:creator>
				<category><![CDATA[Google App Engine]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Howto]]></category>
		<category><![CDATA[JAVA]]></category>

		<guid isPermaLink="false">http://www.javahowto.net/?p=187</guid>
		<description><![CDATA[Recently i decided to try Google App Engine, a service where you can host your applications built in different languages like JAVA, Ruby, Python and so on, using Google's infraestructure. Now is enough for me because i see that you can get this for free: 500MB storage Enough CPU and bandwidth to serve your applications [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="aligncenter" style="display: block;" title="Google App Engine Logo - JAVA How to" src="http://www.javahowto.net/images/googleAppEngine.jpeg" alt="Google App Engine Logo - JAVA How to" /></p>
<p>Recently i decided to try Google App Engine, a service where you can host your applications built in different languages like JAVA, Ruby, Python and so on, using Google's infraestructure. Now is enough for me because i see that you can get this for free:</p>
<ul>
<li>500MB storage</li>
<li>Enough CPU and bandwidth to serve your applications to 5 million visits per month</li>
</ul>
<p>So i want to test what kind of JAVA technologies it supports (I don't know, Struts2, Spring, Hibernate JPA) . The proccess to join this is very simple, the steps are the next:<span id="more-187"></span></p>
<ul>
<li>Go to <strong><a title="Google App Engine" href="http://code.google.com/intl/en-US/appengine/" target="_blank">Google App Engine official site</a></strong> and sign in (with gmail account)</li>
<li>Download the App Engine SDK <a title="Google App Engine - App Engine SDK" href="http://code.google.com/appengine/downloads.html" target="_blank"><strong>HERE</strong></a> that you will use to upload your applications and more</li>
<li>Read the <a title="Google App Engine - Getting Started" href="http://code.google.com/appengine/docs/python/gettingstarted/" target="_blank"><strong>Getting Started Guide</strong></a></li>
</ul>
<p>Well, i suppose that you've read the docs, build your application and you're ready to upload it. The first time that i tried to upload it i get the next error (Click to enlarge):</p>
<p style="text-align: center;"><a href="http://www.javahowto.net/images/badUploadGAE.jpg"><img class="aligncenter" style="display: block;" title="Bad upload App Engine - JAVA How to" src="http://www.javahowto.net/images/badUploadGAE.jpg" alt="Bad upload App Engine - JAVA How to" width="482" height="139" /></a></p>
<p>It says something like "cannot find javac executable based on java.home, tried bla bla bla" , well, i read that this happens when you install JRE and then install JDK, because JDK includes JRE. java.home is the home of JRE and is not an environment variable (you can see the differences between java.home and environment variable JAVA_HOME <a title="java.home vs JAVA_HOME - javahowto blogspot" href="http://javahowto.blogspot.com/2006/05/javahome-vs-javahome.html" target="_blank"><strong>HERE</strong></a>),  and i think that happens because before upload the application, it tries to compile the sources but it doesn't find javac.exe because JRE doesn't have compile tools. So, to solve it i read THIS in Google Groups and even when it doesn't work for the guy in the group it works for me. You have to modify appcfg.cmd or appcfg.sh if you're on Windows or Linux, modify this:</p>
<pre>@java -cp ... (Windows)
java -cp ... (Linux)</pre>
<p>To look like this:</p>
<pre>@"C:\Program Files\Java\jdk1.6.0_16\bin\java" -cp ... (Windows)
"/usr/lib/jvm/java-6-sun/bin/java" -cp ... (Linux)</pre>
<p>As you can see, you change java (that probably takes the value of java.home)  for the javac full path . I read that another solution is uninstall JRE and leave only JDK but i haven't tried that.</p>
<p>Now try again with AppCfg update your/application/path and see how your application is uploaded successfully (Click to enlarge):</p>
<p style="text-align: center;"><a href="http://www.javahowto.net/images/goodUploadGAE.jpg"><img class="aligncenter" style="display: block;" title="Good upload App Engine - JAVA How to" src="http://www.javahowto.net/images/goodUploadGAE.jpg" alt="Good upload App Engine - JAVA How to" width="512" height="282" /></a></p>
<p>You can see my application here (simple JSP with no servlets): <a title="JAVA How to" href="http://myjavahost.appspot.com/" target="_blank">http://myjavahost.appspot.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.javahowto.net/google-app-engine/how-to-solve-cannot-find-javac-with-java-sdk-app-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
