środa, 11 maja 2011

Adding key event to dojo widget

Remember.... if you want your users using any key on whole page in IE you need to pass 'the highest' widget from your page. I just lost some time, because examples on google shows cases from firefox where you can simply pass null and everything works ok.
...
var widget = dojo.byId("some_widget");
dojo.connect( widget, "onkeypress", some_function );
...

środa, 26 stycznia 2011

How to debug applications run by mvn jetty / tomcat in netbeans?

My mates asked me many times about this, so this post is just short information.

For mvn jetty, just add line like this:

set MAVEN_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=4000 -Xmx512m -Xms256m -XX:MaxPermSize=192m -XX:+UseParNewGC -XX:+UseConcMarkSweepGC

in your $MVN_HOME/bin/mvn.bat file. Then just attach debugger from netbeans: Debug->Attach Debugger where options are:

Debugger: Java Debugger (JPDA)
Connector: SocketAttach(Attaches by socketto other VMs)
Transport: dt_socket
Host: your_host_name
Port: 4000 ( port is set in mvn.bat line which we added)

You can easily debug applications which are working on local tomcat. Its done by similar to maven configuration. Add line:

set JAVA_OPTS=-server -Xmx1024m -Xms1024m -Xdebug -Xrunjdwp:transport=dt_socket,address=7779,server=y,suspend=n -Dfile.encoding=ISO-8859-2 -XX:MaxPermSize=192m -XX:+UseParNewGC -XX:+UseConcMarkSweepGC

in your $TOMCAT_HOME/bin/catalina.bat file. Debugger configuration in netbeans is same like above.

Be aware, that options set by these lines are specific to our development environment, change them if needed.

Happy debuggging : )

czwartek, 25 listopada 2010

Growing object-oriented software, guided by tests - book review.

TDD is very modern subject on IT scene nowadays. It makes - with no doubt - more useful code design, which is easier to maintain and refactor. Ok - there are still many sceptic developers, but I would name them 'lazy' instead 'sceptic' ;).

I found this book very inspiring - one of these which change your point of view, move you to keep trying getting better. I was amazed with some pieces of code - I mean ease of reading it like a normal sentence - not code ( example: building objects with builder pattern in chapter 22 ).

"If you want to be an expert in the state of the art in TDD, you need to understand the ideas in this book" - one of many wise sentences from book. Too bad that it is sometimes really hard to catch what is main subject, which authors try to sell to reader. Part III which should be the most interesting - "A Worked Example" was simply boring - I cant see sense of showing building tests for each functionality - I found it boring and hard to overcome. However I still have in mind that I am beginner in TDD world. Maybe some subjects are too hard to understand it now ; )

What I miss in this book is advice how to work properly and effective with legacy code. I mean - how to refactor 10-years old project which didnt see any test in its miserable life.

There are many places where authors try to inspire readers. They show that previous implementation wasn't the best possible, and make you feel that they really didn't know they can make it better before. Ofcourse with TDD you are not scared anymore to refactor anything ;)

To sum up - it is really book from TOP. Nevertheless, too hard to be 1st on TDD way and just one of many books/articles/blogs/conversations which you need to pass to become test-master. I want to read it one more time after some other materials about testing, just for better understanding - lazy developer with will to read it one more time should convince you, really ; )

wtorek, 16 listopada 2010

JavaFX interesting script features

Recently I have started to read about JavaFX. There are many various opinions about this technology... so I decided to take a look on some basics to get any opinion on my own. As a programmer I prefer some 'code-meat' in my IDE rather than playing with GUI, so "Learning the JavaFX Script Programming Language - Tutorial Overview" was my very first guest in browser ( http://download.oracle.com/javafx/1.3/tutorials/core/ ). Code examples are copied from this tutorial.

I just want to share with you with some basic techniques which made 'nice/strange' feeling in my mind ; ) I couldn't run JavaFX brush for SyntaxHighlighter plugin, so some colors dont fit well to code - sorry for that.

Tired of 'plusing' or appending strings? Join them using binding:
def thirdVar = "{one}{two}";
You can even use 'if' statements in line to build string:
var s = "The answer is {if (answer) "Yes" else "No"}";
Use dynamic types if you admire flexibility...
def numOne = 1.0; 
def numTwo = 1;   
...change it to static if you are big fan of clear-intention-code:
def numOne : Number = 1.0;
def numTwo : Integer = 1;

Somehow each introduction of new language contains some mind-twisters about collections/arrays. JavaFX is not an exception, but authors named this structure as 'sequence':
def nums = [1,2,3,4,5];
//sequence with numbers only greater than 2
def numsGreaterThanTwo = nums[n | n > 2];

...
//reverse values in sequence
var nums = [1..5];
nums = reverse nums; // returns [5, 4, 3, 2, 1]

Lets take sequence which contains strings. Do you want to insert new string in specific place? Not a big deal, really. Sql-developers would love that:
def weekDays = ["Mon","Tue","Wed","Thu","Fri"];
insert "Thu" before days[2];
...
delete "Sun" from days;

