Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JSF and the fly likes Ajax populated dropdown submitting improperly Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Ajax populated dropdown submitting improperly" Watch "Ajax populated dropdown submitting improperly" New topic
Author

Ajax populated dropdown submitting improperly

bryan madaras
Greenhorn

Joined: Jun 16, 2006
Posts: 2
I am using Myfaces 1.4 and facelets 1.1.4.
I have dropdown lists that are being initially populated using a backing bean, once one of the values change an ajax call is used to populate the one dependent on the changed one. The population seems to work fine but once I attemp to submit the form with different values in the dropdown that initial page load the page refreshes with the initial values again. The bean method referenced in the actionListener for the submit button does not get executed. But if I leave the dropdown values alone and change values from textboxes the page submits and navigates correctly?

for(var i=1; i<returnedoptions.length; i++)
{
if(currentValue != returnedoptions[i]){
var option = new Option(returnedoptions[i],returnedoptions[i]);
component.options[component.length]=option;
}
}
This is how I am populating the dropdown from the ajax call with component being the dropdown element I am populating.

Any help would be appreciated, or a reason I am not recieving any errors to try and figure out on my own.
Thanks
Bryan
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15357
    
    6
What is your Ajax call exactly. It is cached most likely.

Eric
bryan madaras
Greenhorn

Joined: Jun 16, 2006
Posts: 2
Here is the code for the ajax calls

popMake: function(evt){
var id = "vehicleMake";
if(dojo.byId(formid+"vehicleYear").value!=""){
var param = new Array(dojo.byId(formid+"vehicleYear").value);
var paramids = new Array("vehicleYear");
callServletobj.dropdownlookup(id,param,paramids);
}

},
popModel: function(evt){
var id = "vehicleModel";
if(dojo.byId(formid+"vehicleYear").value!="" && dojo.byId(formid+"vehicleMake").value!=""){
var param = new Array(dojo.byId(formid+"vehicleYear").value,dojo.byId(formid+"vehicleMake").value);
var paramids = new Array("vehicleYear","vehicleMake");
callServletobj.dropdownlookup(id,param,paramids);
}
},
popBodyStyle: function(evt){
var id = "vehicleBodyStyle";
if(dojo.byId(formid+"vehicleYear").value!="" && dojo.byId(formid+"vehicleMake").value!="" && dojo.byId(formid+"vehicleModel").value!=""){
var param = new Array(dojo.byId(formid+"vehicleYear").value,dojo.byId(formid+"vehicleMake").value,dojo.byId(formid+"vehicleModel").value);
var paramids = new Array("vehicleYear","vehicleMake","vehicleModel");
callServletobj.dropdownlookup(id,param,paramids);
}
},

This is the function thast is actually making the call
var callServletobj = {
dropdownlookup: function(elementid,paramArray,idArray){
dojo.io.bind({
url: 'dojo',
handler: handleCallBackobj.handledropdownlookup,
content: {id: elementid,
params: arrayCSV(paramArray),
paramids: arrayCSV(idArray),
type: 'lookup'}
});
},


This is how the response is being handled

var handleCallBackobj = {
handledropdownlookup: function(type, data, evt){
//either use JSON or just split the data into an array
//then populate the returned elementid with the rest of the data
if(data!=""){
var returnedoptions = data.split(",");
var component = dojo.byId(formid+returnedoptions[0]);
var currentValue = component.value;
component.length=0;
if(component.id==formid+"vehicleMake"){
component.options[0] = new Option(currentValue);
}
else{
component.options[0] = new Option('');
}


for(var i=1; i<returnedoptions.length; i++)
{
if(currentValue != returnedoptions[i]){
var option = new Option(returnedoptions[i],returnedoptions[i]);
component.options[component.length]=option;
}
}
}
},

But I am not seeing how a cached ajax call would cause the JSF page to not submit itself properly?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15357
    
    6
Ah, when I first read the post, I thought you were saying that you can call the code once, but the next time it would return the intial values of the first call. I missed the oart about submitting the page.

Sounds like to me is that you have a viewstate mismatch with the serverside code. I am not a Java guy, but I know this issue happens on the .NET world. I normaly would have to set the dynamic value of options of a dropdown list into a hidden textbox on the page when something was selected. Not sure if this is the same case here.

Eric
Domenic D
Greenhorn

Joined: Aug 24, 2006
Posts: 1
Did you ever resolve your problem, I am having the same issue and cannot seem to solve it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ajax populated dropdown submitting improperly
 
Similar Threads
Ajax with Struts - Loading the lookup values in drop down
Avoiding form resubmission
Selecting option in second selectOneMenu not setting property value
Dropdown Selected returning unexpected value on submit.
How to solve back button problem in Ajax