21/10/2013

[PL/SQL] Oracle continue loop with goto

Oracle database versions previous than 11g do not support the CONTINUE statement to skip to the end of a loop and keep cycling. As an alternative, you can use the GOTO statement WITH CAUTION.

Firstly, declare a label which marks the point were you want the execution to continue from using:

 <<label_name>>  

and remember that the label must be followed by an executable statement; in practice, it means you cannot place it directly before the END LOOP instruction. Instead, follow it with a NULL statement as in:

   <<label_name>>  
   NULL;  
 END LOOP;  

Then simply skip to it as needed with:

GOTO label_name;

12/10/2013

[Java] Keep HTML form filled after failed Spring validation

I was working on a JSR-168 portlet written in Java 4 using Spring 2 and I had plain HTML forms validated via Spring validators. Everything works fine with this setting but upon failed validation, the page would reload showing the errors and an empty form.

Instead of replacing all the forms with Spring ones (form:form), I found an alternative solution which let me keep my current project structure and tone down the necessary modifications.

08/10/2013

[Java] Store session attributes in portlet controller and retrieve them from JSP

I was coding a portlet following the JSR-168 specification and Spring 2 and I noticed an inconsistent behaviour on some pages. Passing some Map objects, needed to initialize the JSP drop-down menus, by storing them in session in the controller and retrieving them in the JSP, would work always except when the page was reloaded after a failed form validation during the submission phase.

Note: this issue could not be solved by simply using the ModelAndView addObject("name", value) method in the controller and then retrieving the object in the JSP with ${name} outside of a Java block, since I needed to perform some actions on those values directly from the JSP, therefore inside a Java block, without using EL.

25/09/2013

[Java] Spring use DAO in JSP page

So you're happily coding your webapp with Spring, and have all your DAOs correctly defined as beans; you know they work because you are constantly injecting them around, but now you need to access one of them from a JSP.. how?

You may find this code fragment useful:

 <%@page import="com.groglogs.mydaos.MyDao"%>  
 <%@page import="org.springframework.web.context.WebApplicationContext"%>  
 <%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>  
   
 <%  
 MyDao myDao = null;  
   
 WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());  
 if (context != null) {  
   myDao = (MyDao) context.getBean("myDao");  
 }  
 %>  

You import your DAO, and request it directly from the JSP. Note that this example relies on the fact that somewhere you have correctly defined a bean named "myDao".

19/09/2013

[Eclipse] Comparison method violates its general contract error when updating

When installing updates in Eclipse, you may encounter the "Comparison method violates its general contract" error.

This may be related to a known bug in older Eclipse versions when using new JDKs (>6), I encountered it even using a JDK6 with latest Helios though. To fix it, try adding:

-Djava.util.Arrays.useLegacyMergeSort=true

in your eclipse.ini file, after the -vmargs flag, then restart Eclipse and run the update manager again.

[Eclipse] Slow update process

When installing updates via the Eclipse update manager, it sometimes takes forever to complete the update process, even for very small updates.

One cause may be Eclipse trying to contact all known sites when fetching updates. To avoid that, try adding:

-Declipse.p2.mirrors=false

in your eclipse.ini file, after the -vmargs flag then restart Eclipse. Alternatively, you can uncheck the "Contact all update sites" flag every time you run an update from the update wizard.

10/09/2013

[Windows] Manage printers from command line

On Windows, you can manage the printers connected to your computer from the command line either via Rundll32 printui.dll,PrintUIEntry on 32-bit systems or Cscript.exe and the Prnmngr.vbs script on 64-bit systems.