Nice feature is defining sequences with range syntax, but its not the end - you can easily set interval for this range:
var num = [0..5];
var nums = [1..10 step 2];
println(nums);//output: [ 1, 3, 5, 7, 9 ]

Coding in JavaFX seems easy to learn - its the most important when you need to kick start your project in new technology.

I have some GUI tutorials after me, but too less to consider JavaFX as concurent to any technology made for client-apps. Im going to look further into it, so stay tuned ;)

piątek, 5 listopada 2010

„Wicket in action” book review

You are software developer. If you are reading this that gives some high possibility that you work with java. I would ask you to recommend me some web framework which is easy to kick start, precise and mature enough to work on production environment. Additionally I don’t want to waste time on crawling in tons of xml-hell files and maintenance of application state and session. Maybe after some time for thinking you would give me an answer, but its not so easy to find any technology like this. I found it – Apache Wicket ; )

I started to read book just after running some tutorial application, so I expected some simple step-by-step guide which could help me to understand basic concepts. Book started to meet my expectations at 8th page - it is 1st with some ‘Wicket’ code, then authors slowly – but fast enough to not make readers sleepy – show how to build web application from scratch. There are a lot of examples with ‘not the best possible’ code which is then refactored, this gives guarantee of deep understanding of each subject.

Suprisingly I felt like getting into ‘flow’ while reading, which is hard to achieve in book about any technology. It’s a matter of taste if you are going to like authors style, but they for sure have some gift to share experience and knowledge with readers. In my personal opinion some chapters are not well arranged, there are subjects which are covered too late. Some concepts are shown too many times while others still fly in reader’s mind without explanation, however its very rare feeling and doesn’t disturb overall feeling.

I always expect the highest quality from Manning book every time I take it to my hands. Once again I am not disappointed. Great book, nice technology - after working with Cocoon, some tryouts with JSF - Wicket is like a cold beer in hot day :)

czwartek, 4 listopada 2010

PLSQL dynamic code = execute immediate

Some time ago i was searching for examples of running dynamic pieces of code in pl/sql. 'execute immediate' - hero helped me :)

You can run some super fancy code with it like:
execute immediate 'select 1 from dual' into w_variable;
or
declare
column varchar2(15) :='name';
table_name varchar2(15) := 'test_table';
begin
execute immediate 'select ' || column || ' from ' || table_name;
end;


which is still not impressive enough to surprise even not-pl/sql developer, you can easily achieve this by using sys_refcursor.

Basically you can run any kind of code in this block. Only thing you have to remember - this is anymous blok. There is no straight-access to fields of surrounding code. So if you need to set dynamically some fields of type you should do it like this:
execute immediate '
declare
some_type SOME_TYPE;
begin
some_type := :1;
'|| 'some_type.' || field_name  || ' := ''' || column_value ||''';
:2 :=some_type;
end;'
using in SELF, out SELF;

You need to declare field of type SOME_TYPE in this block, otherwise it wont work.

Execute immediate can be used to create types, packages etc dynamically - so its really powerful when you require such a functionality.

czwartek, 18 lutego 2010

"Open Source SOA" book review


Open Source SOA
Jeff Davis
Manning


To be honest SOA has been some kind of black box for me. I believe that we all run into many technologies’ shortcuts that we don’t really know. I use to read everything what looks interesting in ‘IT-way’ – you never know when it is going to be useful while chit-chat with boss ;)


Book is split in five chapters.:

I Chapter
“History and principles’. I see your face – “im not interested – lets move on”. I thought the same – but this chapter is really great view on technologies which are main parts of SOA. Additionally author made not so short (30 pages) review why he chose these technology solution instead the other – so reading this chapter would prevent later questions – “Why Synapse instead Servicemix?”

II Chapter
“Assembling components and services”. This chapter is about using SCA with Apache Tuscany. Examples are shown in ‘step-by-step’ style, so its easy to understand that there are many ways to solve each problems.

III Chapter
“Business Process Management”. BPM is called by Jeff Davis as “secret sauce of SOA”. In my opinion it’s the most interesting chapter of this book. BPM is shown from jBPM solution point of view. Subject is well-covered with code examples and eclipse jbpm plugin screenshots so we clearly understand what author tries to show us.

IV Chapter
“Event stream processing, integration and mediation”. Chapter 4th contains review on event processing with Esper (with EPL language) and ESB implementation with Synapse.

V Chapter
“Enteprise Decision Management”. Drools – engine for defining rules - is main actor in this chapter.

In my opinion “Open Source SOA” is a great – but not so easy to read – book. Huge subject made every page full of technology information but this makes it useful for beginners and professionals. There are a lot of examples in a book…but that’s not all! You can download source codes from Internet (150mb!) which covers each chapter. Additionally you can find readme.txt file for every part which shows how to run it, so basically it is easy to start – and its worth your time for sure.