Qaiser
Qaiser

Reputation: 19

How to call javascript from backingbean jsf

ClientScript.RegisterStartupScript(
    this.GetType(),
    "ReturnScript", 
    "<script language='javascript'> alert('" + ErrorMsg + "');</script>");

alternate in java (JSF)

Upvotes: 1

Views: 3492

Answers (1)

BalusC
BalusC

Reputation: 1109422

Just print the JS code as-is in the JSF view. The JS runs at client machine, not at server machine. You can use <h:outputText> for this.

<h:outputText value="<script>alert('foo');</script>" escape="false" />

You can even get it as a bean property:

<h:outputText value="#{bean.script}" escape="false" />

The escape="false" is there to prevent the (default) HTML-escaping of the value.

See also:

Upvotes: 5

Related Questions