-1
<h:outputScript library="js" name="jquery-1.11.0.min.js"></h:outputScript>
<script>
//<![CDATA[
function loadSomething() {
$.ajax({
    type: "POST",
    url: "#{testBean.LoadThat}",
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(datas) {
        alert(datas.d);                
    }
  });
}
//]]>
</script>
</h:head>
<body>
    <h:form>
        <h:inputText id="someText" />
        <p:commandButton value="Ajax Submit" id="ajax" update="someText"
            onclick="loadSomething();" />
    </h:form>
</body>

I'm trying to do a simple task with JSF. I used this exact code on Asp.net and i couldnt be sure what should i do to make this work. Any idea what should i write to 'url' to call bean's method?

varstas
  • 335
  • 10
  • 19
  • Take a look to this question and answer: http://stackoverflow.com/questions/12175763/how-to-send-post-request-to-jsf-component-without-using-html-form. In my opinion Your approach is not adequate. You should use pure JSF mechanisms (like @mehmetakifalp indicated) or use Restfull webservices on the server side for requests like this one. (If You need more explanation just let me know) – pWoz May 22 '14 at 09:07
  • Thank you this is what i need as an explanation. – varstas May 28 '14 at 08:02

1 Answers1

-1

your jsf must be like this;

<h:commandButton id="myButton" action="#{myBean.myMethod}" style="display:none">
    <f:ajax render="myButton" execute="myButton"/>
</h:commandButton>

and your jquery;

myButton.click(function(){ 
    $(this).fadeIn(); 
});

If you want to use onclick with your button or commandButton you can.

just put this on your code;

 <h:commandButton value="Click Me" type="button" onclick="alert('h:commandButton');" /> 
mehmetakifalp
  • 445
  • 5
  • 16
  • I know i can do this but couldn't i use plain html tags and jquery in jsf. Is it impossible to use jsf with plain html(without facelets,primeface,richface tags), javascript and jquery? – varstas May 22 '14 at 08:09
  • sorry this is the answer to my question i cant mark this as answered. – varstas May 28 '14 at 08:03