Search code examples
htmljqueryjspstruts2struts-tags

Unable to apply jQuery Chosen on <s:select>


I am using <s:select> (Struts2) drop-down with class chosen-select but that doesn't work. The class in generated HTML is like class="class java.util.HashMap".

Whereas if I use HTML <select> and same class chosen-select which works perfect. What is the problem with Struts 2 drop-down ?

Struts 2 Dropdown:

<s:select list="products" id="productsList_" listKey="id" listValue="name"
          headerKey="-1" headerValue="Select Product" style="width:200px;"
          theme="simple" class="chosen-select" /> 

HTML Dropdown:

<select id="productsList_" name = "products" class="chosen-select" ></select>

Solution

  • There are special attributes for CSS in the Struts UI tags. Instead of class attribute use cssClass and instead of style use cssStyle. Even if <s:select> tag allows dynamic attributes it parses the value for OGNL expression. And if you didn't define a variable with the key "chosen-select" in the value stack it might return occasionally a match. In your case it's some Class object, which has not any meaning to the code.

    The documentation page for <s:select> tag has a list of attributes used by the tag, however they said that it's not evaluated.