Thursday, February 18, 2010

get values from form in controller by auto-mapping

Given:
we expect data send from form, that is fully or partly described in requestListSearchCommand POJO Bean.
We expect that data will be auto-wired by spring and request (POST/GET) parameters values will be set to the bean fields

wrong:
@ModelAttribute("requestListSearchCommand")
public RequestListSearchCommand addSearchParameters(
@RequestParam(value = "requestListSearchCommand",required=false)
RequestListSearchCommand requestListSearchCommand) {

if (requestListSearchCommand != null) { // always FALSE
requestListSearchCommand = new RequestListSearchCommand();
}
requestListSearchCommand.setSameValue(service.getFromService(randomThing));


Solution:


@ModelAttribute("requestListSearchCommand")
public RequestListSearchCommand addSearchParameters(
@ModelAttribute(value = "requestListSearchCommand")
RequestListSearchCommand requestListSearchCommand) {

if (requestListSearchCommand != null) { // always TRUE
requestListSearchCommand.setSameValue(service.getFromService(randomThing));
}

Spring does auto-mapping request parameters on parameters beans while bean is getting from model.

Tuesday, February 16, 2010

freemarker macro complex param issue

GIVEN:

<#macro lalala xxx yyy="BYBYBY" >
title=${title}, order = ${currentSort}


NEED:
<@lalala "ssssssssss" ((requestListSearchParam.order)!"") />
RESULT:
Expected method. "ssssssssss" evaluated instead to freemarker.template.SimpleScalar on <.....> The problematic instruction: - ==> macro lalala [on line <.........................>


FIX:
<#-- COMMA (,) ADDED -->

<@lalala "ssssssssss", ((requestListSearchParam.order)!"") />

Friday, February 5, 2010

testng fixtures in test class

* it runs before whole Test class started to process (fail!)

@BeforeTest
protected void setUp() throws Exception {



* it runs before every test method in Test class (ok)

@BeforeMethod
protected void setUp() throws Exception {