Saturday, March 28, 2009

Multiple Value Selection using Checkbox in Struts

How to design a page in struts using CheckBox for choosing 2 or more values?

Perform the following steps:

1. Action Form: Design a form with Array of Objects of String type.
String[] selectedValues = { };

2. JSP: Populate the values that it can hold using logic:iterate tag.
<html:checkBox .... property="selectedValues" value="<%=obj[i].getValue()%>" ..... >

3. After Form submission: the selected values will be placed in selectedValues property

4. Now, in Action, iterate the collection, to identify the selected DTO object.
This needs to be designed as per the requirements.
For example, based on 'selectedValues', pick up the selected objects from the one collection into another,
so that the business routine can use the resultant collection.

Have Fun...

Hiberate Configuration for Oracle 10g

Oracle Driver Configuration for Hibernate:

Add the following XML file into configuration:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url"> jdbc:oracle:thin:@databaseurl>
<property name="hibernate.connection.username">scott</property>
<property name="hibernate.connection.password">tiger</property>
<property name="connection.pool_size">1</property>
<mapping resource="hibernate.hbm.xml"/>
<mapping resource="hibernate1.hbm.xml"/>
</session-factory>
</hibernate-configuration>