1

In Oracle ADF I am having

<af:resource type="javascript">
var chatSettings = {
   url: "google.com",
   id: "test"
}
function init(){
...
}
</af:resource>
<af:image id="abc">
<af:clientListener method="init()')" type="click"/>
</af:image>

I want to have url and id as dynamic parameters. I am already defining or have access to those using attributes expression like #{attrs.url} and #{attrs.id} But I am unable to dynamically inject values into the script.

If I use expressions inside af:resource JavaScript block I get the below errors:

Caused by: oracle.jsp.parse.JspParseException:
Error: Encountered deferred syntax #{ in template text. If intended as a literal, escape it or set directive deferredSyntaxAllowedAsLiteral

How can I inject the values into JavaScript block or call the function with parameters so that the variables can be injected into the var block.

2 Answers 2

0

You can use af:clientAttribute to pass dynamic parameters. See https://www.jobinesh.com/2011/03/passing-dynamic-parameters-to-java.html for a sample

Sign up to request clarification or add additional context in comments.

Comments

0

You can also run a javascript function inside your ADF java bean : https://cedricleruth.com/how-to-execute-client-javascript-in-an-adf-java-bean-action/

/*** In YOURJSF.jsf button, or other component that need to execute a javascript on action, add : ****/
<af:commandButton text="ClickMe" id="cb1" actionListener="#{YOURSCOPE.YOURJAVABEAN.clickToExecuteJavascriptAction}"/>
 /*** In YOURJAVABEAN.java class add : ***/
 public void clickToExecuteJavascriptAction(ActionEvent actionEvent) {
  this.executeClientJavascript("console.log('You just clicked : " + actionEvent.getSource() + " ')");
  //Note: if you use a java string value in this function you should escape it to avoid breaking the javascript.
  //Like this : stringValue.replaceAll("[^\\p{L}\\p{Z}]", " ")
 }

//You should put this function in a util java class if you want to use it in multiple bean
public static void executeClientJavascript(String script) {
 FacesContext facesContext = FacesContext.getCurrentInstance();
 ExtendedRenderKitService service = Service.getRenderKitService(facesContext, ExtendedRenderKitService.class);
 service.addScript(facesContext, script);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.