Me n My Programming

If Only I Have TIme

ITSB Spring 102 – JSTL HTML Select

This is for making the html select option:

1. JSP file

<form:select path=”cityid” items=”${cityList}” />

2. Controller file

uiModel.addAttribute(“cityList”, cityService.populateCity());

3. Service interface file

public Map populateCity();

4. Service Implementation

public Map populateCity() {
        Map<Integer,String> city = new LinkedHashMap<Integer,String>();
        List<PrCity> prCityList = getCityList();
        
        if (prCityList != null && !prCityList.isEmpty()) {
            for (PrCity prCity : prCityList) {
                city.put(prCity.getId(), prCity.getName());
            }
        }
        
        return city;
}

*** If this is used on the update page and there exists a city that have been selected, the list will automatically showed the selected city.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Information

This entry was posted on May 7, 2013 by in Uncategorized and tagged .
%d bloggers like this: