javascript - Assigning/Passing value from Java function to JS/JQuery function -
javascript - Assigning/Passing value from Java function to JS/JQuery function -
lets have java function like
public int getnumber(){ }
which returns value based on it's logic. , have js file like
tapestry.validator.amountvalidator = function(field, message) { field.addvalidator(function(value) { if (value != null) { // code here } } }); };
now asking myself possible in js or jquery pass value java function it's function(value) in js , if so, how can achieved?
update: suggested abalos answer, tap myself has done 3 out of 4 stages it. providing function deals server side , logic behind it.
@injectcomponent private textfield amount; @inject private fieldvalidatorsource fieldvalidatorsource; public fieldvalidator<?> getamountvalidator() { homecoming fieldvalidatorsource.createvalidators(amount, "required,max=" + getbroj()); }
now here validator taken logic within function getbroj(), maximum number of takes. , works charm on server side. thinking don't have( using logic ) client side, , can accomplish updating current validation class tapestry handle kind of request yet known class. , need phone call js file function calling above in example, not quite sure how pass value getnumber() function js function above.
you don't need bailiwick of jersey or dwr or other framework @ invoking method in tapestry. need inquire questions properly.
final private static string event_name = "whatevereventnameyouwant"; @inject private componentresources resources; @inject private javascriptsupport javascriptsupport; /** method provide value want pass js. */ @onevent(event_name) public jsonobject providevalue() { jsonobject object = new jsonobject(); object.put("value", /* value want pass js */); // other values may want pass homecoming object; } void afterrender() { // creates url event created. requesting // invoke event handler methods event name. link link = resources.createeventlink(event_name); javascriptsupport.addscript("var eventurl = '%s';", link.); // javascript variable name doesn't matter. can take want }
then, in javascript, ajax request using url in eventurl variable. i'll leave part figure out jquery documentation. received info jsonobject or jsonarray you'll homecoming in event handler method.
java javascript jquery tapestry
Comments
Post a Comment