Archive for June, 2011

svn ignore or exclude target folder


Problem: How to ignore target and other folders during svn synchronization in eclipse

Solution:

First of all, the best practice is not to check in any folders which could be modified outside subversion context e.g. target, logs etc.

To avoid these folders appear every time when you synchronise add them to svn:ignore, usually by right clicking and selecting the target to add to svn:ignore or from project properties.

Leave a comment

Maven web resources filtering


Problem: How to perform maven filtering for resources inside webapp

Solution: To acheive this, we need to add the below plugin inside pom.xml and include the resources that need to be filtered, in this example, its *.html

<!– Enabling and configuring web resources filtering –>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<webResources>
<resource>
<filtering>true</filtering>
<directory>src/main/webapp</directory>
<includes>
<include>**/*.html</include>
<!– include any other file types as needed –>
</includes>
</resource>
</webResources>
</configuration>
</plugin>

once the resources are filtered, pom specific settings will be available in the html, for example version of the project can be accessed from the html as ${project.version}

Leave a comment

JQuery


Problem: How to use jquery to set the values of selected dropdown  and selected checkboxes inside html/jsp

Solution:

Inside your jsp, add script tag and define functions that will called during the events from dropdown(onchange) and onclick for checkboxes

<script>
var drpdown;
var myArray;

function selectDropdown() {
drpdown = $(“#select-dropdown”).val();

alert(drpdown);

}

function showCheckbox(){
//get checkboxes
myArray = new Array(2);
if ($(‘#n-width:checked’).val() !== undefined)
{
myArray[0] = $(‘#cb1’).text();
alert(myArray[0]);
}
if ($(‘#n-height:checked’).val() !== undefined)
{
myArray[1] = $(‘#cb2’).text();
alert(myArray[1]);
}

}

</script>

once the above script is added in head, define body and a table inside to create dropdown and checkbox elements

<body>

<table>

<tr>
<td>
Select From Dropdown:
</td>
<td>
<select id=”select-dropdown” onchange=”selectDropdown();”>
<option selected=”selected”></option>
<option >OPTION1</option>
<option >OPTION2</option>
</select>
</td>
</tr>
<tr>
<td>
<label for=”r-left” id=”cb1″>CHECKBOX1</label>
</td>
<td>
<input type=”checkbox” id=”n-width”  onclick=”showCheckbox();”/>
</td>
</tr>
<tr>
<td>
<label for=”r-left” id=”cb2″>CHECKBOX2</label>
</td>
<td>
<input type=”checkbox” id=”n-height” onclick=”showCheckbox();”/>
</td>
</tr>

</table>

</body>

Upon changing the dropdown, selectDropdown will be called and we are using jquery inside selectDropdown to get the value of teh dropdown. Similarly for checkboxes, showCheckbox will be called and using jquery, i am getting the values for selected checkboxes

Leave a comment

Hibernate Criteria setResultTransformer


Problem: How to loop through a resultset with the column alias names defined in the native SQL, instead of accessing the resultset by column index in hibernate

Solution:

Sometimes, accessing the resultset by the names of the columns is much convenient than accessing the result set by index, say a row’s first column as get(0) and second column by get(1).

In this case, when using hibernate, calling setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP).list(),  causes it to return a list of Maps.

For example,

Query query1 = session.createSQLQuery(query.toString()).setParameter(“PRODID”, prodid).setParameter(“PRODTYPE”, prodtype);

//Convert the Query object to a list of maps

List iter1 = query1.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP).list();
Map<String,Object> map= new HashMap<String,Object>();
for (Object object : iter1)
{
map= (Map<String,Object>)object;

logger.debug(map.get(“PRODID”));

logger.debug(map.get(“PRODTYPE”));

logger.debug(map.get(“PRODEXP”));

logger.debug(map.get(“PRODCOST”));

}

1 Comment