Spring 3 MVC capability for JSTL jsp option group label

I am a newbie to Spring and I want to create "option group select" But I am unable to do this.

I want an output as following but in HTML type saying

<select name="..." value"...">
 <optgroup label="Category 1">
  <option ... />
  <option ... />
 </optgroup>
 <optgroup label="Category 2">
  <option ... />
  <option ... />
  </optgroup>
 </select>

 General
       movies
       hobbies        
 Games
      football
      basketball

 Images
      officePics
      familyPics
      PresntationPics

 RingTones
      pop
      classical
      jazz

jsp code Edited : Correct one

   <form:select multiple="single" path="servicemodule" id="servicemodule">
     <form:option value="None" label="--Select--" />
      <c:forEach var="service" items="${servicemodule}">
       <optgroup label="${service.key}">
       <form:options items="${service.value}"/>        
       </optgroup>
      </c:forEach>        
    </form:select>

Controller code : There are 4 main categories and under each of these there can be many subCategories. These can be retrieved from getServiceModuleList method. But I am not getting idea where to implement the loop to store different subcategories under their respective main category.

 @Autowired
         private ServiceModule servicemodule;

Edited: Correct @ModelAttribute

        @ModelAttribute("servicemodule")
    public Map<String,List<String>> populateService() {

        String[][] mainCategory = new String[7][2];

        mainCategory[0][0]= "General"; mainCategory[0][1]= "general1234";
        mainCategory[1][0]= "Games"; mainCategory[1][1]= "games1234";
        mainCategory[2][0]= "Images"; mainCategory[2][1]= "images1234";
        mainCategory[3][0]= "Ringtones"; mainCategory[3][1]= "ringtone1234";

        Map<String,List<String>> serviceModule= 
        new LinkedHashMap<String,List<String>>();


        List<String> subCategory=new ArrayList<String>();

        List<ServicesPojo> services=
        servicemodule.getServiceModuleList("1",mainCategory[0][1],"0");
        for(ServicesPojo serviceName: services)
        {
            subCategory.add(serviceName.getServiceName().trim());
        }
        serviceModule.put(scats[0][0],subService);
        return serviceModule;
}

Edited: Got the Answer for Loop

    for(int i=0;i<mainCategory.length;i=i+2){
    List<String> subCategory=new ArrayList<String>();

        List<ServicesPojo> services=
        servicemodule.getServiceModuleList("1",mainCategory[0][i],"0");
        for(ServicesPojo serviceName: services)
        {
            subCategory.add(serviceName.getServiceName().trim());
        }
        serviceModule.put(mainCategory[i][0],subCategory);
      }

Model This has the main error whether I should keep only String or List Confused!!

Edited: Now Corrected one

  private List<String> servicemodule;

  public List<String> getServicemodule() {
    return servicemodule;
      }

public void setServicemodule(List<String> servicemodule) {
    this.servicemodule = servicemodule;
     }

Error Description

  org.springframework.beans.NotReadablePropertyException: 
  Invalid property 'serviceModule' of bean class 
  [springx.practise.model.SiteModel]: Bean property 'serviceModule' 
  is not readable or has an invalid getter method: 
  Does the return type of the getter match the parameter type of the setter?

Solved!!

Answers


Watch you case: servicemodule != serviceModule.

The <c:foreEach> loop isn't correct either: it uses itemGroup both for var and varStatus, and itemGroup is never used inside the loop. Instead, serviceModule is used, but is not defined anywhere.

And I have a hard time understanding your code, one of the reasons being that you use the same name for very different things and don't pluralize attributes of type List.

private ServiceModule servicemodule;
...
Map<String,List<String>> serviceModule
...
private List<String> servicemodule;
...
<form:select multiple="single" path="serviceModule" id="serviceModule">
...
<c:forEach var="itemGroup" items="${servicesModule}" varStatus="itemGroup">

No wonder you lost yourself.


Need Your Help

How can I update only the proguard in android studio

android

I have older version of the android studio and I am happy from that. I think in newer version of the android studio, the proguard has been updated also.

What would be a good pair programming set up using Macs?

osx pair-programming

If you were setting up a pair programming station what hardware, software and furniture would you include?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.