Tuesday, August 5, 2014

Pass bean properties to JavaScript function


In the JavaScript function call include bean properties in quotes

for example:

<h:form>
  <h:commandButton type="button" value="JavaScript Call" onclick="printInfo('#{person.firstName}', '#{person.lastName}')"/>
</h:form>

The JavaScript function for this is shown in the following code:

<script type="text/javascript">
  function printInfo(name, lastName) {
    alert("Name: " + name + " " + lastName);
  }
</script>

1 comment: