0

I have the following source code for a select:

<select id="_conteneurNum_id" name="conteneurNum" data-dojo-type="dijit.form.FilteringSelect">
<option selected="selected" value="">Tous</option>
<option value="1">951</option>
<option value="2">753</option>
<option value="3">753159</option>
</select>

Which get rendered as follows:

rendering of form field

It seems that the selected attribute is ignored by Dojo/Dijit/SpringJS (notice that the user is first presented with a white label instead of "Tous".

Can anyone please help?

2 Answers 2

1

Are there any errors in the console?

I have a fiddle that does exactly what you want with your code:

http://jsfiddle.net/cswing/eJP3U/

1
  • Thanks for this fiddle. I use the dojo version bundled with Spring roo 1.2.2. I am not sure it is the latest version of dojo/dijit...
    – balteo
    Jul 31, 2012 at 11:35
1

I just found a workaround after some hours wrestling with MyEclipse 2014, Spring 3.1 and old Dojo/Dijit versions, I know this is old but MyEclipse packs these old versions of everything.

I tried FilteringSelect, Select with null value, html option with value, and replacing dojo libraries which messed the rest of the project. So I'll post this here if it could help anybody:

This case is common if you want a dummy prompt option in your select like '-- Select item --' with a null value. Dojo/dijit version packed with MyEclipse into spring-js-2.3.1.RELEASE, replaces option with null values with separators showed in the dropdown list. In a few last versions of Dojo/Dijit this behaviour seems to be corrected as you can see in the fiddle of Craig Swing.

If the property you bind is not a string, you can assign a single espace as value of dummy option instead of null, because later will be binded as null in the controller, so the dummy option will be showed. Ex:

<option selected="selected" value="">Tous</option>

But if the property is a String, this way you will find with an unwished blank space in the property in your controller.

So I finally opted to directly modify Select.js

Place it in your project in webapps/resources/dijit/form/Select.js Comment this lines:

/*
if(!_1.value){
return new dijit.MenuSeparator();
}else{
*/
var _2=dojo.hitch(this,"_setValueAttr",_1);
var _3=new dijit.MenuItem({option:_1,label:_1.label,onClick:_2,disabled:_1.disabled||false});
dijit.setWaiRole(_3.focusNode,"listitem");
return _3;
/*
}
*/

And don't forget to override this path for Resource Servlet in web.xml:

<servlet-mapping>
    <servlet-name>My Servlet</servlet-name>
    <url-pattern>/resources/dijit/form/Select.js</url-pattern>
</servlet-mapping>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.