<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5351168395533279816</id><updated>2024-11-01T03:35:27.951-07:00</updated><category term="Java"/><category term="eclipse"/><category term=".net"/><category term="Glassfish"/><category term="jQuery"/><category term="multithreading"/><category term="pet store"/><category term="JavaScript"/><category term="OpenSessionInView"/><category term="c#"/><category term="debug"/><category term="google maps"/><category term="hibernate"/><category term="jsf"/><category term="MySQL"/><category term="Oracle"/><category term="SQL"/><category term="WebSockets"/><category term="ajax"/><category term="android"/><category term="antivirus"/><category term="cow"/><category term="dojo"/><category term="garbage collection"/><category term="ideal software company"/><category term="maven"/><category term="scalability"/><category term="smartphone"/><category term="tomato"/><title type='text'>I.T. Go Home ....</title><subtitle type='html'>Simpler I.T. for simple people</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>26</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-2577396806808675222</id><published>2016-01-27T00:44:00.001-08:00</published><updated>2016-01-27T00:44:19.368-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Oracle"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><title type='text'>SQL - optimize peformance by limiting table full scans</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
There&#39;s an excellent article here about using the PIVOT/UNPIVOT keywords in Oracle to organize and report data:&lt;br /&gt;
&lt;a href=&quot;https://dzone.com/articles/impress-your-coworkers-by-using-sql-unpivot&quot; target=&quot;_blank&quot;&gt;https://dzone.com/articles/impress-your-coworkers-by-using-sql-unpivot&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
However, I think the most interesting message here is how to limit your full table scans and thus enhance the DB access performance. So, read on ! Thanks Lukas Eder for the great article !&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/2577396806808675222/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2016/01/sql-optimize-peformance-by-limiting.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/2577396806808675222'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/2577396806808675222'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2016/01/sql-optimize-peformance-by-limiting.html' title='SQL - optimize peformance by limiting table full scans'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-4332540713104246058</id><published>2014-07-05T08:17:00.002-07:00</published><updated>2014-07-05T08:22:36.302-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".net"/><category scheme="http://www.blogger.com/atom/ns#" term="garbage collection"/><title type='text'>Could you be .... the most beautiful bug in the world ....</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;script src=&quot;https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
That&#39;s right. I&#39;ve spent almost 3 weeks to fix a bug which has been haunting me all this time, but now it looks like the most &quot;beautiful&quot; I&#39;ve ever encountered.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2 style=&quot;text-align: justify;&quot;&gt;
The context&lt;/h2&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
We have an nUnit test for a medical streaming application that basically reads volumes (depicting body parts) from a disk, loads them in memory and them streams them to the rendering pipeline to be displayed on the screen.&lt;br /&gt;
The test consists of two parts:&lt;br /&gt;
1. initialization - where, among others, we force garbage collection, by calling GC.Collect(2)&lt;br /&gt;
2. the streaming itself, during which we perform some measurements; one of these is the number of generation 2 collections, which should stay on 0 for the whole duration of the streaming (we tolerate only generation 0 and 1 collections, but since generation 2 collections are expensive, we absolutely want to avoid them occurring during our streaming); let&#39;s call this measurement GC2; so we expect GC2 = 0&lt;br /&gt;
&lt;br /&gt;
The issue I faced was that suddenly GC2 was 1, so the test was failing because of that.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;h2&gt;
The approach&lt;/h2&gt;
First I used&amp;nbsp;&lt;a href=&quot;http://www.scitech.se/&quot; target=&quot;_blank&quot;&gt;.NET Memory Profiler 4.5&lt;/a&gt;&amp;nbsp;to analyze my nUnit test. But before doing that, I needed to run nUnit in process, because otherwise it was starting the&lt;i&gt; nunit-agent.exe &lt;/i&gt;process and then I was analyzing the wrong process. In order to run nUnit (version 2.6.2) in process, I changed the &lt;b&gt;nunit-x86.exe.config&lt;/b&gt; like this:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&amp;gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;lt;configuration&amp;gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;lt;startup useLegacyV2RuntimeActivationPolicy=&quot;true&quot;&amp;gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;lt;supportedRuntime version=&quot;v4.0.30319&quot; /&amp;gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;lt;/startup&amp;gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;lt;runtime&amp;gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;lt;legacyUnhandledExceptionPolicy enabled=&quot;1&quot; /&amp;gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;&lt;/i&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;lt;loadFromRemoteSources enabled=&quot;true&quot; /&amp;gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;lt;assemblyBinding xmlns=&quot;urn:schemas-microsoft-com:asm.v1&quot;&amp;gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;probing privatePath=&quot;lib;addins&quot; /&amp;gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/assemblyBinding&amp;gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;nbsp; &amp;lt;/runtime&amp;gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&amp;lt;/configuration&amp;gt;&lt;/i&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;configuration&gt;
  &lt;startup uselegacyv2runtimeactivationpolicy=&quot;true&quot;&gt;
    &lt;supportedruntime version=&quot;v4.0.30319&quot;&gt;
  &lt;/supportedruntime&gt;&lt;/startup&gt;
 
  &lt;runtime&gt;
    &lt;gcconcurrent enabled=&quot;true&quot;&gt;
    &lt;legacyunhandledexceptionpolicy enabled=&quot;1&quot;&gt;

    &lt;loadfromremotesources enabled=&quot;true&quot;&gt;
    
    &lt;assemblybinding xmlns=&quot;urn:schemas-microsoft-com:asm.v1&quot;&gt;
      &lt;probing privatepath=&quot;lib;addins&quot;&gt;
    &lt;/probing&gt;&lt;/assemblybinding&gt;
  &lt;/loadfromremotesources&gt;&lt;/legacyunhandledexceptionpolicy&gt;&lt;/gcconcurrent&gt;&lt;/runtime&gt;
&lt;/configuration&gt;

&lt;br /&gt;
With this in place, I could analyze the nunit-x86 process and noticed the garbage collection pattern as in the figure below:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5-M0EPXEtI2p-5q0ortGOF_Hl6KojFi3ns3d8TzU2w4Ns7GWOiSbPWbP4_XZhejoF5BXryFm2RBWCCMy3n-pyLN3d-7P0_OjZ4qeLkUfuEkPdLdqVQ5NpJRdDA0MeANQCgxVpSUhckEg/s1600/gc2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5-M0EPXEtI2p-5q0ortGOF_Hl6KojFi3ns3d8TzU2w4Ns7GWOiSbPWbP4_XZhejoF5BXryFm2RBWCCMy3n-pyLN3d-7P0_OjZ4qeLkUfuEkPdLdqVQ5NpJRdDA0MeANQCgxVpSUhckEg/s1600/gc2.png&quot; height=&quot;185&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
As I said, I knew that during the initialization phase we triggered several generation 2 collections and on top of those there was another one causing the test to fail. How to identify it ?&lt;br /&gt;
And then I&#39;ve got this simple idea: I measure the number of collections of gen 2 at the beginning of the streaming (after all initialization has taken place) and then, for each sample streamed during the test, I count the number of gen 2 collections again and if it increased, I produce a beep:&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;
g2 = GC.CollectionCount(2);
....
if (GC.CollectionCount(2) - g2 &amp;gt; 0) {
    Console.Beep(500, 200);
}
&lt;/span&gt;&lt;/pre&gt;
&lt;br /&gt;
Yes, a simple beep would tell me when the extra gen 2 collection was produced.&lt;br /&gt;
With this simple approach, I analyzed the test by taking snapshots of memory immediately before and after the beep. Namely, I&#39;ve used the following tools:&lt;br /&gt;
&lt;i&gt;- .NET Memory Profiler 4.5&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;- CLRProfiler&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;- ANTS&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;- WinDbg&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;- PerfView &lt;/i&gt;(with this one I could inspect memory dumps that I generated from the code)&lt;br /&gt;
&lt;br /&gt;
All these tools showed me the same thing: there was no suspicious garbage that could have triggered a new gen 2 collection. So what was causing this extra collection after all ?&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
The other approach - back to basics&lt;/h2&gt;
After many hours of investigating where could the garbage come from and not being able to find anything, I decided to get back to basics: I started the good, old &lt;i&gt;perfmon &lt;/i&gt;and then it struck me - I noticed the &quot;# Induced GC&quot; counter under &quot;.NET CLR Memory&quot; category and I though let&#39;s give it a try.&lt;br /&gt;
I ran &lt;i&gt;nunit &lt;/i&gt;under &lt;i&gt;perfmon &lt;/i&gt;and when I heard the &quot;beep&quot; (see above), I also saw the &quot;Induced GC&quot; growing by one. So that was it ! The &lt;i&gt;generation 2 collection was induced&lt;/i&gt;, it wasn&#39;t due to any extra garbage.&lt;br /&gt;
The next step was to find out who induced it. For this I used&amp;nbsp;&lt;a href=&quot;http://www.jetbrains.com/profiler/&quot; target=&quot;_blank&quot;&gt;JetBrains dotTrace Performance 5.3.1&lt;/a&gt;&amp;nbsp;and this is what I&#39;ve discovered:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhorlqZM-hGDnEGLXMbXFUjdXiOFU8fvd5ZzL3zZNjg1uAKql08fQy8uP8c2aGaOzDajpEnhdtm7-RljEgz6IXwr_enRFwQKsZb-mQq5GpQ9xzmzW3Je0D1IXBMkEolTFltdSLDnYTDhwg/s1600/gc2_induced.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhorlqZM-hGDnEGLXMbXFUjdXiOFU8fvd5ZzL3zZNjg1uAKql08fQy8uP8c2aGaOzDajpEnhdtm7-RljEgz6IXwr_enRFwQKsZb-mQq5GpQ9xzmzW3Je0D1IXBMkEolTFltdSLDnYTDhwg/s1600/gc2_induced.png&quot; height=&quot;115&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Thus, the induced gen 2 collection is called from Microsoft code, namely from a GDI Bitmap method.&lt;br /&gt;
This discovery finally led me to the solution for my bug, but I&#39;ll spare you the details ....&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
Conclusion&lt;/h2&gt;
From the very beginning, I&#39;ve been put on the wrong foot. I was trying to look for any suspicious garbage that would trigger my gen 2 collection, but I couldn&#39;t find any. I used many tools and I spent a lot of time to analyze this, without finding anything. Because there was nothing to find. My gen 2 collection was induced, i.e. forced by Microsoft code.&lt;br /&gt;
Getting back to basics proved to lead me to the solution: simple tools like &lt;i&gt;perfmon &lt;/i&gt;can&#39;t be ignored. Actually, you should start with this, be it for the fact that you might find some hints. Armed with this knowledge, you can then use any other more complex tools to analyze it further.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/4332540713104246058/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2014/07/could-you-be-most-beautiful-bug-in-world.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/4332540713104246058'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/4332540713104246058'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2014/07/could-you-be-most-beautiful-bug-in-world.html' title='Could you be .... the most beautiful bug in the world ....'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5-M0EPXEtI2p-5q0ortGOF_Hl6KojFi3ns3d8TzU2w4Ns7GWOiSbPWbP4_XZhejoF5BXryFm2RBWCCMy3n-pyLN3d-7P0_OjZ4qeLkUfuEkPdLdqVQ5NpJRdDA0MeANQCgxVpSUhckEg/s72-c/gc2.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-5070828865137645147</id><published>2014-06-05T14:18:00.001-07:00</published><updated>2014-07-05T06:15:31.987-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="jQuery"/><category scheme="http://www.blogger.com/atom/ns#" term="WebSockets"/><title type='text'>A chat application with WebSockets, Java and jQuery</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;script src=&quot;https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I&#39;m not going to describe the WebSockets protocol here - you can find zillions of tutorials online. In this short article I show how to build a simple chat application based on WebSockets.&lt;br /&gt;
&lt;br /&gt;
The good news is that you don&#39;t have to worry about the nitty-gritty details of parsing WebSockets headers and packets, that&#39;s already implemented by open source libraries. On top of those you can write a server in Java, C#, Python, etc.&lt;br /&gt;
I use &lt;a href=&quot;https://tyrus.java.net/documentation/1.0/user-guide.html&quot; target=&quot;_blank&quot;&gt;Tyrus&lt;/a&gt;, which makes it so easy to implement the server side of my chat application.&lt;br /&gt;
First I need to create a host for my endpoint:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;package server;

import java.io.BufferedReader;
import java.io.InputStreamReader;
 
import org.glassfish.tyrus.server.Server;
 
public class WebSocketServer {
 
    public static void main(String[] args) {
        runServer();
    }
 
    public static void runServer() {
        Server server = new Server(&quot;localhost&quot;, 8025, &quot;/chat&quot;, ChatEndpoint.class);
 
        try {
            server.start();
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            System.out.print(&quot;Please press a key to stop the server.&quot;);
            reader.readLine();
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            server.stop();
        }
    }
}&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;/pre&gt;
Look at the line where I create the Server object: I&#39;ll deploy ChatEndpoint to localhost:8025/chat.&lt;br /&gt;
Now I need to create the server itself - this ChatEndpoint type:
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;package server;

import java.io.IOException;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
 
import javax.websocket.CloseReason;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.CloseReason.CloseCodes;
import javax.websocket.server.ServerEndpoint;
 
@ServerEndpoint(value = &quot;/test&quot;)
public class ChatEndpoint {
 
    private Logger logger = Logger.getLogger(this.getClass().getName());
    // keep all open WebSocket sessions (from all users)
    private static Queue&lt;/span&gt;&lt;session&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt; queue = new ConcurrentLinkedQueue&amp;lt;&amp;gt;();

    @OnOpen
    public void onOpen(Session session) {
        logger.info(&quot;Connect with session: &quot; + session.getId());
        queue.add(session);
        logger.log(Level.INFO, &quot;Connected with &quot; +  session.getId());
    }
 
    @OnMessage
    public void onMessage(String message, Session session) {
        logger.log(Level.INFO, &quot;Mesage received &quot; + message);
        try {
            // broadcast message to all open WebSocket sessions
            for (Session s : queue) {
             // include the original sender
             s.getBasicRemote().sendText(message);
             logger.log(Level.INFO, &quot;Message sent: &quot; + message);
            }
         } catch (IOException e) {
            logger.log(Level.INFO, e.toString());
         }
        // we could have a return here, in which case the returned string
        // would be the one sent from server to client,
        // as if doing s.getBasicRemote().sendText(message)
        //return message + &quot;TEST&quot;;
    }
 
    @OnClose
    public void onClose(Session session, CloseReason closeReason) {
        logger.info(String.format(&quot;Session %s closed because of %s&quot;, session.getId(), closeReason));
        queue.remove(session);
        logger.log(Level.INFO, &quot;Connection closed with &quot; + session.getId());
    }
}&lt;/span&gt;
&lt;/session&gt;&lt;/pre&gt;
&lt;b&gt;Tyrus &lt;/b&gt;makes things easy for us. Look at the annotation &lt;i&gt;&lt;span style=&quot;color: red;&quot;&gt;@ServerEndpoint(value = &quot;/test&quot;) &lt;/span&gt;&lt;/i&gt;- here I&#39;m saying that my server is accessible under the relative path &quot;/test&quot; under the URL mentioned before, thus the whole URL becomes:&lt;i&gt; localhost:8025/chat/test&lt;/i&gt;.


