I want to simply print a message with a java bean method every time I click on a header.
So this is what I tried to do :
I have a java bean class (with annotation "Test") in which I have the method I will associate to my remoteCommand tag :
public void printSomething(){
System.out.println("Something");
}
I've created a form tag containing my remoteCommand tag in my xhtml file :
<h:form id="form1">
<p:remoteCommand name="print"
actionListener="#{Test.printSomething}"/>
</h:form>
And this is my javascript :
<script>
$('th').on('click', function() {
alert("Hi");
print();
});
</script>
The problem is my function is only called once when I click for the first time in a header ("Something" is printed on my terminal) . If I try to click on another header just after, it doesn't react. The alert message in my javascript doesn't appear after the first click.
Do you know why and how I can fix it ?
Update 1 : I tried with different selectors :
first try with : $('th').click(function(){ ...
// same result
second try with : $('th').bind('click', function() { ...
// same result
I don't think this is a JS problem, I assume it must be something with primefaces but I still didn't find how to solve it.
Update 2 : It's actually working everytime I refresh the page with F5 after a click but this is not what I want.
Update 3 : Still didn't find how to do it but I was wondering if I can "manually" refresh with a jquery function (not the entire page) ?
I want to use load()
function, I want to do something like this :
<script>
$('th').on('click', function() {
alert("Hi");
print();
$("#form1").load(location.href + " #form1");
});
</script>
But it's not working, is it something to do with the syntax ? I searched here : Refresh/reload the content in Div using jquery/ajax