2

I'm on a JSF h:form submit via JavaScript.It's a simple function.I need a validation for inputs before submit while I want to use JavaScript instead of JSF Validator for some dynamic effect. but the submit method is a managed bean function called #{depositMB.deposit} Here's the code:

JS:
function checkAccount(form){
  //some validations here
  form.submit();
 }
XHTML:
<h:form class="form-horizontal" onsubmit="#{depositMB.deposit()}">
        <h:inputText id="account" value="#{depositMB.targetAccount.accountNumber}"/>
     <h:inputText id="money" value="#{depositMB.moneyAmount}"/>
    <h:commandButton value="Deposit" action="checkAccount(form)"/>
</h:form>

When I wrote it in the tag h:form as onSubmit:#{depositMB.deposit} it doesn't work. Then I put it in JS like this

function checkAccount(){
  //some validations 
      #{depositMB.deposit()};
 }
<h:form class="form-horizontal">
        <h:inputText id="account" value="#{depositMB.targetAccount.accountNumber}"/>
     <h:inputText id="money" value="#{depositMB.moneyAmount}"/>
    <h:commandButton value="Deposit" action="checkAccount(form)"/>
</h:form>

It didn't work either...Who can help me with this... Thx a lot

Jiddu.K
  • 69
  • 9
  • The 'onsubmit' gets javascript code which is executed when the form gets submitted. – Holger Dec 05 '16 at 08:10
  • thx for your answer. I have solved it...I wrote checkAccount() in onsubmit as onsubmit="return checkAccount(this)". And make validations in checkAccount(form). The commandButton action is still the #{depositMB.deposit()} and it works...I can validate the inputs in JavaScript before the depositMB.deposit() called... – Jiddu.K Dec 05 '16 at 14:40

0 Answers0