&lt;br /&gt;
&lt;br /&gt;
We have three more annotations:&lt;br /&gt;
-&amp;nbsp;&lt;i&gt;@OnOpen&lt;/i&gt; to mark the method for opening the connection from a client to this server; here session uniquely identifies the connecting client&lt;br /&gt;
-&amp;nbsp;&lt;i&gt;@OnClose&lt;/i&gt; to mark the callback triggered when the connection with a particular client closes&lt;br /&gt;
-&amp;nbsp;&lt;i&gt;@OnMessage&lt;/i&gt; for the method that does the most important job: whenever a message is received from a client, this method broadcasts the message to all clients (including the sender)&lt;br /&gt;
&lt;br /&gt;
That&#39;s all on the server side.&lt;br /&gt;
So now the client is a simple web page with some jQuery embellishments:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;lt;script type=&#39;text/javascript&#39; src=&#39;jquery.js&#39;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;lt;script type=&#39;text/javascript&#39; src=&#39;jquery-ui-1.8.23.custom.min.js&#39;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;lt;script type=&#39;text/javascript&#39;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;var wsocket;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;function connect() {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;wsocket = new WebSocket(&quot;ws://localhost:8025/chat/test&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;wsocket.onmessage = onMessage;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;alert(&quot;Connect&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;function onMessage(evt) {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;$(&quot;#chatText&quot;).append(&quot;\n&quot; + evt.data);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;$(document).ready(&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;nbsp; function() {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;$(&quot;#connect&quot;).click(&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;          &lt;/span&gt;function() {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;              &lt;/span&gt;wsocket = new WebSocket(&quot;ws://localhost:8025/chat/test&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;              &lt;/span&gt;wsocket.onmessage = onMessage;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;          &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;$(&quot;#send&quot;).click(&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;          &lt;/span&gt;function() {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;              &lt;/span&gt;wsocket.send($(&quot;#username&quot;).val() + &quot;:&quot; + $(&quot;#tosend&quot;).val());&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;              &lt;/span&gt;$(&quot;#tosend&quot;).val(&quot;&quot;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;          &lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;lt;title&amp;gt;Chat&amp;lt;/title&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;Username: &amp;lt;input type=&quot;text&quot; id=&quot;username&quot;&amp;gt;&amp;lt;br&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;lt;input type=&quot;submit&quot; value=&quot;Connect&quot; id=&quot;connect&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;lt;input type=&quot;submit&quot; value=&quot;Disconnect&quot;&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;lt;textarea rows=&quot;30&quot; cols=&quot;50&quot; id=&quot;chatText&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;lt;/textarea&amp;gt;&amp;lt;br&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;lt;textarea rows=&quot;4&quot; cols=&quot;50&quot; id=&quot;tosend&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;lt;/textarea&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;lt;br&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;lt;input type=&quot;submit&quot; value=&quot;Send&quot; id=&quot;send&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, Times New Roman, serif; font-size: x-small;&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
Note how we open the connection with the server:&amp;nbsp;&lt;span style=&quot;color: #444444; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #444444; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;i&gt;new WebSocket(&quot;ws://localhost:8025/chat/test&quot;)&lt;/i&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: #444444;&quot;&gt;Sending messages from the client to the server is simple too:&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #444444;&quot;&gt;&lt;i&gt;wsocket.send($(&quot;#username&quot;).val() + &quot;:&quot; + $(&quot;#tosend&quot;).val());&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #444444;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Incredibly easy, isn&#39;t it ?&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Oh, by the way, this is the list of jars I need for the application to compile (you can use Maven to simplify the deployment a bit):&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5WPULI949j4R2z0Dn5lXBZtlpqyEc1ZI4P5kidj0wVRMe1PTOlSWDN_juv4Rhq4MRuML0qYnaDb9epDUpSmYCbuCBbsFsCyNpiZnFfAvW5QN1cK-xC4LmvoerLYEbXJ1bUssguSduvTc/s1600/tyrus.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5WPULI949j4R2z0Dn5lXBZtlpqyEc1ZI4P5kidj0wVRMe1PTOlSWDN_juv4Rhq4MRuML0qYnaDb9epDUpSmYCbuCBbsFsCyNpiZnFfAvW5QN1cK-xC4LmvoerLYEbXJ1bUssguSduvTc/s1600/tyrus.png&quot; height=&quot;188&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #444444; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/5070828865137645147/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2014/06/a-chat-application-with-websockets-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/5070828865137645147'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/5070828865137645147'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2014/06/a-chat-application-with-websockets-java.html' title='A chat application with WebSockets, Java and jQuery'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5WPULI949j4R2z0Dn5lXBZtlpqyEc1ZI4P5kidj0wVRMe1PTOlSWDN_juv4Rhq4MRuML0qYnaDb9epDUpSmYCbuCBbsFsCyNpiZnFfAvW5QN1cK-xC4LmvoerLYEbXJ1bUssguSduvTc/s72-c/tyrus.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-1339160416539826429</id><published>2014-01-05T13:35:00.002-08:00</published><updated>2014-01-05T13:50:54.364-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="eclipse"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="maven"/><title type='text'>Maven tips and tricks</title><content type='html'>&lt;br /&gt;
Maven is cool. Reading the official tutorial&amp;nbsp;&lt;a href=&quot;http://maven.apache.org/guides/getting-started/index.html&quot; target=&quot;_blank&quot;&gt;on the Maven website&lt;/a&gt;, you get a pretty good idea what it does and how it works. The tutorial fails to tell you though the most important thing: follow the Maven conventions and it will work fine; if you don&#39;t follow them, Maven won&#39;t help, better forget about it.&lt;br /&gt;
One of the Maven conventions is the standard directory layout (read&amp;nbsp;&lt;a href=&quot;http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;). As long as your project&#39;s directory structure looks like in the following figure, using Maven is ok:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi86pLyYZCupRWTq92BKe6I2rqmrpGY_xEMS5PUUdHrP_U2zzxjEJTTAE73AHtOllKOPl4HGB5Ux4gtSkEkHrVllCGXp28mNjU6XtA5Nyt41GbNJWLamZPPy43hwgtdCYI7cH_P6BiWhIM/s1600/maven1.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi86pLyYZCupRWTq92BKe6I2rqmrpGY_xEMS5PUUdHrP_U2zzxjEJTTAE73AHtOllKOPl4HGB5Ux4gtSkEkHrVllCGXp28mNjU6XtA5Nyt41GbNJWLamZPPy43hwgtdCYI7cH_P6BiWhIM/s400/maven1.png&quot; width=&quot;251&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that under the src/main you need to have your &quot;java&quot; directory for the java source code, &quot;webapp&quot; for the JSP/JSF pages (the eventual web application) and &quot;resources&quot; for some important files (read on, I&#39;ll give an example).&lt;br /&gt;
&lt;br /&gt;
However, if you happen to develop a web application under Eclipse, your directory structure will be quite different:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEha4ofcpFgLVxdJZ0rtAqtH5eFyC0AnbGhXw2rINX1A6YDfkRGFsezc6YT5akaAPY2oLr0ne1ZJ2ay37pjrqXP8BiG87os60jHL1xv2QDDRmNC-ebyaTg8AP7DYLLerdQYnRCX4lMovxkE/s1600/maven2.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;173&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEha4ofcpFgLVxdJZ0rtAqtH5eFyC0AnbGhXw2rINX1A6YDfkRGFsezc6YT5akaAPY2oLr0ne1ZJ2ay37pjrqXP8BiG87os60jHL1xv2QDDRmNC-ebyaTg8AP7DYLLerdQYnRCX4lMovxkE/s200/maven2.png&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Trying to use Maven now to build and deploy this Eclipse project is doomed to fail. The simplest solution to produce the war you need is to use Export from File menu under Eclipse and choose Web -&amp;gt; &quot;WAR file&quot;.&lt;br /&gt;
&lt;br /&gt;
For my own purposes I needed to use Maven, so I first moved the Eclipse project around in order to mimic the directory structure desired by Maven (as shown in the first figure above). From that point on, I learned some simple lessons:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: red;&quot;&gt;1.&lt;/span&gt; as you&#39;ve noticed, whenever you run a Maven phase/goal, Maven downloads all libraries necessary and places them under your local&amp;nbsp;&lt;i&gt;C:\Users\myUserName\.m2\repository&lt;/i&gt;; this is very powerful, as you can use Maven out of the box with a &quot;tabula rasa&quot; computer and end up with a neatly deployed project with all references solved&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: red;&quot;&gt;2.&lt;/span&gt; I wanted to add to my Maven project a dependency to an existing jar, so here it&#39;s what I&#39;ve done:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoListParagraph&quot; style=&quot;background: #EEEEEE; line-height: 13.5pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-add-space: auto; mso-list: l0 level1 lfo1; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; text-indent: -.25in; vertical-align: baseline;&quot;&gt;
&lt;!--[if !supportLists]--&gt;&lt;span style=&quot;font-family: Consolas; font-size: 10.5pt;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;border: 1pt none windowtext; font-family: Consolas; font-size: 10.5pt; padding: 0in;&quot;&gt;mvn install:install-file -&lt;/span&gt;&lt;span style=&quot;border: none windowtext 1.0pt; color: #2b91af; font-family: Consolas; font-size: 10.5pt; mso-border-alt: none windowtext 0in; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; padding: 0in;&quot;&gt;DgroupId&lt;/span&gt;&lt;span style=&quot;border: 1pt none windowtext; font-family: Consolas; font-size: 10.5pt; padding: 0in;&quot;&gt;=com.mycompany.test -&lt;/span&gt;&lt;span style=&quot;border: none windowtext 1.0pt; color: #2b91af; font-family: Consolas; font-size: 10.5pt; mso-border-alt: none windowtext 0in; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; padding: 0in;&quot;&gt;DartifactId&lt;/span&gt;&lt;span style=&quot;border: 1pt none windowtext; font-family: Consolas; font-size: 10.5pt; padding: 0in;&quot;&gt;=testid -&lt;/span&gt;&lt;span style=&quot;border: none windowtext 1.0pt; color: #2b91af; font-family: Consolas; font-size: 10.5pt; mso-border-alt: none windowtext 0in; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; padding: 0in;&quot;&gt;Dversion&lt;/span&gt;&lt;span style=&quot;border: 1pt none windowtext; font-family: Consolas; font-size: 10.5pt; padding: 0in;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;border: none windowtext 1.0pt; color: maroon; font-family: Consolas; font-size: 10.5pt; mso-border-alt: none windowtext 0in; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; padding: 0in;&quot;&gt;1.0&lt;/span&gt;&lt;span style=&quot;border: 1pt none windowtext; font-family: Consolas; font-size: 10.5pt; padding: 0in;&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;border: none windowtext 1.0pt; color: #2b91af; font-family: Consolas; font-size: 10.5pt; mso-border-alt: none windowtext 0in; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; padding: 0in;&quot;&gt;Dpackaging&lt;/span&gt;&lt;span style=&quot;border: 1pt none windowtext; font-family: Consolas; font-size: 10.5pt; padding: 0in;&quot;&gt;=jar -&lt;/span&gt;&lt;span style=&quot;border: none windowtext 1.0pt; color: #2b91af; font-family: Consolas; font-size: 10.5pt; mso-border-alt: none windowtext 0in; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; padding: 0in;&quot;&gt;Dfile&lt;/span&gt;&lt;span style=&quot;border: 1pt none windowtext; font-family: Consolas; font-size: 10.5pt; padding: 0in;&quot;&gt;=/path/to/jarfile/f.jar&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 10.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraph&quot; style=&quot;background: #EEEEEE; line-height: 13.5pt; margin-bottom: .0001pt; margin-bottom: 0in; mso-add-space: auto; mso-list: l0 level1 lfo1; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; text-indent: -.25in; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;border: 1pt none windowtext; font-family: Consolas; font-size: 10.5pt; padding: 0in;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
This resulted in copying the desired dependency, &lt;i&gt;f.jar&lt;/i&gt;, somewhere under &lt;i&gt;.m2/repository&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
I added then the following to my &lt;i&gt;pom.xml:&lt;/i&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;groupId&amp;gt;com.mycompany.test&amp;lt;/groupId&amp;gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;artifactId&amp;gt;testid&amp;lt;/artifactId&amp;gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;version&amp;gt;1.0&amp;lt;/version&amp;gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;lt;/dependency&amp;gt; &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoListParagraphCxSpFirst&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpLast&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: red;&quot;&gt;3.&lt;/span&gt; by the way, while running&amp;nbsp;&lt;i&gt;mvn package&lt;/i&gt; you&#39;ll most likely get error messages referring to missing classes; to fix this, just look for the missing class online, e.g.:&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&amp;nbsp;&lt;a href=&quot;http://www.findjar.com/class/org/apache/openejb/jee/FacesConverter.html&quot;&gt;http://www.findjar.com/class/org/apache/openejb/jee/FacesConverter.html&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; class=&quot;MsoNormalTable&quot;&gt;
 &lt;tbody&gt;
&lt;tr&gt;
  &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot; valign=&quot;top&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;Containing JAR files:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;padding: .75pt .75pt .75pt .75pt;&quot; valign=&quot;top&quot;&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;
&lt;span style=&quot;color: #e78608; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 7.5pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;[MAVEN2]&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.findjar.com/jar/org/apache/openejb/openejb-jee/3.1.1/openejb-jee-3.1.1.jar.html&quot;&gt;&lt;span style=&quot;color: #e78608; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; text-decoration: none; text-underline: none;&quot;&gt;openejb-jee-3.1.1.jar&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;br /&gt;
  &lt;/span&gt;&lt;span style=&quot;color: #e78608; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 7.5pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;[MAVEN2]&lt;/span&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.findjar.com/jar/org/apache/openejb/openejb-jee/3.1/openejb-jee-3.1.jar.html&quot;&gt;&lt;span style=&quot;color: #e78608; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 10.0pt; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; text-decoration: none; text-underline: none;&quot;&gt;openejb-jee-3.1.jar&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; font-size: 10pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
As you can see, findjar.com gives you links to Maven2 repositories. Following these links will tell you what artifactId and version you&#39;ll need to include in your pom.xml in order to fix this dependency.&lt;br /&gt;
&lt;br /&gt;
Or even better, just go to the&amp;nbsp;&lt;a href=&quot;http://search.maven.org/&quot; target=&quot;_blank&quot;&gt;Central Maven Repository&lt;/a&gt;&amp;nbsp;and look there for the missing class. Finally you&#39;ll get to the page that shows you exactly what you need to include in your pom.xml (you can copy-paste it):&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTvDIKEQcOHeqEjt4CgT8qnhPgPeD6Ds7FgQ8gPphYaOj_apg7Z_5uavNLm9swD1Pl763XBr9O1O4nfqry1oa8L8QfDAg1hk61aIQzf5Qv_A5Sx26opGOFEgMTHHDCuvCZS_0QGfFMJaI/s1600/maven3.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;271&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTvDIKEQcOHeqEjt4CgT8qnhPgPeD6Ds7FgQ8gPphYaOj_apg7Z_5uavNLm9swD1Pl763XBr9O1O4nfqry1oa8L8QfDAg1hk61aIQzf5Qv_A5Sx26opGOFEgMTHHDCuvCZS_0QGfFMJaI/s400/maven3.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: red;&quot;&gt;4.&lt;/span&gt; if you&#39;re using Hibernate (high likelihood I&#39;d say), add your &lt;i&gt;hibernate.cfg.xml&lt;/i&gt;
to &lt;b&gt;/src/main/resources&lt;/b&gt;; moreover, all other Hibernate configuration files, e.g.
&lt;i&gt;Patient.hbm.xml&lt;/i&gt;, must be added to the corresponding /resources subdirectory; I
needed to add all my .&lt;i&gt;hbm.xml &lt;/i&gt;files to &lt;b&gt;/src/main/resources/model&lt;/b&gt;; after you run &lt;i&gt;mvn
package&lt;/i&gt;, they end up in the war file under WEB-INF\classes\model&lt;br /&gt;
&lt;div class=&quot;MsoListParagraph&quot;&gt;
&lt;br /&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraph&quot;&gt;
&lt;span style=&quot;background-color: red;&quot;&gt;5.&lt;/span&gt; since you&#39;re packaging a web application, add the following to your &lt;i&gt;pom.xml:&lt;/i&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;lt;build&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;plugins&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;plugin&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;maven-war-plugin&amp;lt;/artifactId&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;2.4&amp;lt;/version&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;/plugin&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/plugins&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;lt;/build&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
------------------&lt;br /&gt;
&lt;br /&gt;
The following is the &lt;b&gt;pom.xml&lt;/b&gt; file I&#39;m using for my project:&lt;br /&gt;
&lt;div class=&quot;MsoListParagraphCxSpFirst&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;pre nbsp=&quot;&quot; style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJ8Tg4tptl9S3xcHhByw5CjycFO8Tqed23n4JiIt0xSZYSQ2fS_P3VLgdq3Ce0-iuW27HfO7tZGybhNUyju_fblUVbQjlI92OGURAuxPg_UKDy2KSUTTmDeFozKIlzd69C_6diEg_c_30h/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; &amp;lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; &amp;nbsp;&lt;/code&gt;&lt;/pre&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;lt;groupId&amp;gt;com.mycompany.app&amp;lt;/groupId&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;lt;artifactId&amp;gt;app&amp;lt;/artifactId&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;lt;packaging&amp;gt;war&amp;lt;/packaging&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;lt;dependencies&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;lt;dependency&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;junit&amp;lt;/groupId&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;junit&amp;lt;/artifactId&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;3.8.1&amp;lt;/version&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;scope&amp;gt;test&amp;lt;/scope&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;lt;/dependency&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;lt;dependency&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;groupId&amp;gt;javax.servlet&amp;lt;/groupId&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;artifactId&amp;gt;javax.servlet-api&amp;lt;/artifactId&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;version&amp;gt;3.0.1&amp;lt;/version&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;scope&amp;gt;provided&amp;lt;/scope&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;lt;/dependency&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;lt;dependency&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;groupId&amp;gt;org.hibernate&amp;lt;/groupId&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;artifactId&amp;gt;hibernate-core&amp;lt;/artifactId&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;version&amp;gt;3.6.3.Final&amp;lt;/version&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;lt;/dependency&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;lt;dependency&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;groupId&amp;gt;javax.faces&amp;lt;/groupId&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;artifactId&amp;gt;jsf-api&amp;lt;/artifactId&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;version&amp;gt;1.2_02&amp;lt;/version&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;lt;/dependency&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;lt;dependency&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;groupId&amp;gt;org.apache.openejb&amp;lt;/groupId&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;artifactId&amp;gt;openejb-jee&amp;lt;/artifactId&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;version&amp;gt;3.1.1&amp;lt;/version&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;lt;/dependency&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;lt;dependency&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;groupId&amp;gt;commons-logging&amp;lt;/groupId&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;artifactId&amp;gt;commons-logging&amp;lt;/artifactId&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;version&amp;gt;1.1.3&amp;lt;/version&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;lt;/dependency&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;lt;dependency&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;groupId&amp;gt;com.mycompany.test&amp;lt;/groupId&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;artifactId&amp;gt;testid&amp;lt;/artifactId&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;version&amp;gt;1.0&amp;lt;/version&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;lt;/dependency&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;lt;/dependencies&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;lt;build&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;plugins&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;plugin&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;artifactId&amp;gt;maven-war-plugin&amp;lt;/artifactId&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;version&amp;gt;2.4&amp;lt;/version&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;/plugin&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/plugins&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;lt;/build&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&amp;nbsp;&amp;lt;/project&amp;gt; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;MsoListParagraphCxSpFirst&quot;&gt;
&lt;span style=&quot;color: blue; font-family: Courier New, Courier, monospace; font-size: x-small;&quot;&gt;&lt;project o:p=&quot;&quot; xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;&gt;&lt;/project&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoListParagraphCxSpMiddle&quot;&gt;
Enjoy Maven, folks !&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/1339160416539826429/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2014/01/maven-tips-and-tricks.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/1339160416539826429'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/1339160416539826429'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2014/01/maven-tips-and-tricks.html' title='Maven tips and tricks'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi86pLyYZCupRWTq92BKe6I2rqmrpGY_xEMS5PUUdHrP_U2zzxjEJTTAE73AHtOllKOPl4HGB5Ux4gtSkEkHrVllCGXp28mNjU6XtA5Nyt41GbNJWLamZPPy43hwgtdCYI7cH_P6BiWhIM/s72-c/maven1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-8945339020203078549</id><published>2013-10-27T06:42:00.001-07:00</published><updated>2013-12-18T13:31:46.965-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="eclipse"/><category scheme="http://www.blogger.com/atom/ns#" term="Glassfish"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="jsf"/><title type='text'>Write Once Run Anywhere .... if you can</title><content type='html'>Let&#39;s see. A few weeks back my hard-drive crashed and I needed to replace it. Luckily, I had saved my data previously, among which a Java-based application with 3 tiers: JSF, jQuery, servlets, and an open-source database. I wanted thus to resurrect this application. &quot;Piece of cake&quot; I told to myself, Java is after all WORA (Write Once Run Anywhere).&lt;br /&gt;
So this is what I&#39;ve done:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;downloaded and installed Eclipse Juno (which didn&#39;t start on double-clicking the exe, but rather using this command line:&amp;nbsp;&lt;i&gt;C:\eclipse\eclipse.exe -vm &quot;C:\Program Files\Java\jre7\bin&quot;&lt;/i&gt;)&lt;/li&gt;
&lt;br /&gt;
&lt;li&gt;I want to run this application on Apache Tomcat and Glassfish application servers, so after downloading and installing both, I needed to download server adapters, as shown in the following figure (see &quot;Download additional server adapters&quot; in the figure below)&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEig8Q1r6FJ3QmTInCAZPrrW0oC-7zuYRux3r-vx5ZOqTRt4AlhrB_KM1sg2AddYBZqQwoEyhMyguKJSxMGdc10x1HfgWhOULj1tFjK21NTCBGR3dwhRUlJjKzPHIvVel8oFUjlCg5Z-VxA/s1600/Download+server+adapters.png&quot; imageanchor=&quot;1&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;225&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEig8Q1r6FJ3QmTInCAZPrrW0oC-7zuYRux3r-vx5ZOqTRt4AlhrB_KM1sg2AddYBZqQwoEyhMyguKJSxMGdc10x1HfgWhOULj1tFjK21NTCBGR3dwhRUlJjKzPHIvVel8oFUjlCg5Z-VxA/s400/Download+server+adapters.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Note that I tried first with Glassfish 4.0.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
3. I created a &lt;b&gt;Dynamic Web Project &lt;/b&gt;in Eclipse and imported the sources of my project (saved from the previous hard-drive)&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
4. Then, as I was building the project, I noticed missing required jar files, so I started looking for them (either jarfinder.com or findjar.com) and adding them to \WEB-INF\lib&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
At this point in time I thought everything should work fine.&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
But first I encountered a strange run-time exception, as shown below:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpRCuG8LKIDT81L3YjHiuyAzRW5AplC17glRHrpGWnpAS2AEHjm-KMFXLMgpMfjQY-03VFsWoa4DS9Js5DlOMnsODRJsZN8f8rp-Z6vK0_tffhVoKMjsZZtg6sdeMWHgpL6z_M-LZp-Aw/s1600/ErrorFixedWithDynamicWebProject3.0.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;225&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpRCuG8LKIDT81L3YjHiuyAzRW5AplC17glRHrpGWnpAS2AEHjm-KMFXLMgpMfjQY-03VFsWoa4DS9Js5DlOMnsODRJsZN8f8rp-Z6vK0_tffhVoKMjsZZtg6sdeMWHgpL6z_M-LZp-Aw/s400/ErrorFixedWithDynamicWebProject3.0.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
5. After a bit of searching online, it turned out I needed to configure Project Facets to use &lt;b&gt;Dynamic Web Project 3.0&lt;/b&gt;, as shown below:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeG6Lt8foyqEj2sdtoztidKVUvGfm8BioQg5W0Zcq9ciIVtr9_JJZBCMixpEdpLl3Vzl6b1YwP2D13Jb9GQLbsdK1Eh0lNJY1YzFI9ftlTLtl_xyYwSaGdpB1T1VLfFEAweBlEt660ru4/s1600/TryingToSetDynamicWebProjectTo3.0.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;225&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeG6Lt8foyqEj2sdtoztidKVUvGfm8BioQg5W0Zcq9ciIVtr9_JJZBCMixpEdpLl3Vzl6b1YwP2D13Jb9GQLbsdK1Eh0lNJY1YzFI9ftlTLtl_xyYwSaGdpB1T1VLfFEAweBlEt660ru4/s400/TryingToSetDynamicWebProjectTo3.0.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Note: it&#39;s very important to select the right Project Facets, because that decides what jars will be used. Fro example, if you don&#39;t choose the JSF facet, then you need to add the JSF jars yourself; sometimes there&#39;s a good reason to do just that, e.g. the default provided jars won&#39;t do the job, so you want to use other jars.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
6. As you can see, Eclipse complained about the Java version, so I needed to use the &lt;b&gt;Java 7 compiler&lt;/b&gt;, as shown in the following figures:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-2N4S5fLdIXipUdD3hYfHS54vD63BDXDqr5rH1X1ZJXzsl39fG9bfxdbGwx5HukIe40X349F9YTM5gFMtcRGtBFfBL6vTViDGaaWOF0xrvrSH8GRijFzhGy5ecXI36EqJgj64B3CZzuA/s1600/set+Java+CompilerTo1.7.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;225&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-2N4S5fLdIXipUdD3hYfHS54vD63BDXDqr5rH1X1ZJXzsl39fG9bfxdbGwx5HukIe40X349F9YTM5gFMtcRGtBFfBL6vTViDGaaWOF0xrvrSH8GRijFzhGy5ecXI36EqJgj64B3CZzuA/s400/set+Java+CompilerTo1.7.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVquWyEFdV00zdMy2Uz_ppWFT3xrCJqnD2H0V6eAxvI2-pmw4Tcc51EUK4y_8mLdHn4uSFg7_Drk7br7_eJz6p3rU6WyD2pmHmxlmbJbBm_Omhi8XNmS5L_Ja7aQnktsFiW9cDtHnVHoA/s1600/TryingToSetDynamicWebProjectTo3.0_fixed.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;225&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVquWyEFdV00zdMy2Uz_ppWFT3xrCJqnD2H0V6eAxvI2-pmw4Tcc51EUK4y_8mLdHn4uSFg7_Drk7br7_eJz6p3rU6WyD2pmHmxlmbJbBm_Omhi8XNmS5L_Ja7aQnktsFiW9cDtHnVHoA/s400/TryingToSetDynamicWebProjectTo3.0_fixed.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
7. After all this hassle, my application worked, but only with &lt;b&gt;Glassfish 3.1&lt;/b&gt;; on 4.0 it throws an NPE; on Tomcat, no way to make it work, even though the same application previously worked ONLY on Tomcat and not on Glassfish ....&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIJQcuaeLN-k5IHVs-LsikHVbvsaeqE5Ge4xaY9QoPL5A71QpCHL1unbRn0haYSrxyr19dQPkP6nbkVSKTYRQntO0yfjnosgDUQOKODOdtRz8mcURV_y1d8MPFdgNC7ixogX1YkgeMbFI/s1600/OnlyGlassfish3.1Worked.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;225&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIJQcuaeLN-k5IHVs-LsikHVbvsaeqE5Ge4xaY9QoPL5A71QpCHL1unbRn0haYSrxyr19dQPkP6nbkVSKTYRQntO0yfjnosgDUQOKODOdtRz8mcURV_y1d8MPFdgNC7ixogX1YkgeMbFI/s400/OnlyGlassfish3.1Worked.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;i&gt;By the way, in the past I also had an issue with an application working fine on the former Oracle OAS and not working at all on Tomcat. It turned out that replacing the standard Oracle JSF libs with the ones from &lt;b&gt;Mojarra &lt;/b&gt;helped. But you never know ....&lt;/i&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
I need to investigate this further, but now I&#39;m happy at least I made it work on Glassfish 3.1.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Greetings from the jungle,&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&amp;nbsp; &amp;nbsp; Sorin&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
P.S. A great article about JSF 2.0 with Glassfish and Eclipse is here:&amp;nbsp;&lt;a href=&quot;http://balusc.blogspot.nl/2011/01/jsf-20-tutorial-with-eclipse-and.html&quot;&gt;http://balusc.blogspot.nl/2011/01/jsf-20-tutorial-with-eclipse-and.html&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/8945339020203078549/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2013/10/write-once-run-anywhere.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/8945339020203078549'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/8945339020203078549'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2013/10/write-once-run-anywhere.html' title='Write Once Run Anywhere .... if you can'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEig8Q1r6FJ3QmTInCAZPrrW0oC-7zuYRux3r-vx5ZOqTRt4AlhrB_KM1sg2AddYBZqQwoEyhMyguKJSxMGdc10x1HfgWhOULj1tFjK21NTCBGR3dwhRUlJjKzPHIvVel8oFUjlCg5Z-VxA/s72-c/Download+server+adapters.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-171665005369968366</id><published>2013-06-09T14:13:00.000-07:00</published><updated>2013-06-10T04:27:50.282-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="jQuery"/><category scheme="http://www.blogger.com/atom/ns#" term="jsf"/><title type='text'>Sweat, blood and tears with JSF</title><content type='html'>I&#39;ll start with the conclusion: if you&#39;re building standard, textbook web applications with Java Server Faces, you&#39;re going to love the technology. But the moment you start developing things that are a bit off the beaten track, the fun begins ....

