How to use jsf.ajax.request to manually send an ajax request to JSF

I have a table, and each row has an "onclick" configured to call the js function - this part works. I would like the function to issue an ajax request to a method that I can somehow determine. Upon return, a div should be displayed below the table. Is it possible? I tried a JS function with code:

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

But that does not work, of course. I have no idea what the value of the source parameter is (the code above uses 'this'), and I don't know what should be set in the last parameter. I also don't know how to determine the url to call and the action method.

The solution may also use some invisible form somewhere else on the page, which will be sent by click. Can anyone help?

+3
source share
3 answers

According to JSF 2.3, this can be used <h:commandScript>. See also specification 613 .

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

function clickAndRender() {
    foo();
}

Available since Mojarra 2.3.0-m06 .


This answer was updated, as before, 3 years after the publication of the question. Below is the original answer when dated, when <h:commandScript>does not exist.


I have no idea what the value of the source parameter (the code above uses 'this') should be

UICommand, , . <h:commandLink>, <h:commandButton> .., API JSF. , JSF ().


, .

, , . , <f:ajax execute>.


, URL-,

, <form>, <h:form>, UICommand . jsf.ajax.request(). jsf.js UICommand.


.

action actionListener UICommand .


, , UICommand , jsf.ajax.request(). , CSS display:none:

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

foo:bar source.

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

, <f:ajax execute="@form" render="div-to-render"> . , document.getElementById("foo:bar").click() jsf.ajax.request().

UICommand, JavaScript. JSF OmniFaces , <o:commandScript>. . . JSF PrimeFaces <p:remoteCommand>. . . RichFaces <a4j:jsFunction>, . . .

+9

JSF, , . PrimeFace RemoteCommand. , . :

<p:remoteCommand name="onRowClick" actionListener="myBean.onRowClick" update="div-to-render" />

<h:someComponent onclick="onRowClick" />
0

, , , , BalusC, < a4j: jsFunction > . , , , , , ; d

  • - โ€‹โ€‹ "":

    <table>
      <ui:repeat>...</ui:repeat>
      <form>...</form>
    </table>
    

    -Ajax, id Ajax-. .

  • , , = 'false', HTML. Ajax- , , , ( ). , div- , , div. , :

    <h:outputText id="to-render" rendered="${bean.clicked != null}">
      ...
    </h:outputText>
    

    :

    <h:panelGroup layout="block" id="to-render">
      <h:outputText rendered="${bean.clicked != null}">
        ...
      </h:outputText>
    </h:panelGroup>
    

. BalusC , , , .

0

All Articles