tag:blogger.com,1999:blog-115933742018-03-11T12:08:50.563+00:00Andrew Beacock's Blog<a href="/search/label/Agile">agile</a> / <a href="/search/label/Apache">apache</a> / <a href="/search/label/Java">java</a> / <a href="/search/label/Leadership">leadership</a> / <a href="/search/label/Linux">linux</a> / <a href="/search/label/Mobile">mobile</a> / <a href="/search/label/Ruby">ruby</a> / <a href="/search/label/Subversion">subversion</a> / <a href="/search/label/Web">web</a>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.comBlogger246125http://bp0.blogger.com/_Vu_eUOpUOMk/RgWamJV19TI/AAAAAAAAAGw/Lu_6ZKf-Glw/s400/buddy_icon.pngandrewbeacockhttps://feedburner.google.comThis is an XML content feed. It is intended to be viewed in a newsreader or syndicated to another site.tag:blogger.com,1999:blog-11593374.post-84637737687285608522016-07-06T21:30:00.000+01:002016-07-06T21:30:38.439+01:00Setting up Spring application & webapp contexts correctly in Java integration testsWhen integration testing <a href="https://spring.io/">Spring </a>web applications you would often pull in the applicationContext.xml and the appropriate *-servlet.xml file using the <a href="http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/test/context/ContextConfiguration.html">@ContextConfiguration</a> annotation within the junit test class. The problem is that this loads both sets of beans into the same context which is different from when tcServer loads the webapp for real. In a real server, the application context is loaded into the 'root' context and each servlet into it's own separate context which is dependent on the root (see my <a href="http://blog.andrewbeacock.com/2010/09/spring-autowiring-component-scanning.html">set of previous articles</a> for more details).<br /><br />To properly set up the contexts in a test environment so that they are loaded and treated the same as in a running tcServer you need to tell the test that it's a webapp test using the <a href="http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/test/context/web/WebAppConfiguration.html">@WebAppConfiguration</a> annotation and then use the <a href="http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/test/context/ContextHierarchy.html">@ContextHierarchy</a> annotation to set up the order in which to load the contexts:<br /><br /><pre><br />@RunWith(SpringJUnit4ClassRunner.class)<br />@WebAppConfiguration<br />@ContextHierarchy({<br /> @ContextConfiguration(locations = { "/applicationContext.xml" }),<br /> @ContextConfiguration(locations = { "/beacock-servlet.xml" })<br />})<br />public class BeacockControllerIntegrationTest {<br /> ....<br />}<br /></pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=2Lmw0KJbG9U:GeAGyur6fTs:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=2Lmw0KJbG9U:GeAGyur6fTs:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=2Lmw0KJbG9U:GeAGyur6fTs:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=2Lmw0KJbG9U:GeAGyur6fTs:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=2Lmw0KJbG9U:GeAGyur6fTs:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=2Lmw0KJbG9U:GeAGyur6fTs:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=2Lmw0KJbG9U:GeAGyur6fTs:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com0http://blog.andrewbeacock.com/2016/07/setting-up-spring-application-webapp.htmltag:blogger.com,1999:blog-11593374.post-63417439148454650672013-01-13T21:43:00.001+00:002013-01-13T21:43:51.791+00:00cvc-complex-type.2.4.c issues - a few things to checkI've battled with the Spring cvc-complex-type.2.4.c issue on a few occasions but with them far enough apart that I can't remember what the steps are to solve it. This time round I thought I would write it down...<br /><br />You are writing a Spring-based app and you have some of your bean declarations in XML (I also use annotations but that's not important here). You wire your beans, you write your code and you build your application. Everything compiles and builds correctly, you run up your app in your container (in my case the dreaded Glassfish) and BOOM:<br /><pre>Caused by: org.xml.sax.SAXParseException;<br /> lineNumber: 30; columnNumber: 76;<br /> cvc-complex-type.2.4.c: The matching wildcard is strict,<br /> but no declaration can be found for element 'jms:listener-container'.<br /> at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.<br /> createSAXParseException(ErrorHandlerWrapper.java:198)<br /></pre>Here are a few things to check:<br /><br />Check that you have a element in your XML of the mentioned type, in my case it complained about 'jms:listener-container' and I correctly had this in the config: <br /><pre>&lt;jms:listener-container<br /> acknowledge="transacted"<br /> concurrency="5"<br /> connection-factory="jmsAsyncMLQueueConnectionFactory"<br /> destination-resolver="jndiDestinationResolver"/&gt;<br /></pre>Check that you have the mentioned namespace declared correctly, it complained about 'jms:listener-container' and I correctly had this in the beans header part of the XML: <br /><pre>&lt;beans<br /> xmlns:jee="http://www.springframework.org/schema/jee"<br /> xmlns:jms="http://www.springframework.org/schema/jms"<br /> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<br /> xmlns="http://www.springframework.org/schema/beans"<br /> xsi:schemalocation="<br /> http://www.springframework.org/schema/beans<br /> http://www.springframework.org/schema/beans/spring-beans-3.0.xsd<br /> http://www.springframework.org/schema/jms<br /> http://www.springframework.org/schema/jms/spring-jms-3.0.xsd<br /> http://www.springframework.org/schema/jee<br /> http://www.springframework.org/schema/jee/spring-jee-3.0.xsd<br /> "&gt;<br /> ....<br /></pre>As you can see I've declared the xmlnss:jms and then put the correct schema location URL in as well.<br /><br />None of this was the problem, in fact the problem wasn't to do with mistakes in the XML configuration, or incorrect namespace URLs or even whether the correct SAX parser was being used (look out for this one though).<br /><br />The problem was that the spring jms schema file couldn't be found, the Spring XML parser doesn't go to the internet to get the schema files, it looks for them in the Spring jars. I'd completely forgotten to declare the use of sping-jms in my maven config and so it couldn't find the Spring JMS schema.<br /><br />By adding the following to my Maven project sorted out the issue:<br /><br /><pre><br />&lt;dependency><br /> &lt;groupId>org.springframework&lt;/groupId><br /> &lt;artifactId>spring-jms&lt;/artifactId><br />&lt;/dependency><br /></pre>Why couldn't the XML parser have told me that it couldn't find one of the schema files?!?! >:O<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=rTCVWVe0apE:H4Ycj_G7R88:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=rTCVWVe0apE:H4Ycj_G7R88:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=rTCVWVe0apE:H4Ycj_G7R88:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=rTCVWVe0apE:H4Ycj_G7R88:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=rTCVWVe0apE:H4Ycj_G7R88:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=rTCVWVe0apE:H4Ycj_G7R88:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=rTCVWVe0apE:H4Ycj_G7R88:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com3http://blog.andrewbeacock.com/2013/01/cvc-complex-type24c-issues-few-things.htmltag:blogger.com,1999:blog-11593374.post-20539858266269387632012-03-25T21:33:00.002+01:002012-03-25T21:35:02.971+01:00Java Date & Time manipulation using Apache Velocity<a href="http://velocity.apache.org/">Apache Velocity</a> is an excellent tool if you need to bang out a quick bit of XML output or a text file with a particular layout and you don't want to do it all in Java. You create a <a href="http://velocity.apache.org/engine/releases/velocity-1.5/user-guide.html#velocity_template_language_vtl:_an_introduction">Velocity template</a> with your text in it and use various place-holders for the dynamic data that will be passed into it from your Java code. Velocity them merges the two together to give you a nicely formatted custom-filled file/document/SOAP request/etc.<br /><br />It's a great tool but does have it's quirks and downsides and one that I hit upon recently was how to display dates in a particular format. You can call methods on any Java object that you pass to the template but only if it's in the Java bean standard format of <code>getX()</code> and the Date formatting methods don't follow this standard.<br /><br />The solution was found within the optional Velocity-Tools library - DateTool. <a href="http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/DateTool.html#format%28java.lang.String,%20java.lang.Object,%20java.util.Locale,%20java.util.TimeZone%29">DateTool has a number of format methods</a> on it which can twist the dates and times into any format that you need, here are some examples:<br /><br /><b>Date &amp; Time together</b><br /><br />This in the template:<br /><pre class="brush:javascript">$dateTool.format('default', $testDate)<br />$dateTool.format('full', $testDate)<br />$dateTool.format('long', $testDate)<br />$dateTool.format('medium', $testDate)<br />$dateTool.format('short', $testDate)</pre>Gives this in the output:<br /><pre>03-Jan-2012 00:00:00<br />Tuesday, 3 January 2012 00:00:00 o'clock GMT<br />03 January 2012 00:00:00 GMT<br />03-Jan-2012 00:00:00<br />03/01/12 00:00</pre><br /><b>Just Dates</b><br /><br />This in the template:<br /><pre class="brush:javascript">$dateTool.format('default_date', $testDate)<br />$dateTool.format('full_date', $testDate)<br />$dateTool.format('long_date', $testDate)<br />$dateTool.format('medium_date', $testDate)<br />$dateTool.format('short_date', $testDate)</pre>Gives this in the output:<br /><pre>03-Jan-2012<br />Tuesday, 3 January 2012<br />03 January 2012<br />03-Jan-2012<br />03/01/12</pre><br /><b>Just Times</b><br /><br />This in the template:<br /><pre class="brush:javascript">$dateTool.format('default_time', $testDate)<br />$dateTool.format('full_time', $testDate)<br />$dateTool.format('long_time', $testDate)<br />$dateTool.format('medium_time', $testDate)<br />$dateTool.format('short_time', $testDate)</pre>Gives this in the output:<br /><pre>00:00:00<br />00:00:00 o'clock GMT<br />00:00:00 GMT<br />00:00:00<br />00:00</pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=f3aSciG0hA8:XkenD6vg160:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=f3aSciG0hA8:XkenD6vg160:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=f3aSciG0hA8:XkenD6vg160:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=f3aSciG0hA8:XkenD6vg160:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=f3aSciG0hA8:XkenD6vg160:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=f3aSciG0hA8:XkenD6vg160:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=f3aSciG0hA8:XkenD6vg160:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com0http://blog.andrewbeacock.com/2012/03/java-date-time-manipulation-using.htmltag:blogger.com,1999:blog-11593374.post-52741022236749172892012-01-25T23:47:00.003+00:002012-01-26T14:10:11.888+00:00Beware of JavaScript's parseInt function - 010 does not equal 10...I use JavaScript &amp; jQuery quite a bit in my day job helping to add a bit of 'shiny' to our web applications. One feature that I added recently kept a track of the percentages that you had typed in the form.&nbsp; It told you at the bottom of the page how much percentage you had left - I used JavaScript's parseInt function to help me in this respect.<br /><br />As the application passed through system test it was found that if you typed '020' as a percentage my application said that you had 84% left to assign rather than the expected 80% - any ideas what's going on?<br /><br />Yes that's right - the leading zero was causing <a href="http://www.w3schools.com/jsref/jsref_parseInt.asp">parseInt</a> to treat the number as an octal (base 8) number and so 020 was two lots of 8 = 16. It appears that this <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/parseInt#ECMAScript_5_Removes_Octal_Interpretation">octal recognition is being deprecated</a> but who knows when it will actually go so for now I've had to add ", 10" (i.e. a decimal radix) to the end of all of my parseInt calls:<br /><pre>parseInt(percentage, 10);<br /></pre>Double check any code that you use which uses parseInt to make sure it doesn't trip you up in the same way that I way!<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=pYGGzoLhH0A:5546VxkVxDQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=pYGGzoLhH0A:5546VxkVxDQ:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=pYGGzoLhH0A:5546VxkVxDQ:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=pYGGzoLhH0A:5546VxkVxDQ:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=pYGGzoLhH0A:5546VxkVxDQ:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=pYGGzoLhH0A:5546VxkVxDQ:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=pYGGzoLhH0A:5546VxkVxDQ:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com0http://blog.andrewbeacock.com/2012/01/beware-of-javascripts-parseint-010-does.htmltag:blogger.com,1999:blog-11593374.post-22638549819465615182011-10-31T22:32:00.000+00:002011-10-31T22:32:45.780+00:00Do 'is' boolean methods work in JSPs with JSTL?When coding in <a href="http://www.oracle.com/technetwork/java/jstl-137486.html">JSTL</a> you often want to use conditional logic (I'm thinking <c:if> and the like) to be able to structure your page correctly. Auto-generated getter &amp; setter methods will normally create isX() methods for the getters of boolean values (at least in <a href="http://www.eclipse.org/">Eclipse</a> it does) but can you access this method directly from JSTL without writing a getX() version?</c:if><br /><br />Does <a href="http://www.oracle.com/technetwork/java/jstl-137486.html">JSTL</a> support 'is' boolean methods though? Ask a random poll of Java we developers and you will get conflicting answers so I decided to investigate, want the short answer?<br /><br /><b>YES</b> - JSTL does support accessing isX() methods directly as if you were accessing a getX() method, but only if the return type of the isX() method is a <a href="http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html">primative boolean</a>. If you return an object of any kind (such as <a href="http://download.oracle.com/javase/6/docs/api/java/lang/Boolean.html">Boolean</a> isObjectBooleanTrue()) then JSTL fails to find the method and will give you a rather nasty JSP exception:<br /><blockquote class="tr_bq"><div class="MsoNormal">javax.el.<wbr></wbr>PropertyNotFoundException: The class 'com.andrewbeacock.BooleanTest' does</div>not have the property 'objectBooleanTrue'.</blockquote>So yes, 'is' methods work in JSTL but make sure you ONLY return <a href="http://download.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html">primitive booleans</a> from them.<br /><br /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=o79RD_mUnn0:-VDpqHLcyO4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=o79RD_mUnn0:-VDpqHLcyO4:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=o79RD_mUnn0:-VDpqHLcyO4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=o79RD_mUnn0:-VDpqHLcyO4:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=o79RD_mUnn0:-VDpqHLcyO4:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=o79RD_mUnn0:-VDpqHLcyO4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=o79RD_mUnn0:-VDpqHLcyO4:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com1http://blog.andrewbeacock.com/2011/10/do-is-boolean-mthods-work-in-jsps-with.htmltag:blogger.com,1999:blog-11593374.post-78278058031983272942011-10-27T20:29:00.000+01:002011-10-27T20:29:01.495+01:00How to stop Eclipse reformating your Java enumerations & commentsEclipse is a wonderful IDE for the Java language and I’ve used it daily for at least the past 4 years but it does have some 'issues'. One is regarding it’s code formatting (or reformatting) support, normally it does a great job of putting stuff in the right place but there are occasions where it just fails to get it right.<br /><br /><b>Enumerations</b><br />When I write enums I like to have each item on it's own row, I find it's easier to read and amend in the future:<br /><pre class="brush:java">public enum Family {<br /> MOTHER,<br /> FATHER,<br /> DAUGHTER,<br /> SON;<br />}<br /></pre>But Eclipse has other ideas and formats it so that it looks like this:<br /><pre class="brush:java">public enum Family {<br /> MOTHER, FATHER, DAUGHTER, SON;<br />}<br /></pre>A way to get around this (and any other times where you have a few lines of code that you don't want collapsing into one is to add the double-slash style code comments to the end of each line: <br /><pre class="brush:java">public enum Family {<br /> MOTHER, //<br /> FATHER, //<br /> DAUGHTER, //<br /> SON;<br />}<br /></pre><b>Block comments</b><br /><br />I recently wanted to have a decent sized chunk of XML stored within Java's block comments (/* ... */) so that I could refer to it as I coded a mapping class. Everytime I saved the class Eclipse reformatted my XML so that it looked like someone had been sick on the page.<br /><br />After a little digging I found this gem buried in the original coding conventions document from Sun back in 1997:<br /><blockquote>Block comments can start with /*-, which is recognized by indent(1) as the beginning of a block comment that should not reformatted.</blockquote>&nbsp;&nbsp;&nbsp;&nbsp;Taken from section 5.1.1 of <a href="http://www.oracle.com/technetwork/java/codeconventions-150003.pdf">Java Code Conventions</a><br /><br />Now I'm pretty damn sure that Eclipse doesn't use indent for it's layout but I tried it anyway and it works a treat! Simply add the minus sign to the start of the block comment section and it will leave the whole block comment alone:<br /><pre class="brush:java">/*-<br /> <xml><br /> <some lovely="formatted"><br /> XML which we don't want<br /> <some><br /> <silly formatter="to touch"/><br /> </xml><br />*/<br /></pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=YeMOreRrpbQ:t5NfyepPWe4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=YeMOreRrpbQ:t5NfyepPWe4:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=YeMOreRrpbQ:t5NfyepPWe4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=YeMOreRrpbQ:t5NfyepPWe4:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=YeMOreRrpbQ:t5NfyepPWe4:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=YeMOreRrpbQ:t5NfyepPWe4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=YeMOreRrpbQ:t5NfyepPWe4:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com2http://blog.andrewbeacock.com/2011/10/how-to-stop-eclipse-reformating-your.htmltag:blogger.com,1999:blog-11593374.post-87726492640432796312011-08-17T21:15:00.000+01:002011-08-17T21:15:03.683+01:00Always note DNS server settings offlineHad a strange experience this evening - complete loss of the internet. My router was suggesting that I had ASDL connectivity, and even an IP address but I wasn't able to load any websites. After a bit of debugging with the help of a remote friend I figured out that I wasn't able to connect to <a href="http://blog.andrewbeacock.com/2009/05/replace-your-broadband-providers-dns.html">my OpenDNS name servers</a> and so google.com wasn't resolving for me.<br /><br />I updated my router with <a href="http://code.google.com/speed/public-dns/">Google's DNS settings</a> and was back in play - just goes to show that what appears to be an ISP outage can be a case of name servers not being available at that time.<br /><br />Make sure you make a note of a few free DNS server details (i.e. both <a href="http://blog.andrewbeacock.com/2009/05/replace-your-broadband-providers-dns.html">OpenDNS</a> and <a href="http://code.google.com/speed/public-dns/">GoogleDNS</a>) offline so you can try them out if you ever end up 'offline'!<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=d1c2ggghRps:J5II1759o_0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=d1c2ggghRps:J5II1759o_0:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=d1c2ggghRps:J5II1759o_0:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=d1c2ggghRps:J5II1759o_0:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=d1c2ggghRps:J5II1759o_0:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=d1c2ggghRps:J5II1759o_0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=d1c2ggghRps:J5II1759o_0:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com0http://blog.andrewbeacock.com/2011/08/always-note-dns-server-settings-offline.htmltag:blogger.com,1999:blog-11593374.post-25367276527333957882011-05-14T21:32:00.000+01:002011-05-14T21:32:59.648+01:00Misleading wiring messages with aliased Spring DataSourcesWhen accessing databases in <a href="http://www.springsource.org/">Spring</a> you commonly use a <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/jdbc.html#jdbc-introduction">dataSource.xml file</a> of some description to hold the XML <a href="http://en.wikipedia.org/wiki/Stanza">stanzas</a> describing the connection details to various databases or schemas.<br /><br />When dealing with multiple dataSource requirements you might find that more than one logical dataSource bean name actually points to the same physical connection. Rather than define multiple datasource stanzas with exactly the same details, Spring allows the use of the <alias> element to point easily to an existing bean but use a different name:<pre class="brush:xml">&lt;bean id="personDataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt;<br /> &lt;property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /&gt;<br /> &lt;property name="url" value="jdbc:oracle:thin:@database:port:SID" /&gt;<br /> &lt;property name="username" value="USER" /&gt;<br /> &lt;property name="password" value="PASS" /&gt;<br /> &lt;property name="validationQuery" value="select 1 from dual"/&gt;<br /> &lt;/bean&gt;<br /><br /> &lt;alias alias="customerDataSource" name="personDataSource"/&gt;<br /></pre><b>BUT (this is the whole point of this blog post really!)</b><br /><br />If you get wiring errors when Spring tried to wire data sources into other beans it DOESN'T see aliased beans as first class citizens, when the error reports which data sources are available it won't list the aliased names, suggesting that you actually have less data sources than you really do!<br /><br />So although aliases are great (and have saved me loads of lines of duplicated XML config) make sure you consider that they won't be shown in lists of 'available data sources'.<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=6TzJGAJ7KRc:-ADFvxIO_tA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=6TzJGAJ7KRc:-ADFvxIO_tA:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=6TzJGAJ7KRc:-ADFvxIO_tA:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=6TzJGAJ7KRc:-ADFvxIO_tA:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=6TzJGAJ7KRc:-ADFvxIO_tA:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=6TzJGAJ7KRc:-ADFvxIO_tA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=6TzJGAJ7KRc:-ADFvxIO_tA:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com1http://blog.andrewbeacock.com/2011/05/misleading-wiring-messages-with-aliased.htmltag:blogger.com,1999:blog-11593374.post-5457029242959938822011-05-01T21:34:00.000+01:002011-05-01T21:34:51.732+01:00Sound advice for a source code commit frequencyA <a href="http://twitter.com/blarti">colleague</a> of mine commented recently in a discussion on how often one should commit their source code:<br /><blockquote>commit on keyup<br />&nbsp;&nbsp;&nbsp;&nbsp;- always tends to keep everything as up to the minute as possible</blockquote>Classic! and yes it was tongue in cheek advice!<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=Nkmy5Fv-diA:AJi22LZe6vc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=Nkmy5Fv-diA:AJi22LZe6vc:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=Nkmy5Fv-diA:AJi22LZe6vc:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=Nkmy5Fv-diA:AJi22LZe6vc:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=Nkmy5Fv-diA:AJi22LZe6vc:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=Nkmy5Fv-diA:AJi22LZe6vc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=Nkmy5Fv-diA:AJi22LZe6vc:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com0http://blog.andrewbeacock.com/2011/05/sound-advice-for-source-code-commit.htmltag:blogger.com,1999:blog-11593374.post-27217745141272465632011-03-28T20:27:00.000+01:002011-03-28T20:27:00.586+01:00Using & comparing enumerations (enums) with JSTLOften in your <a href="http://www.oracle.com/technetwork/java/index-jsp-135995.html">JSTL</a> pages you will want to test a value of a particular variable before displaying something on the page. Often you are comparing against primitive types or other objects but what if you want to compare against an <a href="http://download.oracle.com/javase/tutorial/java/javaOO/enum.html">enumerated type</a>?<br /><br />Attempting to access the enumeration directly as <code>Colour.BLUE</code> doesn't work as the class/enum isn't available but what you can do it compare objects against their label or enum name.<br /><br />If we have a Colour enumeration:<br /><pre class="brush:java">public enum Colour {<br /> RED, GREEN, BLUE<br />}</pre>and we have a car object which has a getColour() method on it (returning the enumerated type) we can test against it in JSTL by using the specific name:<br /><pre class="brush:xml">&lt;c:if test="${car.colour eq 'BLUE'}"&gt;</pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=hplvUKDB5L0:rxIa5_XFvpk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=hplvUKDB5L0:rxIa5_XFvpk:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=hplvUKDB5L0:rxIa5_XFvpk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=hplvUKDB5L0:rxIa5_XFvpk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=hplvUKDB5L0:rxIa5_XFvpk:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=hplvUKDB5L0:rxIa5_XFvpk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=hplvUKDB5L0:rxIa5_XFvpk:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com1http://blog.andrewbeacock.com/2011/03/using-comparing-enumerations-enums-with.htmltag:blogger.com,1999:blog-11593374.post-42339110936187645652011-03-21T23:15:00.000+00:002011-03-21T23:15:12.545+00:00Keyboard shortcut for 'paste as plain text' in PidginI use <a href="http://www.pidgin.im/">Pidgin</a> at work for communicating with my remote colleagues and I regularly paste code snippets and log file output into the Pidgin window. Often the text formats completely wrong and you end up sending the recipient a page of garbage rather than the real text.<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://lh6.googleusercontent.com/-h36BsxSVPVY/TYfbh94HdkI/AAAAAAAAAws/IUxEfgDUZkI/s1600/pidgin+paste+as+plain+text.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="236" src="https://lh6.googleusercontent.com/-h36BsxSVPVY/TYfbh94HdkI/AAAAAAAAAws/IUxEfgDUZkI/s320/pidgin+paste+as+plain+text.png" width="320" /></a></div><br />Pidgin has a right-click context menu option for getting round this called 'paste as plain text' which normally does the trick but what if you normally use CTRL-V to paste your text in? After 2 seconds of experimentation today I found that CTRL-SHIFT-V is the keyboard shortcut for 'paste as plain text', I now feel complete...<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=WdetoJlIE74:DXdVDDygFx4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=WdetoJlIE74:DXdVDDygFx4:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=WdetoJlIE74:DXdVDDygFx4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=WdetoJlIE74:DXdVDDygFx4:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=WdetoJlIE74:DXdVDDygFx4:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=WdetoJlIE74:DXdVDDygFx4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=WdetoJlIE74:DXdVDDygFx4:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com1http://blog.andrewbeacock.com/2011/03/keyboard-shortcut-for-paste-as-plain.htmltag:blogger.com,1999:blog-11593374.post-53583951551762714772011-02-11T21:42:00.001+00:002011-02-11T21:42:57.393+00:00Embedding a Google Docs spreadsheet in BloggerBlogger is an excellent free blogging platform but if you want anything 'dynamic' then it starts to get in the way. One thought I've had recently was to see how I could share information captured in Google Docs Spreadsheet with Blogger.<br /><br />I've a few ideas which will take a few posts to explain, so let's start with the most basic - embedding a Google Spreadsheet direct into Blogger.<br /><br />Access the spreadsheet in Google Docs that you want to expose in Blogger, I've chosen a simple table of the most popular programming languages in 2010:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-VHSGn-umVro/TVWs7FX-UtI/AAAAAAAAAwM/d4nyqDsWkR8/s1600/spreadsheet.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="303" src="http://4.bp.blogspot.com/-VHSGn-umVro/TVWs7FX-UtI/AAAAAAAAAwM/d4nyqDsWkR8/s320/spreadsheet.png" width="320" /></a></div><br />Next you'll want to share this spreadsheet with the rest of the world by publishing it as a web page:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-MfRpFCJHBFA/TVWtCHzkoCI/AAAAAAAAAwQ/hJ_OI_Cd9h8/s1600/publish.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="228" src="http://3.bp.blogspot.com/-MfRpFCJHBFA/TVWtCHzkoCI/AAAAAAAAAwQ/hJ_OI_Cd9h8/s320/publish.png" width="320" /></a></div><br />Now you need to select the "HTML to embed in a page" option and copy the HTML code into the clipboard:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-CPEQRjcIdHA/TVWtEovuQ5I/AAAAAAAAAwU/SQk1-hMTWWY/s1600/publish+as+a+webpage.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://1.bp.blogspot.com/-CPEQRjcIdHA/TVWtEovuQ5I/AAAAAAAAAwU/SQk1-hMTWWY/s320/publish+as+a+webpage.png" width="314" /></a></div>&nbsp;Open a new post in blogger and ensure that the "Edit HTML" tab is selected and paste the code in:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-X2iN6f6iEFM/TVWtL6Zpy7I/AAAAAAAAAwY/IA3pDhsDBvE/s1600/blogger.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="261" src="http://4.bp.blogspot.com/-X2iN6f6iEFM/TVWtL6Zpy7I/AAAAAAAAAwY/IA3pDhsDBvE/s320/blogger.png" width="320" /></a></div><br />Now publish your post and your spreadsheet will be visable in your blog post:<br /><br /><iframe frameborder="0" height="300" src="https://spreadsheets.google.com/pub?key=0AlvsnAh0wPwVdF9GSlp2Y0Z4ejBtX1RTRUUxbjY1cXc&amp;hl=en&amp;single=true&amp;gid=0&amp;output=html&amp;widget=true" width="500"></iframe><br /><br />I didn't say it would be pretty though did I? ;)<br /><br />That's the most basic way of doing it, and any changes you make in Google Docs will be reflected in the Blogger page. In the next few posts I'll show how a little HTML &amp; JavaScript coding with Google Visualisations means we can have a much neater looking table as well as access to producing some graphs of the data.<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=LtlE8DRY-l8:RdGHVBeiUTE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=LtlE8DRY-l8:RdGHVBeiUTE:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=LtlE8DRY-l8:RdGHVBeiUTE:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=LtlE8DRY-l8:RdGHVBeiUTE:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=LtlE8DRY-l8:RdGHVBeiUTE:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=LtlE8DRY-l8:RdGHVBeiUTE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=LtlE8DRY-l8:RdGHVBeiUTE:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com9http://blog.andrewbeacock.com/2011/02/embedding-google-docs-spreadsheet-in.htmltag:blogger.com,1999:blog-11593374.post-91730973979721741832010-11-08T21:53:00.000+00:002010-11-08T21:53:34.819+00:00How to use MatchMode in your JPA/Hibernate Restrictions & Criteria queriesBack in July I blogged about <a href="http://blog.andrewbeacock.com/2010/07/how-to-do-andor-type-sql-queries-using.html">how to do AND/OR type SQL queries using Hibernate AND/OR JPA using disjunctions</a>. If you looked at the example code you will have seen that I was appending "%" as the wildcard operator in my <a href="http://docs.jboss.org/hibernate/stable/core/reference/en/html/querycriteria.html#querycriteria-narrowing">Restrictions</a>.<br /><br />Since then I've used <a href="http://docs.jboss.org/hibernate/stable/core/reference/en/html/querycriteria.html#querycriteria-narrowing">Restrictions</a> a couple more times and wondered if there was a better way of specifying them other than string concatenation.<br /><br />Well there is and it's with the use of the <a href="http://docs.jboss.org/hibernate/stable/core/api/org/hibernate/criterion/MatchMode.html">MatchMode</a> class.<br /><br />Rather than this code:<br /><pre class="brush:java">import org.hibernate.Criteria;<br />import org.hibernate.Session;<br />import org.hibernate.criterion.Restrictions;<br /> <br />Criteria criteria = session.createCriteria(Product.class);<br />criteria.add(<br /> Restrictions.disjunction()<br /> .add(Restrictions.ilike("code", codeOrName + "%"))<br /> .add(Restrictions.ilike("name", "%" + codeOrName + "%"))<br />);<br />return criteria.list();</pre>You can now write:<br /><pre class="brush:java">import org.hibernate.Criteria;<br />import org.hibernate.Session;<br />import org.hibernate.criterion.Restrictions;<br /> <br />Criteria criteria = session.createCriteria(Product.class);<br />criteria.add(<br /> Restrictions.disjunction()<br /> .add(Restrictions.ilike("code", codeOrName, MatchMode.START))<br /> .add(Restrictions.ilike("name", codeOrName, MatchMode.ANYWHERE))<br />);<br />return criteria.list();</pre><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=_E9ikJ0rIM0:r_pma4RNLHo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=_E9ikJ0rIM0:r_pma4RNLHo:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=_E9ikJ0rIM0:r_pma4RNLHo:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=_E9ikJ0rIM0:r_pma4RNLHo:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=_E9ikJ0rIM0:r_pma4RNLHo:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=_E9ikJ0rIM0:r_pma4RNLHo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=_E9ikJ0rIM0:r_pma4RNLHo:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com1http://blog.andrewbeacock.com/2010/11/how-to-use-matchmode-in-your.htmltag:blogger.com,1999:blog-11593374.post-4945319152381347852010-11-03T20:53:00.000+00:002010-11-03T20:53:17.714+00:00Accessing & iterating over a Java Map in a JSP page with JSTLWhen you are coding JSP pages using <a href="http://java.sun.com/products/jsp/jstl/">JSTL</a> one thing you use a lot is the <a href="http://blog.andrewbeacock.com/2009/04/jstl-foreach-looping-tricks-using.html">&lt;c:foreach&gt; tag</a>. This tag a great for iterating over <a href="http://download.oracle.com/javase/6/docs/api/java/util/List.html">Lists</a> or <a href="http://download.oracle.com/javase/6/docs/api/java/util/Set.html">Sets</a> but what do you do when you want to display the contents of a <a href="http://download.oracle.com/javase/6/docs/api/java/util/Map.html">Map</a>?<br /><br />Firstly you need to decide how you are going to use the Map. Do you want to access a 'value' stored within the Map based on a known key or iterate over the Map displaying both key and value?<br /><br /><b>Access a Map based on a 'key'</b><br /><br />This one is pretty straight forward you just need to know the JSTL syntax:<br /><pre class="brush:xml">${aMapFullOfKeysAndValues[yourKnownKey]}<br /></pre>Two key points:<br /><ul><li> The key is an existing JSTL variable or a quoted string</li><li> You use square brackets at the end of the Map name</li></ul><b>Iterate over a Map pulling out the 'key' &amp; 'value'</b><br /><br />This is a little more complex, note the name of the variable that is filled on each pass through the Map ('entry'):<br /><pre class="brush:xml"><c:foreach items="${aMapFullOfKeysAndValues}" var="entry"><br /> ${entry.key} - ${entry.value}<br /></c:foreach></pre>Four key points:<br /><ul><li> The name of the Map is placed as the 'items' attribute of the forEach</li><li> To access the 'key' object use ${entry.key}</li><li> To access the 'value' object use ${entry.value}</li><li> If either the key or value is a complex object, simply walk into it: ${entry.value.surname}</li></ul>Hopefully that has demystified it a little, please post a comment if you found this post useful or I've missed something out!<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=auZg2B-8d1M:zk2AxJHu6pU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=auZg2B-8d1M:zk2AxJHu6pU:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=auZg2B-8d1M:zk2AxJHu6pU:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=auZg2B-8d1M:zk2AxJHu6pU:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=auZg2B-8d1M:zk2AxJHu6pU:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=auZg2B-8d1M:zk2AxJHu6pU:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=auZg2B-8d1M:zk2AxJHu6pU:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com1http://blog.andrewbeacock.com/2010/11/accessing-iterating-over-java-map-in.htmltag:blogger.com,1999:blog-11593374.post-52769374376996072412010-10-08T22:04:00.000+01:002010-10-08T22:04:38.027+01:00Spring Autowiring & Component Scanning Problems - Part 6: The RemedyPart 5 can be found <a href="http://blog.andrewbeacock.com/2010/10/spring-autowiring-component-scanning.html">here</a><br /><br />So what can you do about root context beans not being wired correctly?<br /><br />One solution is to ensure that all your root context beans have their autowiring specified via XML, either with explicit <property> elements or autowire="byType" or autowire="byName" XML attributes, but this is a bit of a backward step considering how annotation centric Spring is becoming.<br /><br />You could enable component scanning (via the <context:component-scan> XML element) and go through the beans marking them with the <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/stereotype/Component.html">@Component</a> family of annotations so that the <a href="http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-autowired-annotation">@Autowired</a> statements are picked up. You will also need to remove the XML-based bean definitions from the context files otherwise you will end up with two conflicting beans - one loaded due to the XML declaration and another loaded due to component scanning.<br /><br />Or you could switch on 'annotation awareness' by adding a <context:annotation-config> XML element to your root application context files. In fact you only need to add it to one of the root context files as all the beans are loaded into the same context and looking for autowired annotations only happens once all the beans are loaded into the context.<br /><br />Or you could do all of the above but then you might be creating new problems for yourself... ;-)</context:annotation-config></context:component-scan></property><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=bc_nzrT9aMw:gSDjTnA81Go:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=bc_nzrT9aMw:gSDjTnA81Go:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=bc_nzrT9aMw:gSDjTnA81Go:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=bc_nzrT9aMw:gSDjTnA81Go:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=bc_nzrT9aMw:gSDjTnA81Go:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=bc_nzrT9aMw:gSDjTnA81Go:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=bc_nzrT9aMw:gSDjTnA81Go:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com0http://blog.andrewbeacock.com/2010/10/spring-autowiring-component-scanning_08.htmltag:blogger.com,1999:blog-11593374.post-88701536538280509472010-10-05T21:52:00.001+01:002010-10-08T22:05:11.648+01:00Spring Autowiring & Component Scanning Problems - Part 5: The CausePart 4 can be found <a href="http://blog.andrewbeacock.com/2010/09/spring-autowiring-component-scanning_30.html">here</a><br /><br />It's not clearly stated in the Spring documentation but the auto-wiring stage for <a href="http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html#mvc-servlet">DispatcherServlets</a> only scan through the beans within it's specific application context searching for <a href="http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-autowired-annotation">autowiring annotations</a> (@Autowired, @Qualifier, etc.), it does not venture into the root application context to wire those beans.<br /><br />It sometimes appears that it does cross that root context boundary if you have root bean classes annotated with one of the <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/stereotype/Component.html">@Component</a> family and you enable your web application's component scanning to include that package. What happens is that the bean is loaded into the root application context and then an overwritten version is loaded into the <a href="http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/web/context/WebApplicationContext.html">WebApplicationContext</a>. This overlaid version is then auto-wired as it lives inside the <a href="http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/web/context/WebApplicationContext.html">WebApplicationContext</a>.<br /><br />Part 6 can be found <a href="http://blog.andrewbeacock.com/2010/10/spring-autowiring-component-scanning_08.html">here</a><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=wqo1JySRXr4:8yyDALYANHk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=wqo1JySRXr4:8yyDALYANHk:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=wqo1JySRXr4:8yyDALYANHk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=wqo1JySRXr4:8yyDALYANHk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=wqo1JySRXr4:8yyDALYANHk:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=wqo1JySRXr4:8yyDALYANHk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=wqo1JySRXr4:8yyDALYANHk:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com0http://blog.andrewbeacock.com/2010/10/spring-autowiring-component-scanning.htmltag:blogger.com,1999:blog-11593374.post-6368879563220284412010-09-30T19:41:00.002+01:002010-10-05T21:53:11.847+01:00Spring Autowiring & Component Scanning Problems - Part 4: Application Contexts<div class="western" style="margin-bottom: 0cm;"><span style="color: black;">Part 3 can be found <a href="http://blog.andrewbeacock.com/2010/09/spring-autowiring-component-scanning_20.html">here </a></span></div><div class="western" style="margin-bottom: 0cm;"><br /></div><div class="western" style="margin-bottom: 0cm;"><span style="color: black;">Spring loads beans into application contexts. Any beans declared in XML files or any annotated classes found via component scanning are placed into a suitable application context - either the root application context or one specific to the web application that the bean is declared in.</span></div><div class="western" style="margin-bottom: 0cm;"><br /></div><div class="western" style="margin-bottom: 0cm;"><span style="color: black;">Any beans declared (or scanned for) which are not <a href="http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html#mvc-servlet">DispatcherServlet</a> related (i.e. not <servlet-name>-servlet.xml files) are placed into one big root application context bucket, the support for separate XML application context files is purely a convenience for you to manage the logical separation of the beans.</servlet-name></span></div><div class="western" style="margin-bottom: 0cm;"><br /></div><div class="western" style="margin-bottom: 0cm;"><span style="color: black;">Each DispatcherServlet gets it's own <a href="http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/web/context/WebApplicationContext.html">WebApplicationContext</a> which </span>inherits<span style="color: black;"> all the beans from the root application context, overlaying all the beans defined within it's web application scope (i.e. any beans within </span><code><span style="color: black;"><servlet-name>-servlet.xml)</servlet-name></span></code><span style="color: black;">. Once all the DispatcherServlet's beans are loaded it will attempt to autowire them together and this is where the potential problems start.</span></div><div class="western" style="margin-bottom: 0cm;"><br /></div><div class="western" style="margin-bottom: 0cm;"><span style="color: black;">Part 5 can be found <a href="http://blog.andrewbeacock.com/2010/10/spring-autowiring-component-scanning.html">here</a></span></div><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=rTqGFkoN7yY:Kn_jrb9u1L8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=rTqGFkoN7yY:Kn_jrb9u1L8:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=rTqGFkoN7yY:Kn_jrb9u1L8:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=rTqGFkoN7yY:Kn_jrb9u1L8:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=rTqGFkoN7yY:Kn_jrb9u1L8:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=rTqGFkoN7yY:Kn_jrb9u1L8:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=rTqGFkoN7yY:Kn_jrb9u1L8:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com0http://blog.andrewbeacock.com/2010/09/spring-autowiring-component-scanning_30.htmltag:blogger.com,1999:blog-11593374.post-21613164726560622732010-09-20T21:24:00.002+01:002010-09-30T19:41:58.879+01:00Spring Autowiring & Component Scanning Problems - Part 3: AutowiringPart 2 can be found <a href="http://blog.andrewbeacock.com/2010/09/spring-autowiring-component-scanning_16.html">here</a> <br /><br />Having a load of beans instantiated in an application context is one thing, having them wired together so that they know about each other is another. Wiring can be done either using XML or via the <a href="http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-autowired-annotation">@Autowired annotation</a>. The annotations on their own don't cause Spring to wire the beans, you need to turn on annotation support for Spring to find them:<br /><pre class="brush:xml">&lt;context:annotation-config/&gt;<br /></pre>When added to an application context XML file it instructs Spring to look through all the loaded beans in the relevant application context for annotations like @Autowired, @Qualifier &amp; @Required. In a reasonably mature Spring application you could have the beans being wired together in a number of ways:<br /><ul><li>Explicit &lt;property&gt; XML elements referencing other beans</li><li>The addition of autowire="byType" or autowire="byName" XML attributes</li><li><a href="http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-autowired-annotation">@Autowired</a> annotations inside normal classes declared as beans in XML</li><li><a href="http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-autowired-annotation">@Autowired</a> annotations inside <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/stereotype/Component.html">@Component</a>-based classes</li></ul>Note: The &lt;context:component-scan&gt; element also implicitly defines the &lt;context:annotation-config&gt; autowiring element as well - after all if you are scanning for annotated <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/stereotype/Component.html">@Component</a> classes you want the embedded <a href="http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-autowired-annotation">@Autowired</a> annotations to be scanned for as well.<br /><br />Part 4 can be found <a href="http://blog.andrewbeacock.com/2010/09/spring-autowiring-component-scanning_30.html">here</a><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=l8QsUA1Gu9c:1qUjVrishIk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=l8QsUA1Gu9c:1qUjVrishIk:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=l8QsUA1Gu9c:1qUjVrishIk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=l8QsUA1Gu9c:1qUjVrishIk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=l8QsUA1Gu9c:1qUjVrishIk:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=l8QsUA1Gu9c:1qUjVrishIk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=l8QsUA1Gu9c:1qUjVrishIk:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com0http://blog.andrewbeacock.com/2010/09/spring-autowiring-component-scanning_20.htmltag:blogger.com,1999:blog-11593374.post-65816086297941098572010-09-16T21:09:00.003+01:002010-09-20T21:26:43.830+01:00Spring Autowiring & Component Scanning Problems - Part 2: Component ScanningPart 1 can be found <a href="http://blog.andrewbeacock.com/2010/09/spring-autowiring-component-scanning.html">here</a><br /><br />Instead of adding explicit beans to your XML files, <a href="http://www.springsource.org/download">Spring</a> 2.5 introduced the <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/stereotype/Component.html">@Component</a> annotation family (<a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/stereotype/Service.html">@Service</a>, <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/stereotype/Controller.html">@Controller</a>, <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/stereotype/Repository.html">@Repository</a> – all children of the @Component parent annotation). Simply add these object-level annotations to your class definitions to mark what type of Spring bean they are. Then add the following XML snippet to the application context XML file to tell Spring where to look:<br /><pre class="brush:xml">&lt;context:component-scan base-package="com.andrewbeacock"/&gt;<br /></pre>Spring now scans through the whole classpath for the specified package (and sub-packages) looking for @Component-based classes. Any found are created as beans and placed in the application context.<br /><br />This purely adds the beans to the relevant application context, it doesn't look inside the class for other annotations until it's finished loading all the remaining beans into the context.<br /><br />Part 3 can be found <a href="http://blog.andrewbeacock.com/2010/09/spring-autowiring-component-scanning_20.html">here</a><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=P3cYz-xM_Q4:-RMsPxwGET8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=P3cYz-xM_Q4:-RMsPxwGET8:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=P3cYz-xM_Q4:-RMsPxwGET8:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=P3cYz-xM_Q4:-RMsPxwGET8:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=P3cYz-xM_Q4:-RMsPxwGET8:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=P3cYz-xM_Q4:-RMsPxwGET8:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=P3cYz-xM_Q4:-RMsPxwGET8:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com0http://blog.andrewbeacock.com/2010/09/spring-autowiring-component-scanning_16.htmltag:blogger.com,1999:blog-11593374.post-59702242735539384692010-09-13T20:48:00.001+01:002010-09-16T21:10:46.469+01:00Spring Autowiring & Component Scanning Problems - Part 1: The ProblemLet's set the scene a little: You're a developer on a long-running <a href="http://www.springsource.org/">Spring</a>-based web application. It's a reasonably large application developed before <a href="http://static.springsource.org/spring/docs/2.5.x/reference/metadata.html">annotations</a> were a twinkle in Spring's eye and so uses <a href="http://static.springsource.org/spring/docs/2.5.x/reference/xsd-config.html">XML</a> to declare the beans and wiring. Over time the use of annotations has grown - particularly in the area of annotated controllers - and you've started to add <a href="http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-factory-autowire">@Autowired annotations</a> rather than explicitly defining the wiring in the XML application context files.<br /><br />So now you've got a good mix of XML-defined beans and annotated ones, sometimes mixing the two together; a bean is declared in the XML context file but it's wirings are defined using <a href="http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-autowired-annotation">@Autowired statements</a> rather than the usual <property> XML elements.<br /><br />Everything is working perfectly...<br /><br />You've never had a problem adding @Autowired annotations to beans until now, but a particular bean's members don't seem to get wired (you get a NullPointerException at runtime) but you don't get a wiring error. This is confusing as you know that the @Autowired annotation has 'required' set to true by default, so it should be throwing a wiring exception during the loading of the context at the very least!<br /><br />Why is it not wiring correctly? Because Spring is not even seeing the @Autowired annotation! To fully understand the issues at hand we need to wind back a bit and cover some theory.<br /><br />Part 2 can be found <a href="http://blog.andrewbeacock.com/2010/09/spring-autowiring-component-scanning_16.html">here</a><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=sw21wdKQH2E:NaOjmVAx3Nk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=sw21wdKQH2E:NaOjmVAx3Nk:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=sw21wdKQH2E:NaOjmVAx3Nk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=sw21wdKQH2E:NaOjmVAx3Nk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=sw21wdKQH2E:NaOjmVAx3Nk:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=sw21wdKQH2E:NaOjmVAx3Nk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=sw21wdKQH2E:NaOjmVAx3Nk:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com0http://blog.andrewbeacock.com/2010/09/spring-autowiring-component-scanning.htmltag:blogger.com,1999:blog-11593374.post-80100481306010628052010-09-13T20:43:00.001+01:002010-09-13T20:43:38.889+01:00Something new for my blogI'm going to try something new, a multi-post feature which is basically an article I've written for an open source journal but broken up into bite-sized pieces and posted over a couple of weeks (or so).<br /><br />Please comment if you like it, find it annoying, my content is completely wrong, etc. I'd like to hear from you.<br /><br />My series is on "Spring Autowiring & Component Scanning Problems"<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=rfx_9yTco-s:NDeNziqZ86c:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=rfx_9yTco-s:NDeNziqZ86c:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=rfx_9yTco-s:NDeNziqZ86c:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=rfx_9yTco-s:NDeNziqZ86c:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=rfx_9yTco-s:NDeNziqZ86c:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=rfx_9yTco-s:NDeNziqZ86c:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=rfx_9yTco-s:NDeNziqZ86c:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com1http://blog.andrewbeacock.com/2010/09/something-new-for-my-blog.htmltag:blogger.com,1999:blog-11593374.post-5324199716098106152010-08-16T21:32:00.002+01:002010-08-16T21:32:50.923+01:00Have more than one gmail account?Not sure if you are aware of this but Google have added a rather funky dropdown account selector to a number of their applications, more details are here:<br /><br /><a href="http://gmailblog.blogspot.com/2010/08/access-two-gmail-accounts-at-once-in.html">Access two Gmail accounts at once in the same browser</a><br /><br />A damn fine invention if you ask me!<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=N6N-nmQitao:JH-J74bUyPw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=N6N-nmQitao:JH-J74bUyPw:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=N6N-nmQitao:JH-J74bUyPw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=N6N-nmQitao:JH-J74bUyPw:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=N6N-nmQitao:JH-J74bUyPw:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=N6N-nmQitao:JH-J74bUyPw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=N6N-nmQitao:JH-J74bUyPw:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com0http://blog.andrewbeacock.com/2010/08/have-more-than-one-gmail-account.htmltag:blogger.com,1999:blog-11593374.post-61851981374229482252010-07-29T21:46:00.002+01:002010-07-29T21:48:00.561+01:00How to do AND/OR type SQL queries using Hibernate AND/OR JPA using disjunctionsIf you have been using <a href="http://www.hibernate.org/">Hibernate</a> or <a href="http://en.wikipedia.org/wiki/Java_Persistence_API">JPA</a> for a while you will know that the <a href="http://docs.jboss.org/hibernate/stable/core/reference/en/html/querycriteria.html">Criteria</a> and <a href="http://docs.jboss.org/hibernate/stable/core/reference/en/html/querycriteria.html#querycriteria-narrowing">Restrictions</a> classes are very handy for querying the database without writing any SQL code and without worrying about the real column names (these are all captured in the annotations that you have applied to the domain objects).<br /><br />This is fine when you want to search for objects (rows) which are a combination of columns such as forename = "Andrew" AND surname = "Beacock" but what if you want to search for all people who either have a forename of Andrew and/or a surname of Beacock?<br /><br />This is where a "<a href="http://docs.jboss.org/hibernate/stable/core/api/org/hibernate/criterion/Restrictions.html#disjunction%28%29">disjunction</a>" comes in. This is one of the types hanging off the <a href="http://docs.jboss.org/hibernate/stable/core/api/org/hibernate/criterion/Restrictions.html">Restrictions</a> class and deals with AND/OR situations. The code below is looking through the 'products' table for any product that has a code or name starting with the text supplied:<br /><br /><pre class="brush:java">import org.hibernate.Criteria;<br />import org.hibernate.Session;<br />import org.hibernate.criterion.Restrictions;<br /> <br />Criteria criteria = session.createCriteria(Product.class);<br />criteria.add(<br /> Restrictions.disjunction()<br /> .add(Restrictions.ilike("code", codeOrName + "%"))<br /> .add(Restrictions.ilike("name", codeOrName + "%"))<br />);<br />return criteria.list();</pre><br />You can obviously add as many additional Restrictions as you like to the disjunction to make it as simple or complex as you like...<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=PCMOseti7bw:grwwKI7y840:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=PCMOseti7bw:grwwKI7y840:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=PCMOseti7bw:grwwKI7y840:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=PCMOseti7bw:grwwKI7y840:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=PCMOseti7bw:grwwKI7y840:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=PCMOseti7bw:grwwKI7y840:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=PCMOseti7bw:grwwKI7y840:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com0http://blog.andrewbeacock.com/2010/07/how-to-do-andor-type-sql-queries-using.htmltag:blogger.com,1999:blog-11593374.post-77801667952478170222010-07-22T20:47:00.000+01:002010-07-22T20:47:18.904+01:00iPhone version of the excellent Password ComposerI've been using the excellent <a href="http://www.xs4all.nl/%7Ejlpoutre/BoT/Javascript/PasswordComposer/">Password Composer</a> <a href="http://www.greasespot.net/">Greasemonkey</a> script for <a href="http://www.firefox.com/">Firefox</a> for over 2 years now - it's a great way to ensure that your master password isn't spread around the web yet never gets in the way of accessing a site.<br /><br />My collegue<a href="http://andykayley.blogspot.com/"> Andy Kayley</a> recently pointed out that there is an <a href="http://www.indelible.org/ink/iphone-pwdcomposer/">iPhone version</a> available so that you can easily access your <a href="http://www.xs4all.nl/%7Ejlpoutre/BoT/Javascript/PasswordComposer/">Password Composer</a> encrypted passwords whilst on the move!&nbsp; It's written by <a href="http://www.indelible.org/about/">Jon Parise</a> and not only does he include a <a href="http://www.indelible.org/ink/iphone-pwdcomposer/">link to his version</a> but also goes into excellent detail on how he developed the iPhone application!<br /><br />Now I just need to get myself an iPhone... ;)<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=N7DcPbT5QgU:1X3o8nz3OLc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=N7DcPbT5QgU:1X3o8nz3OLc:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=N7DcPbT5QgU:1X3o8nz3OLc:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=N7DcPbT5QgU:1X3o8nz3OLc:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=N7DcPbT5QgU:1X3o8nz3OLc:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=N7DcPbT5QgU:1X3o8nz3OLc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=N7DcPbT5QgU:1X3o8nz3OLc:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com1http://blog.andrewbeacock.com/2010/07/iphone-version-of-excellent-password.htmltag:blogger.com,1999:blog-11593374.post-83755795669583035032010-05-17T22:27:00.001+01:002010-05-17T22:27:46.763+01:00googlemail is going, gmail returns (if you're in the UK)This might be old news now but Google now have the ability to use 'gmail.com' for UK people rather than the awkward 'googlemail.com':<br /><blockquote>Why did you change the name from Google Mail to Gmail?<br /><br />A little more than a year after Gmail first launched, Google changed the name of its webmail service in the United Kingdom to "Google Mail" due to negotiations over a trademark dispute. We have reached a settlement, so we are happily changing the name back to Gmail, and offering @gmail.com addresses to all Google Mail users in the UK. Plus, it's shorter and easier to type this way :) </blockquote>There's more information about it here: <a href="http://gmailblog.blogspot.com/2010/05/google-mail-is-becoming-gmail-in-uk.html">Google Mail is becoming Gmail in the UK</a><br /><br /><span class="technoratitag">Technorati Tags: <a href="http://www.technorati.com/tags/Google" rel="tag">Google</a>, <a href="http://www.technorati.com/tags/Gmail" rel="tag">Gmail</a>, <a href="http://www.technorati.com/tags/Andrew%20Beacock" rel="tag">Andrew Beacock</a></span><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=X4lUR2EAVqs:TawpEJ608TU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=X4lUR2EAVqs:TawpEJ608TU:dnMXMwOfBR0"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=dnMXMwOfBR0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=X4lUR2EAVqs:TawpEJ608TU:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=X4lUR2EAVqs:TawpEJ608TU:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=X4lUR2EAVqs:TawpEJ608TU:63t7Ie-LG7Y"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?d=63t7Ie-LG7Y" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/andrewbeacock?a=X4lUR2EAVqs:TawpEJ608TU:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/andrewbeacock?i=X4lUR2EAVqs:TawpEJ608TU:V_sGLiPBpWU" border="0"></img></a>
</div>Andy Bhttp://www.blogger.com/profile/01039992884679308726noreply@blogger.com0http://blog.andrewbeacock.com/2010/05/googlemail-is-going-gmail-returns-if.html