为什么 xPage 处理我的评论,好像它们不是 [英] why does xPage process my Comments as though they weren't

查看:21
本文介绍了为什么 xPage 处理我的评论,好像它们不是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 XPage 中有一个奇怪的行为,带有注释代码.

I got a strange behavior in XPage, with commented Code.

我有一个包含大量代码的文本字段,它在我遇到此问题的地方输出 html.在开发时,我在其他领域的某些领域遇到了很多麻烦,所以我决定 - 更好地了解该领域正在做什么 - 将代码从故障字段复制到我的文本字段中的注释,以便我看到其他代码.但后来 xPage 开始表现得很奇怪,直到我发现问题.

I had a textfield with a lot of code in it which outputs html where I hit this issue. While developing I had a lot of trouble with some fields other fields so I decided -to get a better idea what the field is doing- to copy the code from the troublefields to a comment inside my textfield to have the other code at my sight. But then the xPage started to behave strange until I found the issue.

下面的代码是导致我的问题的一个例子,它有两个文本字段,一个设置范围变量,还有一个注释,设置相同的变量但已注释,另一个显示ScopeVar.我以为这会在第二个文本框中输出我在哪里",但结果却是呼呼我在这里".

The Code below is a example what caused my issue, it has two text fields in it one which sets a scope var and also has a comment which sets the same var but commented, ant another one which shows the ScopeVar. I thought this would output 'where I am' in the second text box but instead I got the 'Huhu I am here'.

        <xp:text escape="true" id="computedField7">
            <xp:this.value><![CDATA[#{javascript://
                sessionScope.put("findme","where i am");
                /* #{javascript:sessionScope.put("findme","HuHu I am here!");} */
                return sessionScope.findme;}]]></xp:this.value>
        </xp:text>
        <xp:br></xp:br>
        <xp:text escape="true" id="computedField6"
            value="#{javascript:return sessionScope.findme;}">
        </xp:text>

在我遇到此问题的原始代码中,我想将旧的 #{} el 注释掉以使用 JavaScript,但将 el 保留在代码中间的注释中......结果相同.看来,如果你在评论中使用 #{ 或 ${ ,它总是会被计算出来!

In my original Code where I hit this issue I wanted to comment the old #{} el out to use a JavaScript instead but keep the el in comment in the middle of the code.. same result. It seams that if you use #{ or ${ in a comment it will always get computed!

在注释 9 中解决了这个问题.我目前使用的是 8.5.3.

Got this fixed in notes 9. I am currently using 8.5.3.

更新:小提示:使用 dojoAttribute queryExpr 时要小心,因为查询看起来像 SSJS "${0}" 并且也会被解释为 SSJS.我现在用这个:

Update: As a small note: Be careful when using the dojoAttribute queryExpr because the query Looks like SSJS "${0}" and also gets interpreted as SSJS. I now use this:

<xe:this.queryExpr><![CDATA[${javascript:"*$\{0}*";}]]></xe:this.queryExpr>

让它发挥作用.感谢 Paul Stephen Withers 提供 \{ 的提示.

to make it work. Thanks to Paul Stephen Withers for the tip with the \{.

推荐答案

这是一个有趣的错误.

这是由 JavaScript 解释器的预处理器功能引起的.通常,您可以在 CSJS 代码中编写 #{javascript:...} 来替换部分代码之前它被放入渲染页面.

It is caused by pre-processor functionality of JavaScript interpreter. Normally, you can write #{javascript:...} in CSJS code to replace parts of code before it gets put to rendered page.

就您而言,它是 SSJS.同样,解释器替换 SSJS 代码中的 #{javascript:...} 并认为,工作已经完成.这样你就可以看到渲染页面上的代码,而不是执行代码的结果.

In your case it is SSJS. Again, the interpreter replaces the #{javascript:...} inside your SSJS code and thinks, work is done. This way you see the code on rendered page instead the result of executed code.

作为一种解决方法,只需从 /* #{javascript... 中删除 # ,它就会像预期的那样工作.

As a workaround, just delete # from /* #{javascript... and it will work like expected.

这篇关于为什么 xPage 处理我的评论,好像它们不是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