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

alternate in java (JSF)

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Qaiser
  • 19
  • 3
  • 4
  • Either I haven't had enough coffee yet, or this is a banner day for vague, unintelligible questions. – Pointy Jun 17 '10 at 13:04
  • 1
    @Pointy: this code sample comes from ASP.NET world. He's asking for a JSF equivalent. – BalusC Jun 17 '10 at 14:30

1 Answers1

5

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:

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Hi I have applied your solution. In my case its showing this error - Error Parsing /viewMetadata/DynamicCss.xhtml: Error Traced[line: 28] The value of attribute "value" associated with an element type "null" must not contain the '<' character. – Kush Sahu Feb 25 '13 at 15:15
  • 1
    @Kush: that will indeed happen if you're using Facelets instead of JSP. Just manually escape it. See also e.g. http://stackoverflow.com/questions/6883860/how-to-insert-special-characters-like-and-into-jsf-components-value-attribu/6883872#6883872 – BalusC Feb 25 '13 at 15:16