Question: If I have a HTML or a JSP page having list of sports like below. 

Tennis  

Football  

Hockey  

Cricket

All these 4 should be a Link. If I click on any of them it should return some details wherever clicked. For this I need to pass this sport name to a REST client which will pass this as a parameter to a rest service. 

My question is how to pass the value of a link whichever clicked from HTML page to a Java application like we pass text box or check box values from HTML using the form action? Or is there any better approach, please suggest

Answer: 
The db table structure should be - 

**Countries**

```
id | name

```

**States**

```
id | country_id | name

```

The relation should be - 

```
Country HasMany State

```

And after fetching all the countries by - 

```
$countries = ClassRegistry::init('Country')->find(
   'all', 
   array(
    'conditions' => your conditions,
    'fields'     => array(fields),
    'contain'    => 'State',
   )
)

```

Generate the `optGroup` array as needed by looping through the array.
Given the DB as described by sgt BOSE.

**Countries**

```
id | name

```

**States**

```
id | country_id | name

```

**SQL**

```
CREATE TABLE IF NOT EXISTS `countries` (
`id` int(11) NOT NULL,
  `name` varchar(255) CHARACTER SET utf8 NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `states` (
`id` int(11) NOT NULL,
  `country_id` int(11) NOT NULL,
  `name` varchar(60) CHARACTER SET utf8 NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE `countries`
 ADD PRIMARY KEY (`id`);
ALTER TABLE `states`
 ADD PRIMARY KEY (`id`);
ALTER TABLE `countries`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `states`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

```

**And the two models:**

```
<?php // File: Model/Country.php
App::uses('AppModel', 'Model');
class Country extends AppModel {
  public $hasMany = array('State');
}

<?php // File: Model/State.php
App::uses('AppModel', 'Model');
class State extends AppModel {
    public $belongsTo  = 'Country';
}

```

In **CountriesController.php**:

```
public function test(){ 
    $countries = $this->Country->find('all');
    $countries = Set::combine($countries, '{n}.Country.name', '{n}.State.{n}.name');
    $this->set('countries', $countries);
}

```

$countries now hold an array as described in the question and is sent to the view

```
array(
    'Norway' => array(
        (int) 0 => 'Oslo',
        (int) 1 => 'Bergen'
    ),
    'Sweeden' => array(
        (int) 0 => 'Stockholm',
        (int) 1 => 'Göteborg',
        (int) 2 => 'Malmö'
    )
)

```

**In the view** (View/Countries/test.ctp in my case)

```
<?php
echo $this->Form->select('field', $countries);
?>

```

**Will create the following html code:** (This is a drop down)

```
<select name="data[field]" id="field">
  <option value=""></option>
    <optgroup label="Norway">
    <option value="0">Oslo</option>
    <option value="1">Bergen</option>
  </optgroup>
  <optgroup label="Sweeden">
    <option value="0">Stockholm</option>
    <option value="1">Göteborg</option>
    <option value="2">Malmö</option>
  </optgroup>
</select>

```