0

In a form i used i called a Javascript function. Though the function returns false , form is submitted and action method is called.

i used like this

<h:commandButton onclick="test();" action="{#bean.menthod}">

test- javascript method returns boolean value false.

Above doesnt work. Below mentioned code alone worked. I want to know why

 <h:commandButton onclick="if(test) return true;else return false" action="{#bean.menthod}">
0

3 Answers 3

1

It is not working simply because the result of test() function is not returned to the component.

it should work as expected with

<h:commandButton onclick="return test()" action="{#bean.menthod}">

and this is exactly the same as your second case but simplified.

Sign up to request clarification or add additional context in comments.

3 Comments

i want to know why result of test is not returned to the component though the test() method returns false
because you're not putting return before calling the function :)
Thanks for this suggestion. Headache gone and now I can rest easy :)
0

At the end of the day your h:commandButton will become a HTML Form submit button. i.e, <input type="submit" .../>

Usually form won't get submitted when the submit button returns false.

Comments

0

Thanks.. This helped me lot. Here simple logic which i missed i.e .. in that onclick function I am returning false instead of true, which is stopping the action to be called. Finally i changed return value to true, and solved my issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.