Reputation: 5654
I have a web application build using Dojo UI when the application loads i call parser.parse()
to create the widgets necessary. I am now attempting to do data binding from an Ajax request to the UI. I have been looking at an example here however i am seeing the model is set before the parser.
I need to be able to set the model from within a function and bind it to the UI. Since i am calling the parser.parse() a second time i am getting the following error:
dojo/parser::parse() error
Error: Tried to register widget with id==xxxx but that id is already registered
Also is there a way i can only parse for the bindData function only and avoid this error ?
Function to preform binding
var model;
function bindData(data){
require([
"dojo/Stateful",
"dojo/parser"
], function( Stateful, parser){
model = new Stateful(data);
parser.parse();
});
}
Function called when query button is executed
if (getSelectedRadioButton('userOption') == 1){
if (!dijit.byId("employeeNumberId").value){
var employeeNumberId = dijit.byId("employeeNumberId");
dijit.showTooltip(
employeeNumberId.get('missingMessage'),
employeeNumberId.domNode
);
showNotificationDialog("okResponseNotificationDialog", 'Please Enter A Valid Employee Number Proceed', 'User Options');
return false;
}else{
showNotificationDialog("okResponseNotificationDialog", 'Please Wait While We Retrive Your Data', 'User Options');
dojo.xhrPost({
url: getEmployeeData,
postData: dojo.toJson({
employeeNumber: EmployeeId
}),
handleAs: "text",
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
sync: true,
load: function (data) {
data = ({First: "John", Last: "Doe", Email: "[email protected]"});
bindData(data);
},
error: function (error) {
showNotificationDialog('okResponseNotificationDialog', 'Contact Your HELP DESK : ' + error, 'Error');
}
});
}
}
JSP
<s:textfield required="true" name="Employee.firstname"
id="surname" placeholder="Your Firstname"
trim="true"
data-dojo-type="dijit/form/ValidationTextBox"
missingMessage="Please Enter Your Firstname!"
invalidMessage="Invalid Firstname!" title="(a) Firstname:"
style="width: 20em;" data-dojo-props="value: at(model, 'First.name'), uppercase:true, regExp:'^[`a-zA-Z ]+(([\,\.-][`a-zA-Z ])?[`a-zA-Z ]*)*$'"/>
Upvotes: 0
Views: 645
Reputation: 321
Right you can not call parser.parse() twice. You probably should use an EditModelRefController instead of just using a Stateful for the model, and then you should be able to set it up originally with dummy data, and then replace it with the real data when it is available. To see an example of replacing the model, you can look here: https://github.com/dojo/dojox/blob/master/mvc/tests/test_mvc_new-data-replace-simple.html
Upvotes: 1