Posts

No Scope registered for scope request

Recently I was working with some code which defined beans as request scope. Junit tests failed with the following exception while trying to initialize the application context: Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: ...; nested exception is java.lang.IllegalStateException: No Scope registered for scope 'request' I found the solution by searching around (unfortunately I didn't record the sources). Basically, you can register the required scopes as shown below: [sourcecode language='java'] import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestScope; import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.SessionScope; public class SampleTest extends AbstractDependencyInjectionSpringContextTests { @Override protected v...

Trinidad and text wrapping

While using Trinidad 1.0.1 I came across a problem where text did not wrap when displaying read only text fields. This meant that everything was pushed off the right hand side of the page. I had to change the fields from: <tr:inputText label="#{msgs['message1']}" styleClass="labelRight" required="false" value="#{mybean.value}" id="mybean" columns="10" readOnly="true"/> to <tr:panelLabelAndMessage label="#{msgs['message1']}"> <tr:outputText value="#{mybean.value}" /> </tr:panelLabelAndMessage> and added the following to my style sheet: .af_panelFormLayout_content-cell { white-space: normal; } Note outputText instead of inputText. It was tricky to get it working in FF and IE at the same time.

Virtual machines with VirtualBox

I've found VirtualBox to be very easy to create virtual machines - it's free, open source, and available on Windows, Linux, Macintosh and OpenSolaris. One of the features I particularly like is being able to create a virtual disk that grows as needed ( dynamically expanding image ). You can also mount an iso image for the CD/DVD drive - which is exactly what I want to do when installing the operating system on my new virtual machine. Installing on Ubuntu is as easy as: sudo apt-get install virtualbox Now, from the Applications/Accessories/VirtualBox OSE menu item, you can start VirtualBox and create virtual machines. Several things I need to remember after I've created a new machine: Under "Settings/General/Advanced" select "Enable PAE/NX" to avoid the "This kernel requires the following features not present on the CPU: 0:6 Unable to boot - please use a kernel appropriate for your CPU." Under "Settings/Network/Adapter 1" select ...

Finding constraints in Oracle

It can be quite frustrating when you get exceptions like those below - constraint violations where the constraint has a system generated name which means nothing to you: 2009-03-23 23:30:43 ERROR [AbstractFlushingEventListener.performExecutions] Could not synchronize database state with session org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update ... Caused by: java.sql.BatchUpdateException: ORA-00001: unique constraint (SAMPLE.SYS_C00123456) violated ... The easiest way to find out which table this constraint is associated with is to issue a statement as shown: select constraint_name, table_name from user_constraints where constraint_name='SYS_C00123456'; Now you know the table involved, you can easily find out the exact nature of the constraint in various ways - my tool of choice is SqlDeveloper - a GUI interface to Oracle (and other) database.

Just for a bit of fun... whohasmorefollowers.com

Recently I jumped on the Twitter bandwagon and created whohasmorefollowers.com - a simple service that lets you compare the number of followers for 2 Twitter users. This weekend I added a game feature to it - the player is presented with 2 random twitter users (from the top 50) and is challenged to guess which user has the most followers. It makes you think, and the results can surprise you! Why build such a thing? Well, just for a bit of fun really. But it was also a good excuse to familiarise myself with: jquery jquery plugins ( jquery.template ) blueprint css framework Another added benefit was with having such a simple application was that the whole exercise fitted into a very short timebox . The exposure to these frameworks made it worthwhile doing, and it reminded me how painful IE can be. If you're interested, play the game and tweet your score!

Redirecting javathinking.com to www.javathinking.com

I thought it would be a good idea to redirect requests to http://javathinking.com to http://www.javathinking.com and I found out how to do that easily here. Basically I just needed to add the apache directives: RewriteEngine on RewriteCond %{HTTP_HOST} ^javathinking.com RewriteRule ^(.*)$ http://www.javathinking.com$1 [R=permanent,L] In ISPConfig this can be done easily through the administration console rather than editing the apache config files. Firebug shows me that I am now getting a 301 redirect when accessing http://javathinking.com.

cp with force overwrite

I was recently trying to copy a directory over an existing one and kept getting prompted - asking if I wanted to overwrite existing files - even though I was using the force option: cp -Rf dir1 dir2 I found the answer  here  - it was caused by an alias forcing the interactive mode. Quick solution is to bypass the alias by an absolute reference to cp: /bin/cp -Rf dir1 dir2