java - Oracle ADF how to pass dynamic values into JS inside <af:resource type="javascript"> - St

In Oracle ADF I am having<af:resource type="javascript">var chatSettings = {url: &quo

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 badges
Add a comment  | 

2 Answers 2

Reset to default 0

You 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);
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744788713a4593783.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信