I am using Struts 2-REST plugin for web services for my web app. It uses backbone.js to retrieve and display data from the services. However, I am struggling on how to capture the parameters from the collection.fetch() method to the server-side (Java). It is somehow similar how it is applied in AJAX.
For example:
Example #1
fetchStudents : function() {
this.fetch({
data : {
packet : JSON.stringify({
type : "retrieveAllStudents",
data : {}
})
},
type : 'POST',
success : function(collection, response, options) {
console.log('SUCCESS: all students fetched');
}
});
}
Example #2:
fetchStudentById : function(studentId) {
this.fetch({
data : {
packet : JSON.stringify({
type : "retrieveStudentById",
data : {
studentId : studentId
}
})
},
type : 'POST',
success : function(collection, response, options) {
console.log('SUCCESS: student#' + studentId + ' fetched');
}
});
}
Based on the examples above, parameter type
refers to name of method to be called, whilst data
is for the parameter/s of the method to be called.
For example# 1, it will be calling method retrieveAllStudents()
; and example #2 will be calling retrieveStudentById(studentId)
method.
Would it be advisable if I will use Java Reflections? Based on my research, its performance is slow, isn't it? If any, are there alternatives for Reflections?
Aucun commentaire:
Enregistrer un commentaire