Here is my javascript code
Code:dojo.addOnLoad( function(){ dojo.require("dijit.form.Select"); var id = 3; var node = dijit.byId('_projectType_id'); var dNode = dojo.byId('_years_id'); dojo.connect(node, 'onChange', function(){ dojo.xhrGet({ url: '../../TDF/projectdurations/lookup/' + id, handleAs: "json", preventCache: true, load: function(data) { var html = '<option value="">State</option>'; var len = data.length; for ( var i = 0; i < len; i++) { html += '<option value="' + data[i].name + '">' + data[i].description + '</option>'; } html += '</option>'; //now that we have our options, give them to our select dojo.byId('mydiv').html(html); }, error: function(error) { dNode.innerHTML = "AJAX error: " + error; } }); } ); });
To explain, I have two dropdown lists generated by Roo or to explain in code :
Basicly how this works is, you select a project type and some projects have 1 some have 2 and some have 3 years to select from, so when you select a project type that has one year only as the duration, the duration dropdownlist should only have that one item, not one year , two years three years.Code:<field:select field="projectType" id="c_is_rannis_sjodir_tdf_domain_TypeAndDuration_projectType" itemValue="id" items="${projecttypes}" path="/projecttypes" z="aX32lFhmcIYB81RjsH/7HBr1DLs="/> <field:select field="years" id="c_is_rannis_sjodir_tdf_domain_TypeAndDuration_years" itemValue="id" items="${projectdurations}" path="/projectdurations" required="true" z="0LwlWg69oxlubxwcXvA8qsHbeBU="/>
The project Type select gives 6 types of projects to select from
Project duration (or years) basicly gives one year, two years three years.
I have created a function in a controller which returns a json response (this works I tested it by just callin the function and it returns a json response). I basicly just pass the id of projecttype to this function and it returns the correct number of year objects as json.
So basicly, I tried every variation of theCode:@RequestMapping(value = "/lookup/{numberofyears}", method = RequestMethod.GET) public @ResponseBody List<ProjectDuration> findProjectDurations(@PathVariable("numberofyears") String years, HttpServletResponse response, HttpSession p_session) { try { List<ProjectDuration> tf = ProjectDuration.findProjectDurationsNumberLessAndEquals(years).getResultList(); return tf; } catch(Exception ex) { } return (List<ProjectDuration>) null; }
dojo.byId('mydiv').html(html); I can think of, like making an empty div to receive the new html etc.
Help would be greatly appreciated.
Regards,
Emil


Reply With Quote