Let&#39;s take for example the &lt;a href=&quot;http://sorincalex.blogspot.nl/2013/03/calendar-with-data-from-database-jquery.html&quot;&gt;calendar&lt;/a&gt; I presented recently. I want to add it some more functionality: when clicking on a certain day, you&#39;re redirected to a new page where you can create a new appointment. Once you confirm it, you&#39;ll be returned to the calendar page.
So, this is how I extended the jQuery calendar:

&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;

dayClick: function(date, allDay, jsEvent, view) {
     if (allDay) {
        alert(&#39;Clicked on the entire day: &#39; + date);
        var url = &quot;http://localhost:8080/Patients/appointments.jsf?day=&quot; + date.getDate() + &quot;&amp;amp;month=&quot; + (date.getMonth() + 1) + &quot;&amp;amp;year=&quot; + date.getFullYear();    
        $(location).attr(&#39;href&#39;,url);  
     } else {
        //alert(&#39;Clicked on the slot: &#39; + date);
     }

}
&lt;/code&gt;&lt;/pre&gt;
Note that I&#39;ve hardcoded the path to the appointment page (&quot;&lt;b&gt;appointments.jsp&lt;/b&gt;&quot;). More importantly, I&#39;m passing the date (day, month, year) as URL request parameters, e.g.:
&lt;i&gt;&lt;span style=&quot;color: #b45f06;&quot;&gt;http://localhost:8080/Patients/appointments.jsf?day=5&amp;amp;month=7&amp;amp;year=2013&lt;/span&gt;&lt;/i&gt;
&lt;br /&gt;
&lt;br /&gt;
On the appointments.jsp page, one of the things I do is to print the chosen date:

&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&amp;lt;%
out.println(&quot;Data: &quot; + request.getParameter(&quot;day&quot;) + &quot;-&quot; + request.getParameter(&quot;month&quot;) + &quot;-&quot; + request.getParameter(&quot;year&quot;));
%&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
Then, I&#39;ve added a text input and a button, so that the user can fill in a patient name (or part of it) and click the button in order to search (in a DB) for all patients with the name containing the given text. The patients are supposed to be displayed in a &lt;i&gt;selectOneListBox&lt;/i&gt;, as shown below:

&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&amp;lt;h:inputText binding=&quot;#{PatientsSearch.inputText1}&quot; valueChangeListener=&quot;#{PatientsSearch.lookForName}&quot; immediate=&quot;true&quot; id=&quot;inputText1&quot;/&amp;gt;
&amp;lt;h:commandButton value=&quot;Patient search:&quot; action=&quot;#{&lt;span style=&quot;color: #783f04;&quot;&gt;PatientsSearch.getPatientsByName&lt;/span&gt;}&quot;&amp;gt;
&amp;lt;/h:commandButton&amp;gt;

&amp;lt;h:selectOneListbox id=&quot;patients&quot; value=&quot;#{&lt;span style=&quot;color: #783f04;&quot;&gt;PatientsSearch.selectedPatient&lt;/span&gt;}&quot;&amp;gt;
&amp;lt;f:selectItems value=&quot;#{PatientsSearch.patients}&quot; var=&quot;p&quot;
       itemLabel=&quot;#{p.name}:#{p.phoneMobile}&quot; itemValue=&quot;#{p.name}&quot; /&amp;gt;
&amp;lt;/h:selectOneListbox&amp;gt;

&lt;/code&gt;&lt;/pre&gt;
Almost everything works fine, i.e. if you click the &quot;Patient search&quot; button, the listbox will indeed be filled in with the corresponding patients&#39; names and thus you can select on of the names from the list. I&#39;m saying &quot;almost&quot;, because if you change your mind and look up another patient name, clicking the &quot;Patient search&quot; button doesn&#39;t produce any result (actually I debugged it and noticed that the handler &lt;i&gt;PatientsSearch.getPatientsByName&lt;/i&gt; is indeed called, but somehow the listbox is not refreshed with the new names). If you don&#39;t select any name in the list and perform a new patient search, this will work (so clicking the button produces the desired result). It looks as if the listbox is not just a &quot;select one&quot;, but &quot;use only once&quot;: the moment you select an item from the list, you can&#39;t refresh it anymore ....&lt;br /&gt;
Anyway, I actually didn&#39;t like the list, so I&#39;ve replaced it with a &lt;i&gt;table&lt;/i&gt;:

&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&amp;lt;h:dataTable var=&quot;patient&quot; value=&quot;#{&lt;span style=&quot;color: #783f04;&quot;&gt;PatientsSearch.patients&lt;/span&gt;}&quot; style=&quot;width:300px;height:150px&quot; rowClasses=&quot;oddRow, evenRow&quot;&amp;gt;
  &amp;lt;h:column id=&quot;name&quot;&amp;gt;
    &amp;lt;f:facet name=&quot;header&quot;&amp;gt;
    &amp;lt;h:outputText value=&quot;Name&quot; /&amp;gt;
    &amp;lt;/f:facet&amp;gt;
    &amp;lt;h:outputText value=&quot;#{patient.name}&quot; /&amp;gt;
  &amp;lt;/h:column&amp;gt;
  &amp;lt;h:column id=&quot;phone&quot;&amp;gt;
    &amp;lt;f:facet name=&quot;header&quot;&amp;gt;
    &amp;lt;h:outputText value=&quot;Phone&quot; /&amp;gt;
    &amp;lt;/f:facet&amp;gt;
    &amp;lt;h:outputText value=&quot;#{patient.phoneMobile}&quot; /&amp;gt;
  &amp;lt;/h:column&amp;gt;
  &amp;lt;h:column&amp;gt;
    &amp;lt;h:inputHidden id=&quot;patientId&quot; value=&quot;#{patient.id}&quot;/&amp;gt;
  &amp;lt;/h:column&amp;gt;
&amp;lt;/h:dataTable&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
I want to show the patient&#39;s name in the first column and the patient&#39;s phone number in the second. Wait a minute, there are three columns .... The third column contains an &lt;i&gt;inputHidden &lt;/i&gt;field, whose value is the patient&#39;s ID - &lt;i&gt;patient.id&lt;/i&gt;. So, what&#39;s the deal with this one ? Well, when I click a row in this table, I want that patient to be selected. Since the patient&#39;s ID uniquely identifies each patient, I can&#39;t simply use the name (it might not be unique). So I&#39;m going to keep the patient&#39;s ID in this hidden field and when the user selects a patient, this ID will be sent to the managed bean that takes care of creating the new appointment using the patient&#39;s ID. Compare this with the &lt;i&gt;selectOneListbox &lt;/i&gt;above: when I was selecting a patient in the listbox, the selected &lt;i&gt;Patient &lt;/i&gt;instance (as a Java type) was passed to the managed bean, as the field &lt;i&gt;PatientsSearch.selectedPatient&lt;/i&gt;. So I&#39;m losing this elegance when working with the table, but ok ....
&lt;br /&gt;
&lt;br /&gt;
Next, let&#39;s do what I&#39;ve just said: when the user selects a patient from the list, the patient&#39;s ID needs to be sent to a backing bean (i.e. we need to preserve it in order to create the appointment later). Again, look how simple was to do that with the &lt;i&gt;selectOneListbox&lt;/i&gt;: just add&lt;i&gt; value=&quot;#{PatientsSearch.selectedPatient}&quot;&lt;/i&gt; and you&#39;re done. This is the intrinsic functionality of the listbox. The table however is meant rather for listing data, such as the patients in our case, not necessarily for selecting it. After googling around for a while, I&#39;ve arrived to the conclusion that all I need to do is:
&lt;br /&gt;
&lt;span style=&quot;color: #783f04;&quot;&gt;1.&lt;/span&gt; use some&lt;b&gt; &lt;i&gt;jQuery&lt;/i&gt;/&lt;/b&gt;&lt;i&gt;&lt;b&gt;JavaScript&lt;/b&gt; &lt;/i&gt;functionality to select a row in the table (and highlight the selection)
&lt;br /&gt;
&lt;span style=&quot;color: #783f04;&quot;&gt;2.&lt;/span&gt; use a &lt;i&gt;&lt;b&gt;JSF&lt;/b&gt;&lt;/i&gt; &lt;i&gt;inputHidden &lt;/i&gt;field to keep the patient&#39;s ID of the selected row
&lt;br /&gt;
&lt;br /&gt;
These two steps are shown below. Note that I first reset the background of all &quot;&lt;i&gt;tr&lt;/i&gt;&quot; (except for the first, which is the header of the table and thus excluded from any selection) and then I set the background of the selected row to orange. &lt;br /&gt;
&lt;br /&gt;
After that I do step 2 - this single line of code cost me many hours of searches online:
&lt;i&gt;&lt;span style=&quot;color: #783f04;&quot;&gt;$(&quot;#j_id_id13\\:testId&quot;).val($(this).find(&#39;td:last&#39;).find(&#39;input&#39;).attr(&quot;value&quot;));&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
Note that the id of the &lt;i&gt;inputHidden &lt;/i&gt;is &quot;&lt;i&gt;testId&lt;/i&gt;&quot;, but JSF prefixes it with &quot;&lt;i&gt;j_id_id13&lt;/i&gt;&quot; when generating the corresponding HTML input field - you can see that by showing the page source in the browser. &quot;\\&quot; are needed to escape &quot;:&quot;. Then, &lt;i&gt;&lt;span style=&quot;color: #783f04;&quot;&gt;$(this).find(&#39;td:last&#39;)&lt;/span&gt;&lt;/i&gt; means that I want to go to the last column (&lt;i&gt;td&lt;/i&gt;) in the current row (&lt;i&gt;this&lt;/i&gt;). Finally, I look for &quot;&lt;i&gt;input&lt;/i&gt;&quot; (the HTML field generated) and read its &quot;&lt;i&gt;value&lt;/i&gt;&quot; attribute - this is the selected patient&#39;s ID.&lt;br /&gt;
Another important note: I&#39;ve displayed the value of the just set hidden field in an &quot;&lt;i&gt;alert&lt;/i&gt;&quot;, since viewing the browser source doesn&#39;t show the hidden field being updated.

&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;
$(&quot;tr&quot;).not(&#39;:first&#39;).click(
    function () {
      $(this).parent().find(&quot;tr&quot;).css(&quot;background&quot;, &quot;&quot;);
      $(this).css(&quot;background&quot;,&quot;orange&quot;);
      $(&quot;#j_id_id13\\:testId&quot;).val($(this).find(&#39;td:last&#39;).find(&#39;input&#39;).attr(&quot;value&quot;));
      alert($(&quot;#j_id_id13\\:testId&quot;).val());
    }
);

&amp;lt;h:inputHidden id=&quot;testId&quot;/&amp;gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;color: #783f04;&quot;&gt;3.&lt;/span&gt; once I have selected the patient (a row in the table) and I click the button &quot;&lt;i&gt;Create appointment&lt;/i&gt;&quot;, I can retrieve the patient&#39;s ID from the hidden field with the following handler in the backing bean:

&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;FacesContext context = FacesContext.getCurrentInstance();  
Map requestMap = context.getExternalContext().getRequestParameterMap();  
String value = (String)requestMap.get(&quot;&lt;span style=&quot;color: #783f04;&quot;&gt;j_id_id13:testId&lt;/span&gt;&quot;);
        
Patient patient;
if (value != null) {
    patient = getPatientById(value);
}
return &quot;toCalendar&quot;;
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
Now I&#39;m almost done. &quot;Almost&quot; again. Remember I&#39;m on the page &quot;&lt;b&gt;appointments.jsp&lt;/b&gt;&quot; and here I click &quot;&lt;i&gt;Patient search&lt;/i&gt;&quot;. What happens is that I&#39;m basically sent back to the same page in the browser, but then the date line I&#39;ve shown at the beginning will only display nulls:

&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&amp;lt;%
out.println(&quot;Data: &quot; + request.getParameter(&quot;day&quot;) + &quot;-&quot; + request.getParameter(&quot;month&quot;) + &quot;-&quot; + request.getParameter(&quot;year&quot;));
%&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
That happens because when clicking the button, I&#39;m actually creating a new request for this page, losing thus the URL parameters encoded from the calendar page. So, here&#39;s what I can do to preserve the date:&lt;br /&gt;
&lt;span style=&quot;color: #783f04;&quot;&gt;1.&lt;/span&gt; write the date into a cookie&lt;br /&gt;
&lt;span style=&quot;color: #783f04;&quot;&gt;2.&lt;/span&gt; use again hidden fields to pass the date around&lt;br /&gt;
&lt;span style=&quot;color: #783f04;&quot;&gt;3.&lt;/span&gt; do URL rewriting with an &lt;i&gt;onclick &lt;/i&gt;JavaScript handler when clicking the &quot;&lt;i&gt;Patient search&lt;/i&gt;&quot; button&lt;br /&gt;
&lt;span style=&quot;color: #783f04;&quot;&gt;4.&lt;/span&gt; use some form of browser storage (see HTML5, etc.)&lt;br /&gt;
&lt;br /&gt;
And the ideas could just flow like crazy hadn&#39;t I found the simplest method:

&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&amp;lt;h:commandButton value =&quot;Patient search:&quot; action=&quot;#{PatientsSearch.getPatientsByName}&quot;&amp;gt;
    &amp;lt;f:param name=&quot;day&quot; value=&quot;#{request.getParameter(&#39;day&#39;)}&quot; /&amp;gt;
    &amp;lt;f:param name=&quot;month&quot; value=&quot;#{request.getParameter(&#39;month&#39;)}&quot; /&amp;gt;
    &amp;lt;f:param name=&quot;year&quot; value=&quot;#{request.getParameter(&#39;year&#39;)}&quot; /&amp;gt;  
&amp;lt;/h:commandButton&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
Note here the EL expressions used to transmit the request parameters to the &lt;i&gt;f:param&lt;/i&gt; and thus keep them in the request scope.

&lt;br /&gt;
That&#39;s all folks ! Pffffffffff ....
&lt;br /&gt;
&lt;br /&gt;
P.S. I know you&#39;ll say there are many JSF plugins which can implement this easier, but sometimes I&#39;m just too conservative ....


</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/171665005369968366/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2013/06/sweat-blood-and-tears-with-jsf.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/171665005369968366'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/171665005369968366'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2013/06/sweat-blood-and-tears-with-jsf.html' title='Sweat, blood and tears with JSF'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-3908382333981650157</id><published>2013-03-03T13:07:00.000-08:00</published><updated>2013-03-04T12:56:14.762-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ajax"/><category scheme="http://www.blogger.com/atom/ns#" term="jQuery"/><title type='text'>Calendar with data from database: jQuery + servlets + Ajax</title><content type='html'>&lt;br /&gt;
I have a Java application that reads appointment data from a database and then shows them in a Java Swing UI. Now I want to publish this application online.&lt;br /&gt;
After a bit of research, I&#39;ve found this convenient &lt;a href=&quot;http://arshaw.com/fullcalendar/&quot; target=&quot;_blank&quot;&gt;jQuery calendar&lt;/a&gt;&amp;nbsp;and decided to use it. The main question is &amp;nbsp;then how to use my existing Java code that reads appointments and expose them to this calendar. So, what I&#39;ve done:&lt;br /&gt;
&lt;br /&gt;
1. created a Java servlet that reads the database&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/anonymous/a12ef4271fbaf206663b.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. created the jQuery fullcalendar that invokes this servlet&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/anonymous/694e8e0a6e110b062d21.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Note here the &quot;url: agenda&quot;, which basically means I&#39;m calling the servlet deployed at &lt;host&gt;/agenda.
&lt;br&gt;
&lt;br&gt;
3. then I realized that I wanted to be able to react to month/week/day changes: whenever I click the previous and next buttons, I should pass the new time period to the servlet, retrieve the new appointments from the DB and show them in the same calendar; this is how I&#39;ve achieved this:&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/anonymous/c32e00cdb049f5ffa6d4.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/3908382333981650157/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2013/03/calendar-with-data-from-database-jquery.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/3908382333981650157'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/3908382333981650157'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2013/03/calendar-with-data-from-database-jquery.html' title='Calendar with data from database: jQuery + servlets + Ajax'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-1551629593930873854</id><published>2013-01-19T13:14:00.001-08:00</published><updated>2013-01-19T13:16:25.313-08:00</updated><title type='text'>Unique in the world</title><content type='html'>&lt;br /&gt;
I remember when I started programming how nothing seemed to be impossible. I was completely ignorant to the fact that there were plenty of experienced developers out there who could do the job faster and better than me. I behaved as if I was the only programmer left on Earth.&lt;br /&gt;
The years passed and the lesson I&#39;ve learned is that the freshness of the spirit should never get worn out. Never lose it. Do your work as if you are unique in the world. Don&#39;t think about the others, they don&#39;t exist - it&#39;s just you, and you can do whatever you want to do.&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/1551629593930873854/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2013/01/unique-in-world.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/1551629593930873854'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/1551629593930873854'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2013/01/unique-in-world.html' title='Unique in the world'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-7688508595035460432</id><published>2013-01-06T03:23:00.000-08:00</published><updated>2013-01-06T03:23:59.001-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="antivirus"/><title type='text'>Another Romanian success story</title><content type='html'>&lt;br /&gt;
Hi all and a happy new year !&lt;br /&gt;
&lt;br /&gt;
No, this post is not about Dacia (&lt;a href=&quot;http://daciacars.co.uk/&quot; target=&quot;_blank&quot;&gt;daciacars.co.uk&lt;/a&gt;), but the initial intention was to praise AllView (&lt;a href=&quot;http://www.allview.ro/&quot; target=&quot;_blank&quot;&gt;www.allview.ro&lt;/a&gt;), a Brasov-based company, which produces several types of tablets and smart phones. I thought it was great that a Romanian company was a market leader in Romania (according to some studies 40% of tablets sold in Romania are Romanian-made) and it is pushing its products to Germany, Italy, the Netherlands, etc.&lt;br /&gt;
&lt;br /&gt;
However, according to &lt;a href=&quot;http://www.androider.ro/cat-de-romensti-sunt-tabletele-romanesti-8790&quot; target=&quot;_blank&quot;&gt;this blog&lt;/a&gt;, the only Romanian-made thing inside these AllView tablets is the BitDefender antivirus (&lt;a href=&quot;http://www.bitdefender.com/&quot; target=&quot;_blank&quot;&gt;www.bitdefender.com&lt;/a&gt;), a true Romaian success story. The rest is &quot;made in China&quot;.&lt;br /&gt;
By the way, a few years ago Microsoft bought GeCAD, another Romanian company which produces the popular RAV Antivirus.&lt;br /&gt;
And by the way again, do you know that the second most spoken language at Microsoft is Romanian ? That&#39;s what I call a success story.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/7688508595035460432/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2013/01/another-romanian-success-story.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/7688508595035460432'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/7688508595035460432'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2013/01/another-romanian-success-story.html' title='Another Romanian success story'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-1664246299749825767</id><published>2012-05-29T14:08:00.002-07:00</published><updated>2018-05-21T23:49:22.371-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="android"/><category scheme="http://www.blogger.com/atom/ns#" term="smartphone"/><title type='text'>Smart phone ? Yeah, right ....</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Last year I finally bought my smartphone - a shiny LG Optimus 2, dual core. I was positively impressed by the flashy look and feel, I loved the applications I could download for free from the Android store - albeit they were mostly games - and of course, I spent late nights playing Angry Birds ....&lt;br /&gt;
&lt;br /&gt;
After a few days of over-enthusiasm, I came back with my feet on the ground. The first &quot;ouch&quot; was when I spent hours to find a simple driver which allowed me to connect my new toy with the laptop. After finally managing that, I got lost trying to copy some files from the laptop to the phone and the other way around. Finally, I got that easier by enabling the Bluetooth between the two devices.&lt;br /&gt;
&lt;br /&gt;
Using GPS was a pain in the a$$ .... At the best I ended up spending huge amounts of money for the mobile Internet. Downloading and using the maps offline was not working properly.&lt;br /&gt;
&lt;br /&gt;
Frustrated, I tried to use the camera - the photos were such a poor quality (bad contrast, ugly colors) that I simply needed to remove them without any regrets.&lt;br /&gt;
&lt;br /&gt;
I&#39;ve got to the conclusion my phone is too smart, &#39;cause I&#39;ve never got to figure out its algorithm for sorting the SMSs. I&#39;m still not able to find the latest one where it should be: on the top of the stack. I went so far that when &amp;nbsp;I was receiving an SMS, I was removing the SIM-card from the smart a$$ and putting it in my plain old ugly Nokia 1110i, to be able to read that SMS.&lt;br /&gt;
&lt;br /&gt;
The battery is another &quot;great success story&quot;: just a few calls and SMSs each day and in two days the battery of my dear smart a$$ is gone .... The same usage pattern with Nokia 1110i takes close to eight days without recharge !&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In short:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQlFi8OApp5BwlEXjwZHpGIpnRkWEDT-SyIGt-62XDmP1JhIMDOMoh8gPCs7Rs8KinnQhcdfPbrKZXhkmDWplqRtEfDbgmTq9LgXK509oKt2SH3Nw_TIXl57pdvuLX3PjaAwmFS6dfS28/s1600/lgnokia.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;161&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQlFi8OApp5BwlEXjwZHpGIpnRkWEDT-SyIGt-62XDmP1JhIMDOMoh8gPCs7Rs8KinnQhcdfPbrKZXhkmDWplqRtEfDbgmTq9LgXK509oKt2SH3Nw_TIXl57pdvuLX3PjaAwmFS6dfS28/s320/lgnokia.PNG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;MsoTableColorful2&quot; style=&quot;border-collapse: collapse; border: none; margin-left: 5.4pt; mso-border-bottom-alt: solid black 1.5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 224;&quot;&gt;
 &lt;tbody&gt;
&lt;tr&gt;
  &lt;td style=&quot;background: maroon; border-top: none; border: solid black 1.5pt; mso-pattern: solid maroon; mso-shading: white; padding: 0in 5.4pt 0in 5.4pt; width: 1.9in;&quot; valign=&quot;top&quot; width=&quot;182&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;background: maroon; border-bottom: solid black 1.5pt; border-left: none; border-right: solid black 1.5pt; border-top: none; mso-border-left-alt: solid black 1.5pt; mso-pattern: solid maroon; mso-shading: white; padding: 0in 5.4pt 0in 5.4pt; width: 2.05in;&quot; valign=&quot;top&quot; width=&quot;197&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;i&gt;&lt;span style=&quot;color: white; font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;LG Optimus 2, dual core&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;i&gt;&lt;span style=&quot;color: white; font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;(bought in May 2011)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;background: maroon; border-bottom: solid black 1.5pt; border-left: none; border-right: solid black 1.5pt; border-top: none; mso-border-left-alt: solid black 1.5pt; mso-pattern: solid maroon; mso-shading: white; padding: 0in 5.4pt 0in 5.4pt; width: 142.2pt;&quot; valign=&quot;top&quot; width=&quot;190&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;i&gt;&lt;span style=&quot;color: white; font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;Nokia&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;i&gt;&lt;span style=&quot;color: white; font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;(bought in January 2007)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
  &lt;td style=&quot;background: #FFFFEF; border-bottom: none; border-left: solid black 1.5pt; border-right: solid black 1.5pt; border-top: none; mso-pattern: gray-20 yellow; mso-shading: white; padding: 0in 5.4pt 0in 5.4pt; width: 1.9in;&quot; valign=&quot;top&quot; width=&quot;182&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;Battery&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;background: #FFFFEF; border-right: solid black 1.5pt; border: none; mso-border-left-alt: solid black 1.5pt; mso-pattern: gray-20 yellow; mso-shading: white; padding: 0in 5.4pt 0in 5.4pt; width: 2.05in;&quot; valign=&quot;top&quot; width=&quot;197&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;2 days (if you’re lucky)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;background: #FFFFEF; border-right: solid black 1.5pt; border: none; mso-border-left-alt: solid black 1.5pt; mso-pattern: gray-20 yellow; mso-shading: white; padding: 0in 5.4pt 0in 5.4pt; width: 142.2pt;&quot; valign=&quot;top&quot; width=&quot;190&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;8 days&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
  &lt;td style=&quot;background: #FFFFEF; border-bottom: none; border-left: solid black 1.5pt; border-right: solid black 1.5pt; border-top: none; mso-pattern: gray-20 yellow; mso-shading: white; padding: 0in 5.4pt 0in 5.4pt; width: 1.9in;&quot; valign=&quot;top&quot; width=&quot;182&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;GPS&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;background: #FFFFEF; border-right: solid black 1.5pt; border: none; mso-border-left-alt: solid black 1.5pt; mso-pattern: gray-20 yellow; mso-shading: white; padding: 0in 5.4pt 0in 5.4pt; width: 2.05in;&quot; valign=&quot;top&quot; width=&quot;197&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;Useless&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;background: #FFFFEF; border-right: solid black 1.5pt; border: none; mso-border-left-alt: solid black 1.5pt; mso-pattern: gray-20 yellow; mso-shading: white; padding: 0in 5.4pt 0in 5.4pt; width: 142.2pt;&quot; valign=&quot;top&quot; width=&quot;190&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;-&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
  &lt;td style=&quot;background: #FFFFEF; border-bottom: none; border-left: solid black 1.5pt; border-right: solid black 1.5pt; border-top: none; mso-pattern: gray-20 yellow; mso-shading: white; padding: 0in 5.4pt 0in 5.4pt; width: 1.9in;&quot; valign=&quot;top&quot; width=&quot;182&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;Startup time&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;background: #FFFFEF; border-right: solid black 1.5pt; border: none; mso-border-left-alt: solid black 1.5pt; mso-pattern: gray-20 yellow; mso-shading: white; padding: 0in 5.4pt 0in 5.4pt; width: 2.05in;&quot; valign=&quot;top&quot; width=&quot;197&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;~ 60 seconds&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;background: #FFFFEF; border-right: solid black 1.5pt; border: none; mso-border-left-alt: solid black 1.5pt; mso-pattern: gray-20 yellow; mso-shading: white; padding: 0in 5.4pt 0in 5.4pt; width: 142.2pt;&quot; valign=&quot;top&quot; width=&quot;190&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;3 seconds&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
  &lt;td style=&quot;background: #FFFFEF; border-bottom: none; border-left: solid black 1.5pt; border-right: solid black 1.5pt; border-top: none; mso-pattern: gray-20 yellow; mso-shading: white; padding: 0in 5.4pt 0in 5.4pt; width: 1.9in;&quot; valign=&quot;top&quot; width=&quot;182&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;Camera&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;background: #FFFFEF; border-right: solid black 1.5pt; border: none; mso-border-left-alt: solid black 1.5pt; mso-pattern: gray-20 yellow; mso-shading: white; padding: 0in 5.4pt 0in 5.4pt; width: 2.05in;&quot; valign=&quot;top&quot; width=&quot;197&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;Useless&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;background: #FFFFEF; border-right: solid black 1.5pt; border: none; mso-border-left-alt: solid black 1.5pt; mso-pattern: gray-20 yellow; mso-shading: white; padding: 0in 5.4pt 0in 5.4pt; width: 142.2pt;&quot; valign=&quot;top&quot; width=&quot;190&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;-&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
  &lt;td style=&quot;background: #FFFFEF; border-bottom: none; border-left: solid black 1.5pt; border-right: solid black 1.5pt; border-top: none; mso-pattern: gray-20 yellow; mso-shading: white; padding: 0in 5.4pt 0in 5.4pt; width: 1.9in;&quot; valign=&quot;top&quot; width=&quot;182&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;SMS&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;background: #FFFFEF; border-right: solid black 1.5pt; border: none; mso-border-left-alt: solid black 1.5pt; mso-pattern: gray-20 yellow; mso-shading: white; padding: 0in 5.4pt 0in 5.4pt; width: 2.05in;&quot; valign=&quot;top&quot; width=&quot;197&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;Mixes up SMSs, can’t
  find the latest&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;background: #FFFFEF; border-right: solid black 1.5pt; border: none; mso-border-left-alt: solid black 1.5pt; mso-pattern: gray-20 yellow; mso-shading: white; padding: 0in 5.4pt 0in 5.4pt; width: 142.2pt;&quot; valign=&quot;top&quot; width=&quot;190&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;Good, logical sorting&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
  &lt;td style=&quot;background: #FFFFEF; border-top: none; border: solid black 1.5pt; mso-pattern: gray-20 yellow; mso-shading: white; padding: 0in 5.4pt 0in 5.4pt; width: 1.9in;&quot; valign=&quot;top&quot; width=&quot;182&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;i&gt;&lt;span style=&quot;font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;Price&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;background: #FFFFEF; border-bottom: solid black 1.5pt; border-left: none; border-right: solid black 1.5pt; border-top: none; mso-border-left-alt: solid black 1.5pt; mso-pattern: gray-20 yellow; mso-shading: white; padding: 0in 5.4pt 0in 5.4pt; width: 2.05in;&quot; valign=&quot;top&quot; width=&quot;197&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;480 Euros&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;td style=&quot;background: #FFFFEF; border-bottom: solid black 1.5pt; border-left: none; border-right: solid black 1.5pt; border-top: none; mso-border-left-alt: solid black 1.5pt; mso-pattern: gray-20 yellow; mso-shading: white; padding: 0in 5.4pt 0in 5.4pt; width: 142.2pt;&quot; valign=&quot;top&quot; width=&quot;190&quot;&gt;&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;garamond&amp;quot;;&quot;&gt;20 Euros&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;br /&gt;
The latest experience was something reminding an &lt;i&gt;opera buffa. &lt;/i&gt;I moved from the Netherlands to Romania and I adjusted the time (it&#39;s one hour later in Romania). It was the night of daylight saving time, so I knew the time would be set one extra hour ahead. I did that manually and I specifically instructed the smart a$$ to not automatically adjust the time settings. After that I set the alarm clock at 7 am and I went to bed. I woke up with the alarm ringing loud, I stopped it and - after the usual swears - I rushed out. But I got a hunch: why was it so dark outside ? I turned on the TV to notice it was 6 am. So my smart .... whatever .... managed to set the time again one hour ahead, even though I had specifically instructed it not to do that ....&lt;br /&gt;
&lt;br /&gt;
Did I mention than when I change the countries, my smart .... thing .... changes the language automatically ? When I move among FR, DE, NL, UK, IT, ES, PT, RO, etc. this is usually not a problem, but what am I gonna do in China or Israel or some Arabic country ? I wouldn&#39;t even be able to set the language back to English.&lt;br /&gt;
Anybody needs a smartphone ?&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;

&lt;i style=&quot;font-weight: normal;&quot;&gt;Update 1: Some people would say &quot;get an iPhone, man&quot;. Possibly, for what you pay it should be a class above the other smart a$$es.&lt;/i&gt;
&lt;/h4&gt;
&lt;br /&gt;
&lt;h4&gt;

&lt;i style=&quot;font-weight: normal;&quot;&gt;Update 2: &lt;a href=&quot;https://www.fastcodesign.com/90165365/smartphones-are-wrecking-the-planet-faster-than-anyone-expected&quot;&gt;Smartphones are wrecking the planet ....&lt;/a&gt;&lt;/i&gt;
&lt;/h4&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/1664246299749825767/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2012/05/smart-phone-yeah-right.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/1664246299749825767'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/1664246299749825767'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2012/05/smart-phone-yeah-right.html' title='Smart phone ? Yeah, right ....'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQlFi8OApp5BwlEXjwZHpGIpnRkWEDT-SyIGt-62XDmP1JhIMDOMoh8gPCs7Rs8KinnQhcdfPbrKZXhkmDWplqRtEfDbgmTq9LgXK509oKt2SH3Nw_TIXl57pdvuLX3PjaAwmFS6dfS28/s72-c/lgnokia.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-3735689888074578301</id><published>2011-12-11T09:50:00.000-08:00</published><updated>2011-12-11T12:08:21.496-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="dojo"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="pet store"/><title type='text'>Java Pet Store 2.0 - the architecture (part 1)</title><content type='html'>To my surprise, the Java Pet Store 2.0 &lt;a href=&quot;http://java.sun.com/developer/technicalArticles/J2EE/petstore/&quot;&gt;page&lt;/a&gt;, even though recently updated, still doesn&#39;t mention much about the design of the application.&lt;br /&gt;
So here we go, below you find some diagrams and explanations over how it&#39;s built and how it works. I&#39;ll continue the story in future posts, here I start with the overview and show how the catalog gets displayed.&lt;br /&gt;
&lt;br /&gt;
First, check out this part of the web.xml file:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&amp;lt;servlet&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;display-name&amp;gt;ControllerServlet&amp;lt;/display-name&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;servlet-name&amp;gt;ControllerServlet&amp;lt;/servlet-name&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;servlet-class&amp;gt;com.sun.javaee.blueprints.petstore.controller.ControllerServlet&amp;lt;/servlet-class&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/servlet&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;lt;servlet-mapping&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;servlet-name&amp;gt;ControllerServlet&amp;lt;/servlet-name&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;url-pattern&amp;gt;/catalog&amp;lt;/url-pattern&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/servlet-mapping&amp;gt;&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;div&gt;It tells that the ControllerServlet needs to be used for URLs that match the pattern &quot;/catalog&quot;.&lt;/div&gt;&lt;div&gt;For example, when following the link &quot;Dogs&quot; on the main page, we navigate to:&lt;/div&gt;&lt;div&gt;&lt;a href=&quot;http://localhost:8087/petstore/faces/catalog.jsp?catid=Dogs&quot;&gt;http://localhost:8087/petstore/faces/catalog.jsp?catid=Dogs&lt;/a&gt;&lt;br /&gt;
(I have &lt;b&gt;Glassfish&lt;/b&gt; running on localhost:8087)&lt;/div&gt;&lt;div&gt;Since this matches the &quot;/catalog&quot; pattern, ControllerServlet.service() is triggered, as shown in Figure 2.&lt;/div&gt;&lt;div&gt;The ControllerServlet implements the FrontController J2EE pattern and delegates to various actions (see Figure 1 and Figure 2), depending on the servlet path. In this case the servlet path is &quot;/catalog&quot; and it maps to CatalogXmlAction. The latter reads the &quot;command&quot; parameter from the request and, because this one is &quot;categories&quot;, it calls the CatalogFacade to get the categories via JPA (note in Figure 1 that &quot;Category&quot; is a JPA Entity).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv0yJrteZ5nF8Ldb4H1isZTHHXdiNvbXU_cqZjdrS31qJVltsTL9mHKnp4FuNRUzckX11rk-EQzIsegUSdlTQqCugayYXayRWmC20ub80QOaDMEw6Thiz-DXPSLS4wtdiCc0NlO5GHBFw/s1600/entitiesCatalog.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;255&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv0yJrteZ5nF8Ldb4H1isZTHHXdiNvbXU_cqZjdrS31qJVltsTL9mHKnp4FuNRUzckX11rk-EQzIsegUSdlTQqCugayYXayRWmC20ub80QOaDMEw6Thiz-DXPSLS4wtdiCc0NlO5GHBFw/s400/entitiesCatalog.PNG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;Figure 1: The main entities involved in fetching the catalog&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSbJXGz13nmp3LPzBLmeCXIGoAoSB2dFBaZxySJFZDebPV7cZlCj7qhyphenhyphenELuV3p5hEKd6ANCaS5Rr28Sl3mwzO2JtlJdngB-p7JzuCAaq1KyMS2RkLrvwF_atB0RSthH7cGbTnOqGG1IzY/s1600/showCatalog.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;248&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSbJXGz13nmp3LPzBLmeCXIGoAoSB2dFBaZxySJFZDebPV7cZlCj7qhyphenhyphenELuV3p5hEKd6ANCaS5Rr28Sl3mwzO2JtlJdngB-p7JzuCAaq1KyMS2RkLrvwF_atB0RSthH7cGbTnOqGG1IzY/s400/showCatalog.PNG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;Figure 2: Displaying the catalog&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;The CatalogXml action, once it has the categories, it writes them to the response (HttpServletResponse) in JSON format (see below).&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;So how come, given this JSON format, the categories and the pets are so nicely displayed in the page (see Figure 3) still ? &amp;nbsp;Well, this is done with a bit of Dojo/JavaScript magic.&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;/div&gt;&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;[{&quot;id&quot;:&quot;CATS&quot;,&quot;catid&quot;:&quot;CATS&quot;,&quot;name&quot;:&quot;Cats&quot;,&quot;description&quot;:&quot;Loving and finicky friends&quot;,&quot;imageURL&quot;:&quot;cats_icon.gif&quot;,
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&quot;products&quot;: [{&quot;id&quot;:&quot;feline01&quot;,&quot;catid&quot;:&quot;CATS&quot;,&quot;name&quot;:&quot;Hairy Cat&quot;,&quot;description&quot;:&quot;Great for reducing mouse populations&quot;,&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&quot;imageURL&quot;:&quot;cat1.gif&quot;},{&quot;id&quot;:&quot;feline02&quot;,&quot;catid&quot;:&quot;CATS&quot;,&quot;name&quot;:&quot;Groomed Cat&quot;,&quot;description&quot;:&quot;Friendly house cat keeps you&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;away from the vacuum&quot;,&quot;imageURL&quot;:&quot;cat2.gif&quot;}]},&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;etc.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;]&lt;/div&gt;&lt;/code&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;code&gt;&lt;/code&gt;&lt;/div&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKVokAPm6HrAc4IqcbeiDNCXh-FplPeK5QJAw5A4Z-mxaw_Q0cHdm8hOXh2v0hR-zBugGuEnRAxpYV23IaKH_muEIfljJsz4aoR3fwnIhPAOfAZ7L9eLATQCxmdDgmKlCtve4RWIfhObA/s1600/petStore.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;285&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKVokAPm6HrAc4IqcbeiDNCXh-FplPeK5QJAw5A4Z-mxaw_Q0cHdm8hOXh2v0hR-zBugGuEnRAxpYV23IaKH_muEIfljJsz4aoR3fwnIhPAOfAZ7L9eLATQCxmdDgmKlCtve4RWIfhObA/s400/petStore.PNG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;Figure 3: The Pet Store application - after choosing the categories&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;Take a look at catalog.js, which is used in catalog.jsp to format the page:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;function loadAccordion () {&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // go out and get the categories&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // this should be made more geric&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var bindArgs = {&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; url: &amp;nbsp;applicationContextRoot + &quot;/catalog?command=categories&amp;amp;format=json&quot;,&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mimetype: &quot;text/json&quot;,&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; load: function(type,json) {&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ac.load(json);&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;processURLParameters();&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;},&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;error: ajaxBindError&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; };&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dojo.io.bind(bindArgs);&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;/code&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;code&gt;&lt;/code&gt;&lt;/div&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;This method is called from initCatalog() in catalog.js, which in turn is called in catalog.jsp:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;/div&gt;&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; dojo.event.connect(window, &quot;onload&quot;, function(){initCatalog();});&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;lt;/script&amp;gt;&lt;/div&gt;&lt;/code&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;code&gt;&lt;/code&gt;&lt;/div&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;Finally, &lt;b&gt;loadAccordion()&lt;/b&gt; calls&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #eeeeee; font-family: monospace; font-size: 12px; line-height: 14px; white-space: pre;&quot;&gt;ac.load(json)&lt;/span&gt;&amp;nbsp;and ac.showCategory(params.catid), where &quot;ac&quot; is AccordionMenu() (the menu with categories in Figure 3), which again, sends us to:&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;this.load = function(lcategories) {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; categories = lcategories;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // create all the rows
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (var l=0; l &amp;amp;lt; categories.length; l++) {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var row = createRow(l,&quot;accordionRow&quot;, ITEM_HEIGHT);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; createLinks(row.div, categories[l].name, l, &quot;accordionLink&quot;);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; divs.push(row);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }
&amp;nbsp; &amp;nbsp; }&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
Here, createLinks() makes the links on the left-hand side menu (&quot;Cats&quot;, &quot;Dogs&quot;, etc.), using &lt;i&gt;categories[l].name&lt;/i&gt; as parameter. &quot;Categories&quot; come from the JSON shown above, retrieved in loadAccordion():&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;background-color: #eeeeee; font-family: monospace; font-size: 12px; line-height: 14px; white-space: pre;&quot;&gt;url: &amp;nbsp;applicationContextRoot + &quot;/catalog?command=categories&amp;amp;format=json&quot;.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;this.showCategory = function(catid) {
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (var l=0; l &amp;lt; categories.length; l++) {&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (catid == categories[l].name) {&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // now tell the scroller to load the first product&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; initiateExpansion(l);&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (categories[l].products[0]) {&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dojo.event.topic.publish(&quot;/catalog&quot;, {type:&quot;showProducts&quot;, productId:categories[l].products[0].id});&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;/code&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;code&gt;&lt;/code&gt;&lt;/div&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;Notice here &quot;type&quot; and &quot;productId&quot; labels. Back in catalog.js, we do:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;/div&gt;&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;dojo.event.topic.subscribe(&quot;/catalog&quot;, this, handleEvent);&lt;/code&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;code&gt;&lt;/code&gt;&lt;/div&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;So here we subscribe to the &quot;/catalog&quot; events with the callback &quot;handleEvent&quot;, which does:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;/div&gt;&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;else if (args.type == &quot;showProducts&quot;) {
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; is.reset();&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; populateItems(args.productId, 0, 0, true);&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;&lt;/code&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;code&gt;&lt;/code&gt;&lt;/div&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;Here, args.type is the label &quot;type&quot; we published above and args.productId is the label &quot;productId&quot;. With the argument args.productId, &quot;populateItems()&quot; displays the images, etc. In order to do that, it uses DOM fields from catalog.jsp, e.g.:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;var targetElement = document.getElementById(&quot;bodySpace&quot;);&lt;/code&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;code&gt;&lt;/code&gt;&lt;/div&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;To be continued ....&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/3735689888074578301/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2011/12/java-pet-store-20-architecture-part-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/3735689888074578301'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/3735689888074578301'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2011/12/java-pet-store-20-architecture-part-1.html' title='Java Pet Store 2.0 - the architecture (part 1)'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv0yJrteZ5nF8Ldb4H1isZTHHXdiNvbXU_cqZjdrS31qJVltsTL9mHKnp4FuNRUzckX11rk-EQzIsegUSdlTQqCugayYXayRWmC20ub80QOaDMEw6Thiz-DXPSLS4wtdiCc0NlO5GHBFw/s72-c/entitiesCatalog.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-2201602768894727125</id><published>2011-07-25T04:36:00.000-07:00</published><updated>2011-07-25T04:36:44.503-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="cow"/><category scheme="http://www.blogger.com/atom/ns#" term="tomato"/><title type='text'>The computer and the cow</title><content type='html'>Isn&#39;t it ironic that nowadays we try to specialize and super-specialize to learn how to program computers and send people into the space, while we should be learning how to milk the cow and grow tomatoes ?</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/2201602768894727125/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2011/07/computer-and-cow.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/2201602768894727125'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/2201602768894727125'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2011/07/computer-and-cow.html' title='The computer and the cow'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-8669548894016958907</id><published>2011-05-22T02:28:00.000-07:00</published><updated>2011-05-29T09:52:13.735-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="MySQL"/><category scheme="http://www.blogger.com/atom/ns#" term="scalability"/><title type='text'>MySQL Scalability</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;When it comes to scaling MySQL (and in fact scaling DBs in general), Cal Henderson in his excellent book &lt;b&gt;&quot;Building Scalable Web Sites&quot;&lt;/b&gt; makes a concise summary:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;1. For limited nonlinear read capacity scaling, we can use MySQL&#39;s &lt;b&gt;replication &lt;/b&gt;system&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;2. For architectural linear scaling, we can go:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&amp;nbsp; &amp;nbsp; a. vertical, and partition our table space into &lt;b&gt;clusters&lt;/b&gt;, or&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&amp;nbsp; &amp;nbsp; b. horizontal, and partition our data into &lt;b&gt;shards&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;A bit more details follow.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;1. With &lt;i&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;replication&lt;/span&gt;&lt;/i&gt;, basically data (e.g. the whole database) is replicated among multiple machines. This is done to have multiple sources to read from, i.e. it&#39;s a method used to enhance &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;scalability of reads&lt;/span&gt;. For a typical web application, where the number of reads is 10-100 times larger than the number of writes, this might be good enough.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;2. If we want good &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;scalability of writes and reads&lt;/span&gt;, we need to split data into pieces, such that several write operations are possible in parallel (e.g. each write happening on a piece of data, independent from the other writes). We can split the data in two ways:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;a. &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Clustering &lt;/span&gt;(vertical partitioning): each chunk of split data contains a subset of your tables; this chunk is called cluster and it can be organized as you wish: a single machine or again, data can be replicated (see 1) on multiple machines with master-slave or master-master relationships.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;b. &lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #cc0000;&quot;&gt;Federation &lt;/span&gt;(horizontal partitioning): each chunk of data contains a part of a table; for example suppose we split our table USERS by the username column: users go into different chunks based on the first letter of the username. Such a chunk of data and the machines behind them are called shards.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;u&gt;Pitfall&lt;/u&gt;: queries that need data in several shards&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;u&gt;To avoid it&lt;/u&gt;: make sure that all records you need to fetch reside on the same shard. In some cases this is difficult, because one query will be able to use data on a single shard, but another query might involve the same data as the first, plus some other data on a different shard. A solution to this is denormalization: we store data on both shards (so we have duplication) in existing, normalized tables and in new, denormalized tables.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Of course another issue here is to synchronize the duplicated data, in order to avoid inconsistencies. But that&#39;s yet another chapter in the long history of designing for performance.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/8669548894016958907/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2011/05/mysql-scalability.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/8669548894016958907'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/8669548894016958907'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2011/05/mysql-scalability.html' title='MySQL Scalability'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-805929804143223665</id><published>2011-04-02T11:24:00.000-07:00</published><updated>2011-04-02T11:25:50.733-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="eclipse"/><title type='text'>Eclipse tips and tricks (episode)</title><content type='html'>Whenever you have a JSP page opened in Eclipse, the standard editor, called &lt;b&gt;JSP Editor&lt;/b&gt;&amp;nbsp;is not very fancy. However, do mouse right-click on the file name and choose &lt;b&gt;Web Page Editor&lt;/b&gt;. The result is much more interesting, since it shows you the look and feel (Design tab) of the page as well as the source code. In the top-right corner of the window you have the Palette, which enables fast design by drag-and-dropping controls to the page. More to the right you have the Outline window, which allows you to select any tag of the page and add attributes to it.&lt;br /&gt;
This is similar to the powerful Oracle JDeveloper&#39;s editor.&lt;br /&gt;
&lt;br /&gt;
Next figure illustrates the Web Page Editor in Eclipse.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRXuRKOZ5j76vqrYMy_e50jeMlxGbYIVtcgDeVEtVt3KZYJOvUwrN85YZQvSROiCNPj8hNRoFBvR1ObfuSs8jFhmiYK_eBjjqB2806RaYJupbh1GKH9SWkGPbWrneUni4z2M1z47Hcttw/s1600/eclipseWebEditor2.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;
&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRXuRKOZ5j76vqrYMy_e50jeMlxGbYIVtcgDeVEtVt3KZYJOvUwrN85YZQvSROiCNPj8hNRoFBvR1ObfuSs8jFhmiYK_eBjjqB2806RaYJupbh1GKH9SWkGPbWrneUni4z2M1z47Hcttw/s1600/eclipseWebEditor2.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;207&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRXuRKOZ5j76vqrYMy_e50jeMlxGbYIVtcgDeVEtVt3KZYJOvUwrN85YZQvSROiCNPj8hNRoFBvR1ObfuSs8jFhmiYK_eBjjqB2806RaYJupbh1GKH9SWkGPbWrneUni4z2M1z47Hcttw/s400/eclipseWebEditor2.PNG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/805929804143223665/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2011/04/eclipse-tips-and-tricks-episode.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/805929804143223665'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/805929804143223665'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2011/04/eclipse-tips-and-tricks-episode.html' title='Eclipse tips and tricks (episode)'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRXuRKOZ5j76vqrYMy_e50jeMlxGbYIVtcgDeVEtVt3KZYJOvUwrN85YZQvSROiCNPj8hNRoFBvR1ObfuSs8jFhmiYK_eBjjqB2806RaYJupbh1GKH9SWkGPbWrneUni4z2M1z47Hcttw/s72-c/eclipseWebEditor2.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-6956274458756174302</id><published>2011-03-31T14:40:00.001-07:00</published><updated>2011-03-31T14:47:04.906-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Java Forever</title><content type='html'>What else can I add ?&lt;br /&gt;
&lt;br /&gt;
&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;390&quot; src=&quot;http://www.youtube.com/embed/kLO1djacsfg&quot; title=&quot;YouTube video player&quot; width=&quot;540&quot;&gt;&lt;/iframe&gt;</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/6956274458756174302/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2011/03/java-forever.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/6956274458756174302'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/6956274458756174302'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2011/03/java-forever.html' title='Java Forever'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/kLO1djacsfg/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-1729131922466853963</id><published>2010-12-09T14:34:00.000-08:00</published><updated>2010-12-09T14:34:50.852-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="google maps"/><category scheme="http://www.blogger.com/atom/ns#" term="multithreading"/><title type='text'>Threads and Web Applications</title><content type='html'>Say you have a standalone (non-web) application where you want to show images. Suppose the images don&#39;t have dependencies among each other, so you can load and show each image in a separate thread.&lt;br /&gt;
Now say you want to design the same thing as a &lt;b&gt;web application&lt;/b&gt;. To make things more concrete, suppose you want to build an application that shows a map of a region as a set (matrix) of tiles, each tile being displayed in a certain, predetermined part of the viewer. Let&#39;s call this application randomly &#39;&lt;i&gt;google maps&lt;/i&gt;&#39;.&lt;br /&gt;
So we&#39;ll have a servlet - say we build this with Java technology - that talks to a certain service from which it gets the corresponding tiles and then generates the page showing these tiles in their proper positions. It is tempting to take the same approach as in the standalone application and let the servlet run threads, each of them dealing with a tile. However, we know running threads from servlets calls for trouble (I&#39;ll write about that in separate posts).&lt;br /&gt;
&lt;br /&gt;
So, what to do ? Well, the idea is to &lt;b&gt;run the requests for the tiles in parallel as Ajax requests &lt;/b&gt;from - for example, a JavaScript piece of code residing in a JSP page. Each such Ajax request invokes the servlet to retrieve the desired tile. Thus, the servlet remains &quot;pure&quot;, unpolluted with dangerous threads and we leave the parallelism and all the other optimizations in the hands of the web container.</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/1729131922466853963/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2010/12/threads-and-web-applications.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/1729131922466853963'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/1729131922466853963'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2010/12/threads-and-web-applications.html' title='Threads and Web Applications'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-4940455944299765215</id><published>2010-11-21T13:56:00.000-08:00</published><updated>2011-04-10T12:17:32.255-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="debug"/><category scheme="http://www.blogger.com/atom/ns#" term="eclipse"/><category scheme="http://www.blogger.com/atom/ns#" term="Glassfish"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="pet store"/><title type='text'>Debugging Java PetStore with Glassfish and Eclipse</title><content type='html'>Once I made &lt;a href=&quot;http://sorincalex.blogspot.com/2010_09_01_archive.html&quot;&gt;PetStore work in Glassfish&lt;/a&gt;, I wanted to debug it in Eclipse.&lt;br /&gt;
&lt;br /&gt;
1. I ran asadmin in my application server path:&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;C:\J2EE\Sun\AppServer\bin&amp;gt;asadmin start-domain&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
2. In the browser, I ran the application server Admin Console, available in my case at &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;localhost:4848&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
3. I went to Application Server menu (top left), I chose &lt;b&gt;JVM Settings&lt;/b&gt; and I enabled &lt;b&gt;Debug&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
4. I restarted the Application Server (after enabling Debug and saving this configuration, I noticed the link &quot;&lt;i&gt;Restart needed&lt;/i&gt;&quot; top left; I clicked on it, after that I ran&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;asadmin start-domain&lt;/span&gt; from the console)&lt;br /&gt;
&lt;br /&gt;
5. I also ran &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;asadmin start-database &lt;/span&gt;to start the database for PetStore&lt;br /&gt;
&lt;br /&gt;
6. I started Eclipse (I use version 3.4.1); under &lt;b&gt;Run &lt;/b&gt;menu, I chose &quot;&lt;b&gt;Debug configurations ....&lt;/b&gt;&quot;; then I chose the PetStore project (which I had created previously in Eclipse) and port &lt;b&gt;9009 &lt;/b&gt;(the default port where Glassfish is listening for debuggers); I also enabled &quot;&lt;b&gt;Allow termination of remote VM&lt;/b&gt;&quot;&lt;br /&gt;
&lt;br /&gt;
7. Just for the test, I put a breakpoint in &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;ImageAction.java&lt;/span&gt;, method &lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;service&lt;/span&gt;; then I started the debug configuration created at bullet 6; finally, I navigated in a browser to&lt;br /&gt;
&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;http://localhost:8087/petstore/faces/catalog.jsp&lt;/span&gt;&lt;br /&gt;
and I clicked a dog under Pets;&amp;nbsp;I could see my breakpoint being hit.</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/4940455944299765215/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2010/11/debugging-java-petstore-with-glassfish.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/4940455944299765215'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/4940455944299765215'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2010/11/debugging-java-petstore-with-glassfish.html' title='Debugging Java PetStore with Glassfish and Eclipse'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-6905586848413919065</id><published>2010-10-20T13:56:00.000-07:00</published><updated>2010-10-21T06:26:47.650-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="ideal software company"/><title type='text'>Motivate me !</title><content type='html'>&lt;i&gt;&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&quot;Give me a place to stand on, and I will move the Earth.&quot; (Greek: δῶς μοι πᾶ στῶ καὶ τὰν γᾶν κινάσω)&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;Archimedes&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Let&#39;s take this scenario: you get hired by a seemingly good company, you get an apparently good job and you are very enthusistic about it. Slowly but surely the job becomes a demotivating and boring routine (pleonasm maybe, but I want to make it clear), and your enthusiasm drops. Sounds familiar ?&lt;br /&gt;
&lt;br /&gt;
Think about it: we are all different, each of us has a special &lt;b&gt;talent&lt;/b&gt;, some &lt;b&gt;desires&lt;/b&gt;, some &lt;b&gt;ideals&lt;/b&gt;. Wouldn&#39;t it be good to get a job in line with those ? A typical IT company employs people of different ages, backgrounds, nationalities, etc. Each of them is unique and can bring unique added value to the organization by employing her/his own, unique skills.&lt;br /&gt;
To me the ideal IT company shouldn&#39;t hire people to work on a given range of products. It should be the other way around: &lt;b&gt;the products of the company should be tailored to the employees&#39; desires, talents, affinities&lt;/b&gt;. Motivate the employees and surely you&#39;ll have a win-win situation. As a company you have to create products and services that your employees love to build/develop/provide. Give them motivation and they will move the Earth.&lt;br /&gt;
&lt;br /&gt;
I have yet to find such a company. Maybe it hasn&#39;t been invented yet, but if you know of any which gets close to my dream, please let me know.</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/6905586848413919065/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2010/10/motivate-me.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/6905586848413919065'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/6905586848413919065'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2010/10/motivate-me.html' title='Motivate me !'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-6381027884450335596</id><published>2010-09-05T13:18:00.000-07:00</published><updated>2011-04-10T12:17:53.734-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Glassfish"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="pet store"/><title type='text'>Making Java PetStore work</title><content type='html'>&lt;span id=&quot;goog_510773952&quot;&gt;&lt;/span&gt;&lt;span id=&quot;goog_510773953&quot;&gt;&lt;/span&gt;Recently I&#39;ve been struggling with making the Pet Store 2.0 application work.&lt;br /&gt;
So, shortly, what I&#39;ve done:&lt;br /&gt;
- &amp;nbsp;downloaded the jar from &lt;a href=&quot;https://blueprints.dev.java.net/petstore/&quot;&gt;https://blueprints.dev.java.net/petstore/&lt;/a&gt;&lt;br /&gt;
- &amp;nbsp;downloaded Glassfish v2.1.1 from &lt;a href=&quot;https://glassfish.dev.java.net/&quot;&gt;https://glassfish.dev.java.net/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Then I tried to deploy and run the Pet Store by running the following commands:&lt;br /&gt;
- in the application server directory &lt;javaeesdk .home=&quot;&quot;&gt;/bin:&amp;nbsp;&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;b&gt;&lt;javaeesdk .home=&quot;&quot;&gt;asadmin start-domain&lt;br /&gt;
asadmin start-database&lt;/javaeesdk&gt;&lt;/b&gt;&lt;javaeesdk .home=&quot;&quot;&gt;&lt;br /&gt;
- in the Pet Store demo directory C:\J2EE\PetStore\latest\javapetstore-2.0-ea5:&lt;br /&gt;
&lt;b&gt;ant setup&lt;br /&gt;
ant run&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Even though all commands were successful, the application won&#39;t start. More specifically I got the error &quot;&lt;i&gt;The requested resource () is not available&lt;/i&gt;&quot; when navigating to&lt;i&gt; http://localhost:8087/petstore&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
So, without further ado, these are the steps I&#39;ve performed to make it work.&lt;br /&gt;
&lt;br /&gt;
&lt;b style=&quot;color: red;&quot;&gt;1.&lt;/b&gt; in C:\J2EE\PetStore\latest\javapetstore-2.0-ea5\bp-project\&lt;b&gt;build.properties&lt;/b&gt; I corrected the following variables:&lt;br /&gt;
a. &lt;i&gt;javaee.home&lt;/i&gt; to point to my application server: &lt;i&gt;c:/J2EE/Sun/AppServer&lt;/i&gt;&lt;br /&gt;
b. &lt;i&gt;javaee.server.username&lt;/i&gt; to point to my username (the one I used when I installed Glassfish)&lt;br /&gt;
c. &lt;i&gt;javaee.server.passwordfile&lt;/i&gt; to point to &lt;i&gt;${javaee.home}/samples/passwordfile&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b style=&quot;color: red;&quot;&gt;2.&lt;/b&gt; I created the file &quot;passwordfile&quot; under&amp;nbsp;&lt;i&gt;c:/J2EE/Sun/AppServer/samples&lt;/i&gt; containing a single line:&lt;br /&gt;
&amp;nbsp;&lt;i&gt;AS_ADMIN_PASSWORD=myPassword&lt;/i&gt; (the password I chose when I installed Glassfish)&lt;br /&gt;
&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;javaeesdk .home=&quot;&quot;&gt;&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;javaeesdk .home=&quot;&quot;&gt;&lt;b style=&quot;color: red;&quot;&gt;3.&lt;/b&gt; I also updated the file &lt;b&gt;app-server.properties&lt;/b&gt; in &lt;/javaeesdk&gt;C:\J2EE\PetStore\latest\javapetstore-2.0-ea5\bp-project with &lt;i&gt;javaee.home=c:/J2EE/Sun/AppServer&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;javaeesdk .home=&quot;&quot;&gt; At this point, I got the Pet Store demo running on the Glassfish server (after running again &quot;&lt;i&gt;ant setup&lt;/i&gt;&quot; and &quot;&lt;i&gt;ant run&lt;/i&gt;&quot;). However, only the first page was properly shown (&lt;i&gt;http://localhost:8087/petstore/&lt;/i&gt;) and as soon as I navigated to &quot;Enter the Store&quot; (&lt;i&gt;http://localhost:8087/petstore/faces/index.jsp&lt;/i&gt;), I saw a blank page.&lt;br /&gt;
&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;javaeesdk .home=&quot;&quot;&gt;&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;javaeesdk .home=&quot;&quot;&gt;&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;javaeesdk .home=&quot;&quot;&gt;Note: instead of running &quot;ant run&quot;, you can also deploy the &lt;i&gt;petstore.war &lt;/i&gt;from the /dist directory (or from /build) by using the Glassfish admin console:&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6yjUbze4FNkl7hJW9H_rBFpNwlADV3dKlDHqe_XQ12OeqZqorefImeORgRd-Jnncswm09Qi7XKI27tmPPs4UFn2kibpcdpxy3BSdxIRKkTcnzULf3Nz4SXQbhjj_MBawYCjNvBFhLtqc/s1600/connectionPool4.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6yjUbze4FNkl7hJW9H_rBFpNwlADV3dKlDHqe_XQ12OeqZqorefImeORgRd-Jnncswm09Qi7XKI27tmPPs4UFn2kibpcdpxy3BSdxIRKkTcnzULf3Nz4SXQbhjj_MBawYCjNvBFhLtqc/s1600/connectionPool4.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;161&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6yjUbze4FNkl7hJW9H_rBFpNwlADV3dKlDHqe_XQ12OeqZqorefImeORgRd-Jnncswm09Qi7XKI27tmPPs4UFn2kibpcdpxy3BSdxIRKkTcnzULf3Nz4SXQbhjj_MBawYCjNvBFhLtqc/s400/connectionPool4.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;javaeesdk .home=&quot;&quot;&gt;&lt;br /&gt;
&amp;nbsp;&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;javaeesdk .home=&quot;&quot;&gt;By looking at the logging of the &quot;ant setup&quot; command I noticed that there was some issue with the username/password when trying to install the connection pool. I could also see this by inspecting the Glassfish log files (in the admin console, at &lt;i&gt;http://localhost:4848/&lt;/i&gt;). So, I&#39;ve done the following:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;4.&lt;/span&gt;&lt;/b&gt; instead of relying on the ant script to install the connection pool and the data source (i.e. the &lt;i&gt;ant setup&lt;/i&gt; command), I installed them by hand using the Glassfish admin console; see below the general properties of the connection pool:&lt;br /&gt;
&lt;br /&gt;
&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxUCXgB1BA1r91P1q9ShWsYnUILxQHZLzSRTX7XZaBRQnEnk1NerIAi3-AbqS7uDhdkmVnMzQTZZZbG-zm1UGOMZ7RnCFuDhFjbYu8Xutu6y9fVA-YlkIPSsW6qMtL9AEKl8VrGkloJVM/s1600/connectionPool.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxUCXgB1BA1r91P1q9ShWsYnUILxQHZLzSRTX7XZaBRQnEnk1NerIAi3-AbqS7uDhdkmVnMzQTZZZbG-zm1UGOMZ7RnCFuDhFjbYu8Xutu6y9fVA-YlkIPSsW6qMtL9AEKl8VrGkloJVM/s400/connectionPool.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;javaeesdk .home=&quot;&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;javaeesdk .home=&quot;&quot;&gt;Also, note the &quot;Additional Properties&quot;:&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMYkO5YUw-QBxtnFs7KQBYabLr70dzg_c4b-Mirs5876tvpZWWgsw6tKVRE4qvHk0V8sJwKJueaECJ5hBVfDjLweb2RbUgjMx9LrwL8pGbCeLgYBjee_H4jTGcwKgm99DPHf_tIGyjCv0/s1600/connectionPool2.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;197&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMYkO5YUw-QBxtnFs7KQBYabLr70dzg_c4b-Mirs5876tvpZWWgsw6tKVRE4qvHk0V8sJwKJueaECJ5hBVfDjLweb2RbUgjMx9LrwL8pGbCeLgYBjee_H4jTGcwKgm99DPHf_tIGyjCv0/s400/connectionPool2.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;javaeesdk .home=&quot;&quot;&gt;&lt;br /&gt;
&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;javaeesdk .home=&quot;&quot;&gt;Here I had to add the following properties:&amp;nbsp;&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;javaeesdk .home=&quot;&quot;&gt;- &lt;i&gt;Password &lt;/i&gt;with the value &lt;i&gt;APP&lt;/i&gt; (I know this from the file &lt;/javaeesdk&gt;&lt;i&gt;app-server.properties&lt;/i&gt;, see 3), &lt;br /&gt;
&lt;javaeesdk .home=&quot;&quot;&gt;- &lt;i&gt;DatabaseName &lt;/i&gt;with the value &lt;i&gt;petstore &lt;/i&gt;(I found this by googling the web)&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;javaeesdk .home=&quot;&quot;&gt;At this point if you click &lt;i&gt;Ping &lt;/i&gt;under the &lt;i&gt;General &lt;/i&gt;tab, you should get the message &quot;Ping succeeded&quot;.&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;javaeesdk .home=&quot;&quot;&gt; &lt;/javaeesdk&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;javaeesdk .home=&quot;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;5.&lt;/span&gt;&lt;/b&gt; I also installed the data source (using the Glassfish admin console), which I called &lt;i&gt;jdbc/PetstoreDB&lt;/i&gt; (I know this from the &lt;i&gt;web.xml&lt;/i&gt; file&lt;res-ref-name&gt;&lt;/res-ref-name&gt;):&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWY8NGWj1eOvhaQYZtTF4CPPy_5zMAZiRI7lNJLoPtD-u-eQTTRzn_MIk2D6EL657etuPYxED6o16H9sLyeDX7x0K6AtbhvdNi_bgZbQU7szxS55-cgThtJyHFPu7eUIjrxdA7r1KGOoY/s1600/connectionPool3.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;222&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWY8NGWj1eOvhaQYZtTF4CPPy_5zMAZiRI7lNJLoPtD-u-eQTTRzn_MIk2D6EL657etuPYxED6o16H9sLyeDX7x0K6AtbhvdNi_bgZbQU7szxS55-cgThtJyHFPu7eUIjrxdA7r1KGOoY/s400/connectionPool3.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;javaeesdk .home=&quot;&quot;&gt;&lt;br /&gt;
&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;javaeesdk .home=&quot;&quot;&gt;&lt;br /&gt;
&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;javaeesdk .home=&quot;&quot;&gt;&lt;br /&gt;
&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;javaeesdk .home=&quot;&quot;&gt;&lt;br /&gt;
&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;javaeesdk .home=&quot;&quot;&gt;Finally, I could navigate to&lt;i&gt; http://localhost:8087/petstore/faces/index.jsp&lt;/i&gt; and got the Pet Store demo working properly ! (of course, don&#39;t forget to start the DB server and the application server by running:&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;b&gt;&lt;javaeesdk .home=&quot;&quot;&gt;asadmin start-domain&lt;br /&gt;
asadmin start-database &lt;/javaeesdk&gt;&lt;/b&gt;&lt;javaeesdk .home=&quot;&quot;&gt;) &lt;/javaeesdk&gt;&lt;br /&gt;
&lt;javaeesdk .home=&quot;&quot;&gt;&lt;/javaeesdk&gt;&lt;br /&gt;
&lt;javaeesdk .home=&quot;&quot;&gt; &lt;/javaeesdk&gt;&lt;br /&gt;
&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;div id=&quot;refHTML&quot;&gt;&lt;/div&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;div id=&quot;refHTML&quot;&gt;&lt;/div&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;div id=&quot;refHTML&quot;&gt;&lt;/div&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;div id=&quot;refHTML&quot;&gt;&lt;/div&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;div id=&quot;refHTML&quot;&gt;&lt;/div&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;div id=&quot;refHTML&quot;&gt;&lt;/div&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;div id=&quot;refHTML&quot;&gt;&lt;/div&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;div id=&quot;refHTML&quot;&gt;&lt;/div&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;div id=&quot;refHTML&quot;&gt;&lt;/div&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;div id=&quot;refHTML&quot;&gt;&lt;/div&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;div id=&quot;refHTML&quot;&gt;&lt;/div&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;div id=&quot;refHTML&quot;&gt;&lt;/div&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;div id=&quot;refHTML&quot;&gt;&lt;/div&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;div id=&quot;refHTML&quot;&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/6381027884450335596/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2010/09/making-java-petstore-work.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/6381027884450335596'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/6381027884450335596'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2010/09/making-java-petstore-work.html' title='Making Java PetStore work'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6yjUbze4FNkl7hJW9H_rBFpNwlADV3dKlDHqe_XQ12OeqZqorefImeORgRd-Jnncswm09Qi7XKI27tmPPs4UFn2kibpcdpxy3BSdxIRKkTcnzULf3Nz4SXQbhjj_MBawYCjNvBFhLtqc/s72-c/connectionPool4.JPG" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-1867393609264253139</id><published>2010-08-20T14:14:00.000-07:00</published><updated>2010-08-25T13:00:59.573-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".net"/><category scheme="http://www.blogger.com/atom/ns#" term="c#"/><category scheme="http://www.blogger.com/atom/ns#" term="debug"/><title type='text'>The evil debugger</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;Let&#39;s take a look at the following piece of C# code:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;pre class=&quot;CICodeFormatter&quot;&gt;&lt;code class=&quot;CICodeFormatter&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;1: &amp;nbsp;using System; 
2: &amp;nbsp;using System.Collections.Generic; 
3: &amp;nbsp;using System.Linq; 
4: &amp;nbsp;using System.Text;&amp;nbsp;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;CICodeFormatter&quot;&gt;&lt;code class=&quot;CICodeFormatter&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;
5: &amp;nbsp;namespace ConsoleApplication1 { 
6: &amp;nbsp; &amp;nbsp;class Program { 
7: &amp;nbsp; &amp;nbsp; &amp;nbsp;private string myString = null; 
8: &amp;nbsp; &amp;nbsp; &amp;nbsp;public string MyString { 
9: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;get { 
10: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (myString == null) { 
11: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;myString = &quot;Bad string&quot;; 
12: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;} 
13: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return myString; 
14: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;} 
15: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;set { 
16: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (myString == null) { 
17: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;myString = value; 
18: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;} 
19: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;} 
20: &amp;nbsp; &amp;nbsp; &amp;nbsp;} 
21: &amp;nbsp; &amp;nbsp; &amp;nbsp;public override string ToString() { 
22: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return MyString; 
23: &amp;nbsp; &amp;nbsp; &amp;nbsp;} 
24: &amp;nbsp; &amp;nbsp; &amp;nbsp;static void Main(string[] args) { 
25: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Program program = new Program(); 
26: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;program.MyString = &quot;Good string&quot;; 
27: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Console.WriteLine(program); 
28: &amp;nbsp; &amp;nbsp; &amp;nbsp;} 
29: &amp;nbsp; &amp;nbsp;} 
30: &amp;nbsp;} &amp;nbsp;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
The result, as you would expect should be &quot;&lt;b&gt;Good string&lt;/b&gt;&quot; written to the console. That is, when you run it from the command line.&lt;br /&gt;
Suppose I run it in Visual Studio .NET 2008 and I put a breakpoint at line 27 in the debugger. Then I debug the program, I reach line 27, I move to line 28 and the result is of course &quot;&lt;b&gt;Good string&lt;/b&gt;&quot;.&lt;br /&gt;
Let&#39;s put a breakpoint at line 26. You&#39;d say &quot;what does the breakpoint have to do with the result ?&quot; Well, it does, because in this case, &quot;&lt;b&gt;Bad string&lt;/b&gt;&quot; will be displayed. This is like Heisenberg principle (or the&amp;nbsp;&lt;a href=&quot;http://en.wikipedia.org/wiki/Observer_effect_(physics)&quot;&gt;observer effect&lt;/a&gt;), isn&#39;t it ? When we debug, we actually influence the result. &lt;i&gt;This is possible because when the breakpoint is set at line 26, MyString getter is executed and in effect myString is set to &quot;Bad string&quot;. &lt;/i&gt;After that trying to set myString to &quot;Good string&quot; can&#39;t succeed because in the setter the test (myString == null) is false. At line 27 ToString() is called, displaying of course &quot;&lt;b&gt;Bad string&lt;/b&gt;&quot;.&lt;br /&gt;
&lt;br /&gt;
The default behavior of the debugger in Visual Studio .NET 2008 is to evaluate the properties when the debugger hits them. Also, the ToString() method is called by default whenever you hover with the mouse pointer over an instance (like &quot;program&quot; in line 26).&lt;br /&gt;
You can disable these behaviors under Tools -&amp;gt; Options -&amp;gt; Debugging -&amp;gt; General.&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;It&#39;s good to know this, because as you can see, .NET properties and ToString() evaluation in VS.NET can give you lots of headaches.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/1867393609264253139/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2010/08/evil-debugger.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/1867393609264253139'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/1867393609264253139'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2010/08/evil-debugger.html' title='The evil debugger'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-4517498177270237878</id><published>2010-08-15T07:51:00.000-07:00</published><updated>2010-09-19T12:56:07.501-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="hibernate"/><category scheme="http://www.blogger.com/atom/ns#" term="OpenSessionInView"/><title type='text'>Hibernate: OpenSessionInView reloaded</title><content type='html'>In the&lt;a href=&quot;http://sorincalex.blogspot.com/2010/06/hibernate-opensessioninview-explained.html&quot;&gt; previous post&lt;/a&gt; regarding Hibernate, I&#39;ve shown how the &lt;i&gt;OpenSessionInView &lt;/i&gt;pattern can be implemented.&lt;br /&gt;
In short, the idea was that the transactional statements (CRUD operations with the database) happen in between the following lines:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;sf.getCurrentSession().beginTransaction();
....
sf.getCurrentSession().getTransaction().commit();&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
These lines are executed by a servlet filter, making thus sure that the Hibernate session is kept open until the view is rendered, and thus allowing us to use managed entities, as opposed to detached.&lt;br /&gt;
&lt;br /&gt;
However, there is still something about which we haven&#39;t talked yet: what happens in the real case, with several simultaneous requests to the servlet ? We know that servlets are multithreaded objects, i.e. multiple threads may call the servlet&#39;s methods at the same time. We also know that servlets are not thread safe, so we &amp;nbsp;have to pay attention to instance or class variables, which can be shared by several threads.&lt;br /&gt;
&lt;br /&gt;
In the case of the OpenSessionPerView pattern, note that&amp;nbsp;sf.getCurrentSession().beginTransaction()&amp;nbsp;may be called by several threads. This means that the result of&amp;nbsp;sf.getCurrentSession(), which is the current Session object, is shared among threads, which is dangerous since a Session is not a thread safe object. This asks for trouble, since the instance of Session is used to create queries and perform CRUD operations with the database.&lt;br /&gt;
&lt;br /&gt;
So how can we ensure a thread-safe behavior of the OpenSessionPerView pattern ? &lt;b&gt;ThreadLocal pattern&lt;/b&gt; to the rescue.&lt;br /&gt;
In a few words, what we need is a Session object per thread, which can be easily implemented using a ThreadLocal variable, as in the code below:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;public class HibernateUtil {
&amp;nbsp;&amp;nbsp; &amp;nbsp;private static final SessionFactory sessionFactory;
&amp;nbsp;&amp;nbsp; &amp;nbsp;private static final ThreadLocal threadSession =
&amp;nbsp;&amp;nbsp; &amp;nbsp;new ThreadLocal();

&amp;nbsp;&amp;nbsp; &amp;nbsp;static {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;// initialize SessionFactory
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;sessionFactory = new Configuration().configure().
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;buildSessionFactory();
&amp;nbsp;&amp;nbsp; &amp;nbsp;}

&amp;nbsp;&amp;nbsp; &amp;nbsp;public static Session getSession() {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;Session s = (Session) threadSession.get();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;// open a new Session, if this thread has none yet
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;try {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (s == null) {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;s = sessionFactory.openSession();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;threadSession.set(s);
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;} catch (HibernateException ex) {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;throw new InfrastructureException(ex);
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;return s;
&amp;nbsp;&amp;nbsp; &amp;nbsp;}

&amp;nbsp;&amp;nbsp; &amp;nbsp;public static void closeSession() {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;try {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Session s = (Session) threadSession.get();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;threadSession.set(null);
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (s != null &amp;amp;&amp;amp; s.isOpen()) s.close();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;} catch (HibernateException ex) {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;throw new InfrastructureException(ex);
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;}
}&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
You get the picture. We would call &lt;i&gt;HibernateUtil.getSession().getTransaction()&lt;/i&gt; in our servlet filter, instead of&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 12px; line-height: 14px; white-space: pre;&quot;&gt;sf.getCurrentSession().beginTransaction()&lt;/span&gt;. Now each thread running through the servlet (and the filter) gets its own session object, so it performs the CRUD operations to the database without&amp;nbsp;interfering&amp;nbsp;with the other threads.</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/4517498177270237878/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2010/08/hibernate-opensessioninview-reloaded.html#comment-form' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/4517498177270237878'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/4517498177270237878'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2010/08/hibernate-opensessioninview-reloaded.html' title='Hibernate: OpenSessionInView reloaded'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-3917391591265139330</id><published>2010-06-27T11:19:00.000-07:00</published><updated>2010-07-05T06:08:39.303-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".net"/><category scheme="http://www.blogger.com/atom/ns#" term="c#"/><category scheme="http://www.blogger.com/atom/ns#" term="multithreading"/><title type='text'>Invoke code on a certain thread in C# / .NET</title><content type='html'>Virtually all GUI frameworks and the languages that come with them give you the possibility to invoke a certain piece of code on the UI thread. This is necessary because the UI components aren&#39;t usually thread safe (making all their methods thread safe would be a big blow to the performance of the application), so any update of the UI can&#39;t be done from another thread. That piece of code needs to be marshalled to the main thread.&lt;br /&gt;
.NET goes a step further and offers us the possibility to invoke a piece of code on any thread. The example bellow shows how this can be done.&lt;br /&gt;
ThreadTask will be run in a new thread, whose name is &quot;Alpha thread&quot;. We create a Control on this thread (new Control()) and then we create its handle:&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 12px; line-height: 14px; white-space: pre;&quot;&gt;ctrl.CreateControl().&lt;/span&gt;&lt;br /&gt;
Finally, we do Application.Run(), which makes our thread wait for messages in the message loop.&lt;br /&gt;
Then we use our control to invoke the method MyTestMethod on our thread.&lt;br /&gt;
&lt;br /&gt;
Note that control handle creation is essential; without it, MyTestMethod would be invoked on the main thread. Also, attaching the thread to the message loop by doing Application.Run() ensures that the thread waits for invokes from other threads.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;using System;
using System.Windows.Forms;
using System.Threading;

namespace TestThreads2 {
&amp;nbsp;&amp;nbsp; &amp;nbsp;public class TestThread {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;private Control ctrl = null;

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// This method that will be called when the thread
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// is started
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public void ThreadTask() {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (ctrl == null) {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// create the control
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ctrl = new Control();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// create the handle
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ctrl.CreateControl();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Console.WriteLine(&quot;ThreadTask is running on thread: &quot; +
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Thread.CurrentThread.Name);
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// ensure the message loop is attached to this thread
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Application.Run();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public Control Ctrl {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;get { return ctrl; }
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;set { ctrl = value; }
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;}

&amp;nbsp;&amp;nbsp; &amp;nbsp;public class Program {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;private static void MyTestMethod() {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Console.WriteLine(&quot;TestMethod invoked on thread: &quot; +
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Thread.CurrentThread.Name);
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;static void Main(string[] args) {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//Control.CheckForIllegalCrossThreadCalls = true;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TestThread myThread = new TestThread();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Thread thread =
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;new Thread(
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;new ThreadStart(myThread.ThreadTask)
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;);
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;thread.Name = &quot;Alpha thread&quot;;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;thread.Start();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Thread.Sleep(1000);
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (myThread.Ctrl.InvokeRequired) {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;myThread.Ctrl.BeginInvoke(
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;new MethodInvoker(MyTestMethod)
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;);
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;} else {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;MyTestMethod();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;}
}&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 12px; line-height: 14px; white-space: pre;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
Check out &lt;a href=&quot;http://sorincalex.blogspot.com/2010/06/invoke-code-on-certain-thread-in-java.html&quot;&gt;here &lt;/a&gt;how to do the same thing in Java.</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/3917391591265139330/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2010/06/invoke-code-on-certain-thread-in-c-net.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/3917391591265139330'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/3917391591265139330'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2010/06/invoke-code-on-certain-thread-in-c-net.html' title='Invoke code on a certain thread in C# / .NET'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-5874553910710979609</id><published>2010-06-19T07:04:00.000-07:00</published><updated>2010-06-30T04:10:52.817-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="multithreading"/><title type='text'>Invoke code on a certain thread in Java</title><content type='html'>I think Java should be a bit&amp;nbsp;jealous&amp;nbsp;on the &lt;a href=&quot;http://sorincalex.blogspot.com/2010/06/invoke-code-on-certain-thread-in-c-net.html&quot;&gt;.NET&#39;s interesting feature&lt;/a&gt; of being able to invoke a piece of code on any given thread. In .NET that&#39;s possible by creating a Control (say myControl) on a certain thread and then using myControl.Invoke or myControl.BeginInvoke having as parameter the piece of code you want to invoke on that thread. The parameter is a delegate, another feature missing in Java, but let&#39;s ignore this for now.&lt;br /&gt;
In Java we have SwingUtilities.invokeAndWait and&amp;nbsp;SwingUtilities.invokeLater to invoke code on the &lt;b&gt;event dispatching thread&lt;/b&gt;, but not on&lt;i&gt; any given thread&lt;/i&gt;. They take a Runnable as parameter.&lt;br /&gt;
&lt;br /&gt;
So how would we implement such a feature in Java ? We&#39;ll need a thread that has nothing better to do but try to dequeue items from its queue and invoke them (the items would be the pieces of code that we need invoked on that thread). Something like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border-bottom-color: rgb(153, 153, 153); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(153, 153, 153); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(153, 153, 153); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(153, 153, 153); border-top-style: dashed; border-top-width: 1px; font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 100%;&quot;&gt;&lt;code&gt;package threading;&lt;/code&gt;&lt;code&gt;


import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;


public class Invoker {
&amp;nbsp;&amp;nbsp; &amp;nbsp;
&amp;nbsp;&amp;nbsp; &amp;nbsp;private static Thread myThread;
&amp;nbsp;&amp;nbsp; &amp;nbsp;private static BlockingQueue&amp;lt;Task&amp;gt; queue;
&amp;nbsp;&amp;nbsp; &amp;nbsp;
&amp;nbsp;&amp;nbsp; &amp;nbsp;private Invoker() {
&amp;nbsp;&amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;
&amp;nbsp;&amp;nbsp; &amp;nbsp;public static void BeginInvoke(Task task) {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (myThread == null) {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;queue = new LinkedBlockingQueue&amp;lt;Task&amp;gt;();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;myThread = new MyThread(queue);
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;myThread.start();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (Thread.currentThread() != myThread) {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;try {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;queue.put(task);
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;} catch(InterruptedException e) {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;e.printStackTrace();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Thread.currentThread().interrupt();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;} else {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;task.perform();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;}


}

&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
And the actual thread (I simulate the .NET delegate by using Java&amp;nbsp;anonymous classes):&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border-bottom-color: rgb(153, 153, 153); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(153, 153, 153); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(153, 153, 153); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(153, 153, 153); border-top-style: dashed; border-top-width: 1px; font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;
package threading;


import java.util.concurrent.BlockingQueue;


public class MyThread extends Thread {
&amp;nbsp;&amp;nbsp; &amp;nbsp;private final BlockingQueue&amp;lt;Task&amp;gt; taskQueue;
&amp;nbsp;&amp;nbsp; &amp;nbsp;
&amp;nbsp;&amp;nbsp; &amp;nbsp;public MyThread(BlockingQueue&amp;lt;Task&amp;gt; queue) {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;taskQueue = queue;
&amp;nbsp;&amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;
&amp;nbsp;&amp;nbsp; &amp;nbsp;public void run() {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;while(true) {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;try {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Task currentTask = taskQueue.take();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;currentTask.perform();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;} catch (InterruptedException e) {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;e.printStackTrace();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Restore the interrupted status
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Thread.currentThread().interrupt();
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;}


}

&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
We need an interface for our task - either an existing one (Swing uses Runnable), or a new one, like:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border-bottom-color: rgb(153, 153, 153); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(153, 153, 153); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(153, 153, 153); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(153, 153, 153); border-top-style: dashed; border-top-width: 1px; font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 100%;&quot;&gt;&lt;code&gt;package threading;&lt;/code&gt;&lt;code&gt;


public interface Task {


&amp;nbsp;&amp;nbsp; &amp;nbsp;void perform();
}

&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
Finally, the test class with the main method:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border-bottom-color: rgb(153, 153, 153); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(153, 153, 153); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(153, 153, 153); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(153, 153, 153); border-top-style: dashed; border-top-width: 1px; font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow-x: auto; overflow-y: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;
package threading;


public class Test {


&amp;nbsp;&amp;nbsp; &amp;nbsp;public static void main(String[] args) {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.out.println(&quot;main thread: &quot; + Thread.currentThread().getId() + &quot; &quot; + Thread.currentThread().getName());
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Invoker.BeginInvoke(new Task() {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public void perform() {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.out.println(&quot;perform task on thread: &quot; + Thread.currentThread().getId() + &quot; &quot; + Thread.currentThread().getName());
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;});
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Invoker.BeginInvoke(new Task() {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public void perform() {
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.out.println(&quot;perform task again on thread: &quot; + Thread.currentThread().getId() + &quot; &quot; + Thread.currentThread().getName());
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;});
&amp;nbsp;&amp;nbsp; &amp;nbsp;}
}
&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
It should come as no surprise the output:&lt;br /&gt;
&lt;br /&gt;
main thread: 1 main&lt;br /&gt;
perform task on thread: 7 Thread-0&lt;br /&gt;
perform task again on thread: 7 Thread-0</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/5874553910710979609/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2010/06/invoke-code-on-certain-thread-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/5874553910710979609'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/5874553910710979609'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2010/06/invoke-code-on-certain-thread-in-java.html' title='Invoke code on a certain thread in Java'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-2465824421171764906</id><published>2010-06-07T13:20:00.000-07:00</published><updated>2010-06-12T02:37:23.803-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="google maps"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>Mashup with Google Maps or How to Call Java from JavaScript</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial;&quot;&gt;You can simply embed Java code with the usual notation  and even expressions (&amp;lt; % = expression % &amp;gt;) in JavaScript &lt;i&gt;used in JSP&lt;/i&gt;. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial;&quot;&gt;Below is an example of how to do that. The code creates some Java arrays (between &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial;&quot;&gt;&amp;lt;% and&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial;&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial;&quot;&gt;) &lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial;&quot;&gt;and uses them in Javascript in order to show markers on a Google map. You can see it in action &lt;/span&gt;&lt;/span&gt;&lt;a href=&quot;http://www.incogniterra.org/pages/home.jsp&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial;&quot;&gt;here&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial;&quot;&gt; (choose trip Customizer and play with it).&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial;&quot;&gt;The code talks for itself, so here it is:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre class=&quot;source-code&quot; style=&quot;text-align: left;&quot;&gt;&lt;code&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&amp;lt;HEAD&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;   &amp;lt;title&amp;gt;Customize you trip !&amp;lt;/title&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;     &amp;lt;script src=&quot;http://maps.google.com/maps?file=api&amp;amp;amp;v=2&amp;amp;amp;key=ABQIAAAAyBigJTywiIxNM2cWUWhcFxR-sC-25ycSkOaRk1LgFwDltfgq9BRvhFBXWyducVZRhIvJw2DLcsPUdg&quot;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;      type=&quot;text/javascript&quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;    &amp;lt;script type=&quot;text/javascript&quot;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;    //&amp;lt;![CDATA[&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;    function load() {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;      if (GBrowserIsCompatible()) {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        var map = new GMap2(document.getElementById(&quot;map&quot;));&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        map.setCenter(new GLatLng(45.29, 25.56), 6);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        var coords = new Array();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&amp;lt;%&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;    int[] coordsX = (int[])(request.getSession().getAttribute(&quot;coordsX&quot;));&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;    int[] coordsY = (int[])(request.getSession().getAttribute(&quot;coordsY&quot;));&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;    String[] locations = (String[])(request.getSession().getAttribute(&quot;locations&quot;));&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;    if ((coordsX == null) || (coordsX.length == 0)) {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        coordsX = new int[1];&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        coordsX[0] = 0;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        coordsY = new int[1];&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        coordsY[0] = 0;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;    for (int i = 0; i &amp;lt; coordsX.length; i++) {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        if (&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;            (coordsY[i] &amp;lt; 2967) &amp;amp;&amp;amp; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;            (coordsY[i] &amp;gt; 2021) &amp;amp;&amp;amp; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;            (coordsX[i] &amp;lt; 4823) &amp;amp;&amp;amp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;            (coordsX[i] &amp;gt; 4362)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        ) {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;          var coord = new GLatLng(&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;                &amp;lt;%= (float)coordsX[i]/100 %&amp;gt;, &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;                &amp;lt;%= (float)coordsY[i]/100 %&amp;gt;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;          var marker = new GMarker(coord);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;          GEvent.addListener(marker, &quot;click&quot;, function() {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;            marker.openInfoWindowHtml(&quot;&amp;lt;b&amp;gt;&amp;lt;%= locations[i] %&amp;gt;&amp;lt;/b&amp;gt;&quot;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;          });&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;          map.addOverlay(marker);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        coords[&amp;lt;%= i %&amp;gt;] = coord;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&amp;lt;%&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        var polyline = new GPolyline(coords, &quot;#ff0000&quot;, 10);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;    map.addOverlay(polyline);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        // define the crosshair tile layer and its required functions&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        var crossLayer = new GTileLayer(new GCopyrightCollection(&quot;&quot;), 0, 15);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        crossLayer.getTileUrl =  function(tile, zoom) {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        return &quot;./include/tile_crosshairs.png&quot;;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        crossLayer.isPng = function() {return true;}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        // Create a new map type incorporating the tile layer&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        var layerTerCross = [ G_PHYSICAL_MAP.getTileLayers()[0], crossLayer ];&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        var mtTerCross = new GMapType(&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;                                      layerTerCross,&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;                                      G_PHYSICAL_MAP.getProjection(), &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;                                      &quot;Ter+&quot;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        map.addMapType(G_PHYSICAL_MAP);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        map.addMapType(mtTerCross);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        map.addControl(new GLargeMapControl())&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        var mapControl = new GHierarchicalMapTypeControl();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        // Set up map type menu relationships&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        mapControl.clearRelationships();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        mapControl.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, &quot;Labels&quot;, false);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        mapControl.addRelationship(G_PHYSICAL_MAP, mtTerCross, &quot;Crosshairs&quot;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        // Add control after you&#39;ve specified the relationships&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;        map.addControl(mapControl);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;      }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;    //]]&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;    &amp;lt;/script&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&amp;lt;/HEAD&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;In the code above, &quot;map&quot; is actually a div:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;pre class=&quot;source-code&quot; style=&quot;text-align: justify;&quot;&gt;&lt;code&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&amp;lt;div id=&quot;map&quot; style=&quot;width: 700px; height: 400px&quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;code&gt;&lt;/code&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;code&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;In case you&#39;re wondering how this mix of JSP, JavaScript and Java actually works, let&#39;s start with the JSP: as we know, JSP runs on the server side and gets translated into a servlet. Thus, the code between&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial; font-size: large;&quot;&gt;&amp;lt; %&amp;nbsp;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: medium;&quot;&gt;and&amp;nbsp;&lt;/span&gt;% &amp;gt;,&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;including the one inside JavaScript, is textually copied into the servlet code, &amp;nbsp;since it is just Java code. The resulting servlet will generate HTML, so it will also dynamically generate the JavaScript code (which you can see in your browser by viewing the page source). The generated JavaScript code will have the for loop expanded with actual values for the coordinates and it will execute on the client side, in the browser.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;That&#39;s all, folks.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;/code&gt;&lt;br /&gt;
&lt;div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/2465824421171764906/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2010/06/mashup-with-google-maps-or-how-to-call.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/2465824421171764906'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/2465824421171764906'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2010/06/mashup-with-google-maps-or-how-to-call.html' title='Mashup with Google Maps or How to Call Java from JavaScript'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5351168395533279816.post-3338084426046174856</id><published>2010-06-01T13:02:00.000-07:00</published><updated>2010-08-15T07:52:14.324-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="hibernate"/><category scheme="http://www.blogger.com/atom/ns#" term="OpenSessionInView"/><title type='text'>Hibernate: OpenSessionInView explained</title><content type='html'>&lt;div&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When you enter the Hibernate world, you hear a lot about sessions, transactions, session-per-request, etc., to the point you start mixing the concepts. Let&#39;s face it:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Fact 1: Hibernate is big&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Fact 2: Hibernate is easy if you understand the fundamentals; everything else builds on top of those&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;I&#39;ll try to explain these fundamental concepts and then I&#39;ll cover the famous OpenSessionInView pattern with an example.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So, what&#39;s a session ? If I tell you &quot;a session is a unit of work bla bla bla&quot;, you&#39;ll say &quot;I&#39;ve read that in about 1,200,000 hits returned by Google and yet I don&#39;t really understand the concept&quot;. Let me put it this way: from the developer&#39;s perspective (what can I do, I usually incarnate this perspective), a &lt;b&gt;session&lt;/b&gt; is actually an API that abstracts the notion of &lt;i&gt;persistence service&lt;/i&gt;. Thus, whenever you want to do something with the objects (representing the O in the ORM), like synchronize them with the DB, persist them to the DB, etc., you need a session instance.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;However, as we all know, each operation to the DB - be it a read or a write - needs a &lt;b&gt;transaction&lt;/b&gt;. Thus, because you use the  session in order to perform DB operations, it means whenever we&#39;re using the session we need a transaction (with a noteworthy exception, but we&#39;ll cover that later). If you&#39;re trying to run an operation on the session without being inside a transaction, you&#39;ll get a runtime exception of the type&lt;i&gt; org.hibernate.TransactionException: Transaction not successfully started&lt;/i&gt;.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In other words, it&#39;s quite logical that the scope of a session (i.e. from the moment you create/open it to the moment you close it) and the scope of a transaction coincide. Without further ado, this is the&lt;i&gt; session-per-request&lt;/i&gt; pattern. &lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Now let&#39;s take a painfully real example. Suppose I have two tables in my DB: a Patients table and a PatientPhones table (basically each patient from the first table has a number of telephone numbers recorded in the second table). They are linked by PATIENT_ID, a foreign key in PatientPhones table and primary key in the Patients table. &lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The Hibernate file that describes these tables is:&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;pre class=&quot;source-code&quot;&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;        &quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;        &quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&quot;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&amp;lt;hibernate-mapping package=&quot;model&quot;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;    &amp;lt;class name=&quot;Patient2&quot; table=&quot;PATIENTS&quot;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;        &amp;lt;id name=&quot;id&quot; column=&quot;PATIENT_ID&quot;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;            &amp;lt;generator class=&quot;assigned&quot; /&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;        &amp;lt;/id&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;        &amp;lt;property name=&quot;name&quot;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;        &amp;lt;property name=&quot;sex&quot;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;        &amp;lt;property name=&quot;birth_day&quot;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;        &amp;lt;property name=&quot;birth_month&quot;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;        &amp;lt;property name=&quot;birth_year&quot;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;        &amp;lt;property name=&quot;address&quot;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;        &amp;lt;property name=&quot;cnp&quot;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;        &amp;lt;bag name=&quot;phoneNumbers&quot; table=&quot;PATIENT_PHONES&quot; cascade=&quot;all&quot; lazy=&quot;true&quot;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;            &amp;lt;key column=&quot;PATIENT_ID&quot;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;            &amp;lt;element type=&quot;string&quot; column=&quot;PHONE_NUMBER&quot;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;        &amp;lt;/bag&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;    &amp;lt;/class&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&amp;lt;/hibernate-mapping&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Georgia, serif; font-size: 130%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Notice the lazy=&quot;true&quot; attribute above ? This means that actually the phone numbers will be retrieved from the DB lazily, i.e. when we request them. For example, suppose I do this:&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre class=&quot;source-code&quot;&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();

// note that in this query we use the name of the class, Patient2,
// rather than the name of the table (Patients)
ArrayList patients =
new ArrayList(session.createQuery(&quot;from Patient2&quot;).list());
session.getTransaction().commit();
HibernateUtil.getSessionFactory().close();
&lt;/code&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Then, after the session has been closed, I do this:&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre class=&quot;source-code&quot;&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;
for (Patient2 p : patients) {
System.out.println(&quot;Patient &quot; + p.getName() + &quot; &quot; + p.getId());
}
&lt;/code&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;This will work, because the patients list has been eagerly populated with the DB data inside the transaction above. &lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But if I try:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000099; font-family: monospace; font-size: 13px; white-space: pre;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre class=&quot;source-code&quot; style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;


&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;
for (Patient2 p : patients) {
  if ((p.getPhoneNumbers() != null) &amp;amp;&amp;amp; (p.getPhoneNumbers().size() &amp;gt; 0)) {
    System.out.print(&quot; * phones :&quot;);
    Iterator iter = p.getPhoneNumbers().iterator();
    while (iter.hasNext()) {
        System.out.print(&quot; &quot; + iter.next());
    }
    System.out.println();
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000099; font-family: monospace; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000099; font-family: monospace; font-size: 100%;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px; white-space: pre;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;This fails with the error &lt;i&gt;LazyInitializationException&lt;/i&gt; (or something like this) because in the xml file above I asked the phone numbers to be lazily retrieved, i.e. when I do p.getPhoneNumbers(). However, at this moment I am outside the session, so I&#39;m working with the detached object &lt;i&gt;p&lt;/i&gt;. In order to be able to retrieve the phones, I have 2 choices:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;1. either do lazy = &quot;false&quot; in the xml above&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;2. or reattach each object p to which I&#39;m asking getPhoneNumbers(), like this:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff; font-family: monospace;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: normal;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre class=&quot;source-code&quot; style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;


&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;Session session = HibernateUtil.getSessionFactory().getCurrentSession(); 
session.beginTransaction(); 
for (Patient2 p : patients) {     
 System.out.println(&quot;Patient &quot; + p.getName() + &quot; &quot; + p.getId());     
 session.lock(p, LockMode.NONE);     
 if ((p.getPhoneNumbers() != null) &amp;amp;&amp;amp; (p.getPhoneNumbers().size() &amp;gt; 0)) {         
  System.out.print(&quot; * phones :&quot;);         
  Iterator iter = p.getPhoneNumbers().iterator();         
  while (iter.hasNext()) {             
   System.out.print(&quot; &quot; + iter.next());         
  }         
  System.out.println();     
 } 
} 
session.getTransaction().commit(); 
HibernateUtil.getSessionFactory().close();  
&lt;/code&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;white-space: pre;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;This situation is extremely relevant, because in a typical web application you&#39;d do exactly this:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;whenever you show the results of a DB query (via Hibernate) in your view  (a jsp page for example), your objects are detached (the session is closed, the transaction committed), so you can get the exception &lt;i&gt;LazyInitializationException&lt;/i&gt;. &lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The solution is the &lt;b&gt;Open Session in View pattern&lt;/b&gt;, which simply states that the session should remain open and the transaction uncommitted until the results have been processed in the view. This can be easily done with a filter, e.g.:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;public class HibernateSessionRequestFilter implements Filter {

private SessionFactory sf;

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {

try {

sf.getCurrentSession().beginTransaction();
// Call the next filter (continue request processing)
chain.doFilter(request, response);
&amp;nbsp;// Commit and cleanup
&amp;nbsp;sf.getCurrentSession().getTransaction().commit();
} catch (StaleObjectStateException staleEx) {
&amp;nbsp;throw staleEx;
} catch (Throwable ex) {
&amp;nbsp;// Rollback only
&amp;nbsp;try {
&amp;nbsp;&amp;nbsp;if (sf.getCurrentSession().getTransaction().isActive()) {
&amp;nbsp;&amp;nbsp;sf.getCurrentSession().getTransaction().rollback();
&amp;nbsp;&amp;nbsp;}
&amp;nbsp;} catch (Throwable rbEx) {
&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;// Let others handle it... maybe another interceptor for exceptions?
&amp;nbsp;&amp;nbsp;throw new ServletException(ex);
}
}

public void init(FilterConfig filterConfig) throws ServletException {
sf = HibernateSession.getSessionFactory();
}
&lt;/code&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;(NOTE: &lt;b&gt;this pattern only works when the jsp and Hibernate code run on the same JVM, i.e. when the presentation and business logic tiers run on the same machine&lt;/b&gt;)&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000099;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000099;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000099;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;I will register this filter in my web.xml:&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;filter&gt;&lt;/filter&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;filter&gt;&lt;/filter&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre class=&quot;source-code&quot;&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&amp;lt;filter&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&amp;lt;filter-name&amp;gt;HibernateFilter&amp;lt;/filter-name&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&amp;lt;filter-class&amp;gt;view.backing.HibernateSessionRequestFilter&amp;lt;/filter-class&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&amp;lt;/filter&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&amp;lt;filter-mapping&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&amp;lt;filter-name&amp;gt;HibernateFilter&amp;lt;/filter-name&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&amp;lt;url-pattern&amp;gt;/*&amp;lt;/url-pattern&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&amp;lt;/filter-mapping&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Now, in one of my JSF backing beans, PatientsSearch.java, I could have:&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;pre class=&quot;source-code&quot; style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;



&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;public void getAllPatients() {
Session session = null;
try {
 session = HibernateSession.getSessionFactory().getCurrentSession();
 Query query = session.createQuery(&quot;from Patient2 p order by p.name asc&quot;);
 int pageNumber = 1;
 int pageSize = rowsPerPage;
 query.setFirstResult((pageNumber - 1) * pageSize);
 query.setMaxResults(pageSize);
 patients = new ArrayList(query.list());
 totalRows = count();
} catch (Exception e) {
 if (session != null) session.getTransaction().rollback();
 e.printStackTrace();
}
}
&lt;/code&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #3333ff;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;And in the view, patientSearch.jsp, I could have:&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3333ff;&quot;&gt;&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&amp;lt;h:dataTable value=&quot;#{PatientsSearch.patients}&quot; var=&quot;patient&quot;


binding=&quot;#{PatientsSearch.dataTable1}&quot; id=&quot;dataTable1&quot;
border=&quot;2&quot; bgcolor=&quot;White&quot; frame=&quot;border&quot;
&quot;&amp;gt;
&amp;lt;h:column&amp;gt;
&amp;lt;f:facet name=&quot;header&quot;&amp;gt;
&amp;lt;h:outputText value=&quot;Name&quot;/&amp;gt;
&amp;lt;/f:facet&amp;gt;
&amp;lt;h:commandLink action=&quot;#{PatientsSearch.edit}&quot;&amp;gt;
&amp;lt;h:outputText value=&quot;#{patient.name}&quot; style=&quot;font-family:Garamond;&quot;/&amp;gt;
&amp;lt;/h:commandLink&amp;gt;
&amp;lt;/h:column&amp;gt;
&amp;lt;h:column&amp;gt;
&amp;lt;f:facet name=&quot;header&quot;&amp;gt;
&amp;lt;h:outputText value=&quot;ID&quot;/&amp;gt;
&amp;lt;/f:facet&amp;gt;
&amp;lt;h:outputText value=&quot;#{patient.id}&quot;/&amp;gt;
&amp;lt;/h:column&amp;gt;
&amp;lt;h:column&amp;gt;
&amp;lt;f:facet name=&quot;header&quot;&amp;gt;
&amp;lt;h:outputText value=&quot;Address&quot;/&amp;gt;
&amp;lt;/f:facet&amp;gt;
&amp;lt;h:outputText value=&quot;#{patient.address}&quot;/&amp;gt;
&amp;lt;/h:column&amp;gt;
&amp;lt;h:column&amp;gt;
&amp;lt;f:facet name=&quot;header&quot;&amp;gt;
&amp;lt;h:outputText value=&quot;Fix phone&quot;/&amp;gt;
&amp;lt;/f:facet&amp;gt;
&amp;lt;h:outputText value=&quot;#{patient.phoneFix}&quot;/&amp;gt;
&amp;lt;/h:column&amp;gt;
&amp;lt;h:column&amp;gt;
&amp;lt;f:facet name=&quot;header&quot;&amp;gt;
&amp;lt;h:outputText value=&quot;Mobile phone&quot;/&amp;gt;
&amp;lt;/f:facet&amp;gt;
&amp;lt;h:outputText value=&quot;#{patient.phoneMobile}&quot;/&amp;gt;
&amp;lt;/h:column&amp;gt;
&amp;lt;/h:dataTable&amp;gt;

&amp;lt;h:commandButton value=&quot;All patients&quot; id=&quot;commandButton1&quot;
action=&quot;#{PatientsSearch.getAllPatients}&quot;/&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;This works just as described above: in the view I don&#39;t need to worry about the session; even if &lt;i&gt;lazy = &quot;true&quot;&lt;/i&gt;, I know that the calls &lt;i&gt;patient.phoneMobile&lt;/i&gt; and &lt;i&gt;patient.phoneFix&lt;/i&gt; will retrieve the data, because everything happens between the two important statements in the filter:&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3333ff;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #3333ff;&quot;&gt;&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;sf.getCurrentSession().beginTransaction();
....
sf.getCurrentSession().getTransaction().commit();&lt;/code&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000099;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;By the way, in Patient2.java, I have:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;public String getPhoneFix() {

&amp;nbsp;&amp;nbsp; &amp;nbsp;if (phoneNumbers.size() &amp;gt; 0) return (String)phoneNumbers.get(0);

return null;

}&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Simple, isn&#39;t it ?&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000099;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: #000099;&quot;&gt;&lt;i&gt;However, there is potentially something wrong with this approach. Check out the &lt;/i&gt;&lt;a href=&quot;http://sorincalex.blogspot.com/2010/08/hibernate-opensessioninview-reloaded.html&quot;&gt;&lt;i&gt;next article&lt;/i&gt;&lt;/a&gt;&lt;i&gt; to see what and how we can correct it.&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;div id=&quot;refHTML&quot;&gt;&lt;/div&gt;&lt;input id=&quot;gwProxy&quot; type=&quot;hidden&quot; /&gt;&lt;input id=&quot;jsProxy&quot; onclick=&quot;jsCall();&quot; type=&quot;hidden&quot; /&gt;&lt;br /&gt;
&lt;div id=&quot;refHTML&quot;&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sorincalex.blogspot.com/feeds/3338084426046174856/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sorincalex.blogspot.com/2010/06/hibernate-opensessioninview-explained.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/3338084426046174856'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5351168395533279816/posts/default/3338084426046174856'/><link rel='alternate' type='text/html' href='http://sorincalex.blogspot.com/2010/06/hibernate-opensessioninview-explained.html' title='Hibernate: OpenSessionInView explained'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/07060141681599554630</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>