In Oracle ADF I am having
<af:resource type="javascript">
var chatSettings = {
url: "google",
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.
In Oracle ADF I am having
<af:resource type="javascript">
var chatSettings = {
url: "google",
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.
Share Improve this question edited Mar 11 at 14:40 Mister Jojo 22.6k6 gold badges25 silver badges44 bronze badges asked Mar 11 at 14:21 SourabhSourabh 6122 gold badges11 silver badges22 bronze badges2 Answers
Reset to default 0You can use af:clientAttribute to pass dynamic parameters. See https://www.jobinesh/2011/03/passing-dynamic-parameters-to-java.html for a sample
You can also run a javascript function inside your ADF java bean : https://cedricleruth/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);
}