gpt4 book ai didi

aem - CQ5 组件后编辑

转载 作者:行者123 更新时间:2023-12-01 05:09:32 25 4
gpt4 key购买 nike

我像这样创建了一个 sling servlet 骨架......

@SlingServlet(paths = "/bin/foo/bar", methods = "POST")
public class FooBarServlet extends SlingAllMethodsServlet {

private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {

response.setHeader("Content-Type", "text/plain");
response.getWriter().write("foo bar");
LOGGER.info("hello world");
}
}

我为我的组件创建了一个编辑配置
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:EditConfig">
<cq:listeners jcr:primaryType="cq:EditListenersConfig"
afteredit="myapp.components.foobar" />
</jcr:root>

我创建了一个 cq:ClientLibraryFolder并添加了这个js
var myapp = { components : {}  };
myapp.components.foobar = function(component, reloadPage) {
var oncomplete = function(success) {
if (success) {
if (reloadPage) document.location.reload();
else component.refreshSelf();
} else
console.log('could not foobar on component ' + component.path);
};

CQ.HTTP.post('/bin/boo/bar', oncomplete, { path : component.path });
};

我的页面加载,我的组件加载,我的 clientlib js 加载,我在控制台中没有看到任何错误。我编辑我的组件并点击确定。我的 servlet 被击中,我跟踪日志服务器端并且没有看到任何错误。当我打开控制台进行跟踪时,我没有看到客户端错误。我的回答是 200 好。一切看起来都很棒!除了我在浏览器的右上角不断收到“未指定的错误”

Unspecified Error

有谁知道我什至开始解决这个问题,因为我在服务器端日志上没有看到错误,在客户端控制台上也没有看到错误?

更新

感谢@rakhi4110 对 CQ.HTTP 的引用.我能够从那个文档中想出一些东西

第一 ,设置 suppressErrorMsg标志隐藏了错误信息
CQ.HTTP.post('/bin/foo/bar', oncomplete, { path : component.path }, null, true);

第二 ,我不喜欢压抑的东西,所以我试着像这样制作我的回应
{
"headers" :
{
"Status":200,
"Message":"foo bar"
}
}

然而那什么也没做。

第三 ,在查看 CQ.HTTP api 时,我注意到其中很多都被弃用,取而代之的是 CQ.shared.HTTP .简单地使用 post 函数,没有抑制,工作
CQ.shared.HTTP.post('/bin/foo/bar', oncomplete, { path : component.path });

现在我坚持使用选项 #3,直到我能找出正确的 json 响应。

最佳答案

Unspecified error是由于应用于 CQ.HTTP.post() 的默认配置

它尝试从响应头中检索消息并将其通知给用户。由于您的自定义 servlet 不提供任何此类消息,因此您收到了此通知。

可以通过设置 suppressErrorMsg 来抑制此通知。参数为真。 IE。,

CQ.HTTP.post('/bin/boo/bar', oncomplete, { path : component.path }, null, true);

进一步观察,似乎通知消息是根据响应构建的,当
  • 响应是 HTML
  • 响应包含一个 id 为“消息”的 HTML 标记。在这种情况下,标签的内容被视为消息。

  • 通知消息可能使用的示例 HTML 响应是
    <html>
    <head>
    <title>OK</title>
    </head>
    <body>
    <h1>OK</h1>
    <table>
    <tbody>
    <tr>
    <td>Status</td>
    <td><div id="Status">200</div></td>
    </tr>
    <tr>
    <td>Message</td>
    <td><div id="Message">Demo Notification Message</div></td>
    </tr>
    </tbody>
    </table>
    </body>
    </html>

    更多配置请引用 CQ.HTTP

    关于aem - CQ5 组件后编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26002764/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com