Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Call the Backing Bean Method from javascript in JSF

 
Balaji Soundarajan
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to call the Backing bean method from javascript. I have a command button in .xhtml page from there i need to call the javascript method, in the javascript i need to validate the textfield which is in the same page. Depands on the validation result i have to call the backing bean method.

Thanks in Advance.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming that you're calling Javascript during the onclick of the button or onsubmit of the form, just let the function return true or false depending on the validation outcome. If the onclick or onsubmit returns false, then the initiating click or submit will be blocked and the page will stay the same.
 
Balaji Soundarajan
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.
If i called the javascript function from the onclick or onsubmit method, from there how can i access the backing bean method. Please tell me.
 
suresh nerella
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
even javascript returns false, backing bean method is executing.... I have code something like below.....
even i am returning false.... after clicking on popup...... the control is still going for backing bean method and giving exception...

function check() {

if(previouslySelectedRow=='null'){

alert('Please Select a row from the table' );
return false;
}

}

<h:commandButton id="editGroup" value="Edit" type="submit" styleClass="submit-button" onclick="check()" action="#{mangUserBackBean.editGroup}"/>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic