Tuesday, March 31, 2009

Ext JS - Disabling FormPanel submit if validation fails

To disable the FormPanel's submit button if the validation fails (example like allowBlank:false). You will need to set the FormPanel's monitorValid to true and the submit button's formBind to true.

[sourcecode language='jscript']
var form=new Ext.form.FormPanel{
monitorValid:true,
items:[{
name:"testing",
xtype:'textfield',
fieldLabel:'Test',
allowBlank:false, //Must be filled in
value:'' //Set the value so that the validation will trigger
}],
buttons:[{
text:'Submit',
formBind:true //If validation fails disable the button
}
]
}
[/sourcecode]

In some cases you might need to set the value of the textfield or combobox explicitly to empty string. If not the validation will not kick in.
Links

Login Form: Disable 'submit' until username has been input

Thursday, March 26, 2009

Visual VM -

Found an interesting video on how to use Visual VM that comes with JDK 6 update 7 to see what's happening in Glassfish. Looks like an interesting tool to find out whether your app servers are leaking memory.

Java VisualVM User Guide:
http://java.sun.com/javase/6/docs/technotes/guides/visualvm/index.html
VisualVM project page:
https://visualvm.dev.java.net/gettingstarted.html

Sunday, March 15, 2009

Keeping your boss in the loop - Software Projects

When I was serving in the Navy, I had a CO who liked to be informed of everything that is happening on the ship. Cause it's his ship and he should be in the know for what happens around. And on a ship there are many departments like engineering, electronics, navigation and so on, and all these department has to coordinate with people all round, inside the ship as well as departments outside the ship so you can see it's quite hard for him to be on top of everything. If something happens and he is not informed, he is not too pleased especially if the information came from some other source. So the people on the ship developed a habit to always inform the CO of what's happening around the ship, to always keep him "in the loop" so to speak. He will offer his advice and even help to resolve some of the issues.

Now trying to keep up with what's going on in a software project is similarly just as hard as on a ship. There are so many components that make up the project and there are co-ordination between people from QA , procurement and even other project teams that you are interfacing with. The project lead/manager will be the person that management will most likely ask on a regular basis what's happening to the project. They might use things like monthly reports to update management to keep track of the progress, issues and so on.

Now what happens when management gets uncomfortable about the project, most likely management  do some or all of the below

  1. More meetings

  2. From monthly to weekly reports

  3. In extreme cases even bother the developers to give him reports on what they are doing

User Story Estimation Resources

Wednesday, March 4, 2009

Spring DataBinding and PropertyEditors

To bind data from a <form> to a SimpleFormController is easy, just read Spring MVC Step by Step in the Spring distribution and they show you how to do it. But what happens when you need to translate strings that represent dates to Date objects? or translate from JSON string to an Object?


To that you'll need to create a custom PropertyEditor and override initBinder in SimpleFormController, to tell the controller how to handle the data that return from a HttpServletRequest object. By default it does a simple mapping, that is to say it tries to read the keys from HttpServletRequest and tries to find the corresponding setter in the commandClass and sets the value. If it can't it will generate a DataBinding error.


e.g


If the class has a setter named setText and the HttpSerlvetRequest has a parameter with the key "text", the binder will try to set the value of the key into the object specified by the commandClass.


Sample code from overiding initBinder using CustomDateEditor to read dates


protected void initBinder(HttpServletRequest request,
ServletRequestDataBinder binder)throws Exception{
SimpleDateFormat df=new SimpleDateFormat("dd/MM/yyyy");
CustomDateEditor cde=new CustomDateEditor(df,true);
binder.setCustomEditor(Date.class,cde);
super.initBinder(request,binder);
}

I suggest you look at this presentation to get a feel of the workflow for the SimpleFormController. For Spring MVC it is important to know how the flow if the controller is so that you can understand how the various overrides will work.


For custom PropertyEditors you can look at the source for CustomDateEditor to get a feel how to implement. Most of the property editors will inherit from PropertyEditorSupport rather then implementing PropertyEditor staright.


It seems like the few methods that you will need to override are the setAsText and getAsText methods. And in these 2 methods you will need to use setValue and getValue to set the correct object so that the binder can retrive the final object. So a custom PropertyEditor might look something like this:


public class CustomEditor extends PropertyEditorSupport{

public CustomEditor(){}

public void setAsText(String text){

//Do some proccessing then call setValue(); to set the object
setValue(someObject);

}

public String getAsText(){

SomeObject obj=getValue();

//Do something to get the thing as text again

}

}

The only puzzling thing (at least to me) is why does Spring use the ProperyEditor interface for something that could probably be implemented by using a simpler interface consiting of the above 4 methods (setAsText,getAsText,setValue,getValue)? I have no idea it seems that lots of methods in the interface are not  being use and they could probably be served by using a simpler interface.


Links


CustomDateEditor source