Ah, my bad. Web client utils plugin isn’t what you need. You need to set up an end point on the server. Several options:
-
http://wiki.servoy.com/display/Serv60/R … b+Services
-
Velocity report plugin
Highly recommended. I’ll let Patrick explain more but the basic idea is:
“The Velocity Report plugin uses CSS (2.1 and 3) and XHTML for building complex layout, Apache Velocity for easy templating, any native Servoy objects for data filling (globals, datasets, foundsets, you name it!) … Report templates are simple (well-formed) HTML documents, which can be saved in a Servoy-server-accessible path …”
- Servoy headless client
Servoy has a little known client (but has been around forever) that is instantiated via jsp files on the server. Trigger the jsp via a url and it will call a servoy method for you and return results. Same idea as #2 except except you’re in the jsp world now.
I’ve attached a simple jsp called “endpoint_example.jsp” which you need to drop into Servoy’s …/server/webapps/ROOT directory. The code looks like this:
<%@ page import = "java.util.*" %>
<%@ page import = "com.servoy.j2db.server.headlessclient.*" %>
<%@ page import = "com.servoy.j2db.util.*" %>
<%
// grab params
String solution = request.getParameter("s");
String method = request.getParameter("m");
Object[] args = new Object[]{session, request};
// start servoy headless client
ISessionBean servoy_hc = (ISessionBean)application.getAttribute("servoy");
if (servoy_hc == null) {
servoy_hc = HeadlessClientFactory.createSessionBean(request, solution);
application.setAttribute("servoy",servoy_hc);
}
// call servoy method
String results = (String)servoy_hc.executeMethod(null, method, args);
// print out results
out.print(results);
%>
Also attached is a servoy solution file called “endpoint.servoy”. It contains one global method called “get”:
function get(session, request) {
var data = []
var row = {}
row.type = (request.getParameter('type')) ? request.getParameter('type') : 'fruit'
row.name = (request.getParameter('name')) ? request.getParameter('name') : 'orange'
row.taste = (request.getParameter('taste')) ? request.getParameter('taste') : 'fruit'
data.push(row)
return JSON.stringify(data) // Servoy 6.1 or later only!
}
Try out a couple of URL’s in your browser once both are installed:
[attachment=2]method.png[/attachment]
[attachment=1]method with params.png[/attachment]
Whatever you set up, you can call via ajax. Sencha example:
proxy: {
type: 'ajax',
extraParams: {
s: '_ds_CODE_resources',
f: 'CODE_0F__sencha',
m: 'AJAX_staticData'
},
url: 'app/controller/bridge.jsp',
reader: {
type: 'json'
}
}
JQuery example:
function stageOneSubmit(event, url) {
// block default submit
event.preventDefault();
// validate first
var validator = $('#checkout_1').bValidator();
if( !validator.validate() ){
return;
}
// don't run if on account
if ( $('.payment :checked').val() == "terms" ) {
$('#checkout_1').submit();
return;
}
// TODO: turn on busy-ness
// validation data
var data = {
name : $('#checkout_1 [name="cc_name"]').val(),
card : $('#checkout_1 [name="cc_number"]').val(),
month : $('#checkout_1 [name="cc_month"]').val(),
year : $('#checkout_1 [name="cc_year"]').val(),
cvc : $('#checkout_1 [name="cc_cvc"]').val(),
address : {
line_1 : $('#checkout_1 [name="b_line1"]').val(),
line_2 : $('#checkout_1 [name="b_line2"]').val(),
city : $('#checkout_1 [name="b_city"]').val(),
state : $('#checkout_1 [name="b_state"]').val(),
zip : $('#checkout_1 [name="b_zip"]').val(),
country : "USA"
}
}
// verify CC info
$.ajax( {
type : "post", // the default
url : url,
data : { params : JSON.stringify(data),
svs : "lind_WEBlind_website",
svf : "WEBlind_0F__checkout",
svm : "AJAX_verifyCC"
},
dataType : "json",
success : function (results) {
// if success, submit
if ( results._msg == 1 ) {
$('#checkout_1').submit();
}
else if ( results._msg == 0 ) {
alert("CC not validated");
}
else {
// back button trapping
window.location=window.location;
}
}
});
}
endpoint demo files.zip (3.92 KB)