Sunday, July 5, 2009

GWT ftw

The google web toolkit provides a kickass infrastructure for creating ajax-powered web apps right from java code. The gwt compiler will transform the java into javascript and the results are stunning. Here are 2 very sweet links for easy learning the basics of GWT, mainly the RPC (remote procedure call) feature:
http://www.vogella.de/articles/GWT/article.html
http://developerlife.com/tutorials/?p=125

Friday, May 8, 2009

Misinterpretation (or the reason why FAQ sounds like "fuck you")

I was trying to get the size of a JDBC result set without the usage of some gay code like "while(rs.next()) { //increment an index}" or worse, creating another statement with the query "select count(*) .... " to retreive only the number of rows from the targeted table.
Even though at first you might want to try resultSet.getFetchSize() , it will not get the "fetch size" specified in the nomenclature, i.e. the number of rows you seek. A closer peek at the jdbc documentation states that getFetchSize() "Retrieves the number of result set rows that is the default fetch size for result sets generated from this Statement object" .
The solution for this ? there is no predefined method in the Statement metadata to return the result set size without parsing it... you may need to choose one of the (gay) methods specified above or find some other.

Saturday, May 2, 2009

parse me again blues

Having the DB entity "Message" with ID and text, i was returning with the entity manager a collection of the form Set<Message> . After obtaining this set i needed to line these messages in a forum thread i was building. The problem isn't that i couldn't get the messages but the message list was not sorted by id (which i recon is by default because that's how result sets go), so everytime i refreshed my forum page, i got those messsages in a different order.
My solution? Altough redneck-ish, i've manually sorted the Set<Message> collection before returning it :p
 

Monday, April 27, 2009

note to self (eclipse bug)

If you add a file to the project folder outside the Eclipse IDE, that file will not be seen inside the IDE until that particular project is refreshed :|

Friday, April 24, 2009

Java operators game

Given the following code:
   int var = 2;
   var+= 2.5;
   System.out.println("var="+var);
the result will be var=4
Now we change that to
   int var = 2;
   var=var + 2.5;
   System.out.println("var="+var);
The result should be the same at first sight but it's not. Compound operators do implicit casting whereas the line "var=var + 2.5;" does not. Explicit casting is required in this situation.
       Have a nice day!

Thursday, April 23, 2009

Spring & XML quickie

something nasty occured today as i tried to pass an attribute from a spring controller to a JSP-page view. That attribute is an XML string of the form "<root><item1>...</item1><item2>...</item2>...</root>", written without newlines. all fine and dandy so far, but when i tried to obtain the attribute in my jsp using ${var}, all i got was the item values without any of the tags... to fix this i had to rewrite the code in the jsp to  <% String str = request.getAttribute("var").toString %> . I'm curious why the jsp has interpreted the xml string like that