-
1. Re: Difference in behaviour between javascript click() and user click on a button using JSF
harut Mar 17, 2010 7:55 AM (in response to mfarwell)I tried to reproduce your mentioned case, but no success -- it works fine for me.
Here is my code:
<script type="text/javascript">
function trapEnter() {
document.getElementById('myForm:forumTestButton').click()return false; //this is just for having the same return type as in your example...
}</script>
<h:form id="myForm">
<a4j:commandButton value="JS_CALL_BUTTON" onclick="trapEnter()"/>
<a4j:commandButton id="forumTestButton"
value="ACTION_CALL_BUTTON"
action="#{searchTaskController.onTestForum}"/>....................
</h:form>
In both cases (clickin on any of above commandButtons) page is redirecting correctly after action...
-
2. Re: Difference in behaviour between javascript click() and user click on a button using JSF
mfarwell Mar 18, 2010 8:27 AM (in response to harut)Thank you for your response.
Your code works, but it doesn't answer my question. I'm not clicking on any buttons, I'm trying to get the click() to work when I press Return.
According to what I understand, typing 1 in the box and pressing return should have exactly the same effect as typing 1 in the box and clicking on the Go button, but it does not.
Any help would be appreciated.
Matthew.
-
3. Re: Difference in behaviour between javascript click() and user click on a button using JSF
harut Mar 18, 2010 8:47 AM (in response to mfarwell)In my previous post above, I just created a simple example to investigate the problem you have mentioned that clicking the button from JS function, is not redirecting the page (or I am missing something???). And that's why in my post I have 2 a4j:commandButtons one of them has "action" assigned
(id="forumTestButton"), and clicking on that button will call an action method in the backing bean, and after it will redirect the page. The second a4j:commandButton (value="JS_CALL_BUTTON") has not any action assigned, it is just calling JS function on "onclick" event (the same way you are pressing "Return" and call the JS), and after pressing that button JS function is calling which provides clicking functionality to the previous button ((id="forumTestButton"), and after it page is redirecting sucessfully.... So in this case the first button has been clicked by JS function (what was the main question).
-
4. Re: Difference in behaviour between javascript click() and user click on a button using JSF
mfarwell Mar 18, 2010 1:59 PM (in response to harut)You are perfectly correct when you say that your example works. However, it is not the same as my example.
The difference between your example and mine is that you are clicking directly on a button in the form, whereas I have defined an onkeypress event for the form, and the function called when I hit return calls click(), and the redirect from this click does not work.
I would like to know why the click() when called from a button works, but when called from the onkeypress event does not.
The problem is that it does not work when I hit return, when I'm calling click() from javascript, from the function called when I hit return.
Matthew.
-
5. Re: Difference in behaviour between javascript click() and user click on a button using JSF
harut Mar 19, 2010 3:45 AM (in response to mfarwell)Hi Matthew, I have modified my sample to make redirection after "Returned" clicked, and it works fine. Here is the code (just add rich:hotKey):
<script type="text/javascript">
function trapEnter() {document.getElementById('myForm:forumTestButton').click()
}</script>
<h:form id="myForm">
<rich:hotKey key="return" handler="trapEnter(); return false;"/>
....................
</h:form>
(And no need to handle onkeypress event of the form)
Regards.