javascript - How to use jsf.ajax.request to manually send ajax request in JSF -


i have table , each row has 'onclick' configured call js function - part works. function issue ajax request method can somehow define. upon return, div below table should rendered. possible? tried js function code:

<h:outputscript library="javax.faces" name="jsf.js" /> ... function clickandrender() {   jsf.ajax.request(this, event, {render: 'div-to-render'}) } 

but doesn't work of course. have no idea values of 'source' parameter (the code above uses 'this') should be, neither know execute in last parameter should set to. don't know how define url called , 'action' method.

the solution using invisible form somewhere else in page get's submitted click. can help?

as per jsf 2.3, can use <h:commandscript> this. see spec issue 613.

<h:form>     <h:commandscript name="foo" action="#{bean.action}" render="div-to-render" /> </h:form> 

function clickandrender() {     foo(); } 

it's available since mojarra 2.3.0-m06.


this answer updated above 3 years after question posted. below original answer when dates when <h:commandscript> didn't exist.


i have no idea values of 'source' parameter (the code above uses 'this') should be

it should client id of uicommand component you'd invoke, e.g. <h:commandlink>, <h:commandbutton>, etc provided standard jsf api. way jsf during apply request values phase able locate desired component in component tree , queue of action(listener)s registered on it.


neither know execute in last parameter should set to.

it should space-separated client ids of components you'd process during form submit. it's same you'd use in <f:ajax execute>.


i don't know how define url called

just current page, derived <form> been generated <h:form> uicommand component nested in. don't need specify in jsf.ajax.request(). jsf.js determine based on client id of uicommand component.


and 'action' method.

just specify action or actionlistener attribute of target uicommand component usual way.


all all, concrete problem don't have uicommand component in view, can't use jsf.ajax.request(). 1 way have form command component hidden css display:none:

<h:form id="foo" style="display:none">     <h:commandlink id="bar" action="#{bean.method}" /> </h:form> 

then can use foo:bar source parameter.

jsf.ajax.request('foo:bar', null, {'javax.faces.behavior.event': 'action', 'execute': '@form', 'render': 'div-to-render'}); 

the above same <f:ajax execute="@form" render="div-to-render"> in command component. alternatively go path , use document.getelementbyid("foo:bar").click() instead of jsf.ajax.request().

alternatively, can create custom uicommand component makes bit easier javascript users. jsf utility library omnifaces has such component, <o:commandscript>. see showcase page , source code. jsf component library primefaces has similar component in flavor of <p:remotecommand>. see showcase page. richfaces has <a4j:jsfunction> same. see showcase page.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -