最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论