[英]How to use JavaScript in Velocity file from Webwork1 module?
I have an Atlassian SDK webwork1 module with its view:我有一个 Atlassian SDK webwork1 模块及其视图:
<webwork1 key="ai-config" name="AI Config" i18n-name-key="ai-config.name">
<description key="ai-config.description">The AI Config Plugin</description>
<actions>
<action name="com.softgile.jira.webwork.AIConfigAction" alias="AIConfigAction">
<view name="success">/templates/ai-config/success.vm</view>
</action>
</actions>
</webwork1>
In the view I have several forms:在视图中我有几个 forms:
<form class="aui" id="configForm" method="post" action="AIConfigAction!saveIp.jspa">
...
</form>
<form class="aui" id="serviceName" method="post" action="AIConfigAction!saveService.jspa">
...
</form>
Also I have a button there, which is controlled with JS:我还有一个按钮,它是用 JS 控制的:
<div class="field-group">
<label for="authenticate">
<span class="aui-icon aui-icon-large aui-iconfont-app-access">Insert meaningful text here for accessibility</span>
</label>
<div class="buttons">
<button class="aui-button aui-button-primary" id="authenticate">Authenticate</button>
</div>
</div>
In JS file I have something like this:在 JS 文件中我有这样的东西:
AJS.toInit(function(){
AJS.$(document).on('click', '#authenticate', function(e) {
e.preventDefault();
alert("authenticate");
});
});
Both forms work okay, and JS works when I click the button. forms 都工作正常,当我单击按钮时 JS 工作。 But JS stops working when I submit one of the forms, it works only before submitting forms. I see that URL is changing from AIConfigAction.jspa
to AIConfigAction.saveService.jspa
and in that case JS not working.但是当我提交 forms 之一时,JS 停止工作,它仅在提交 forms 之前工作。我看到 URL 正在从AIConfigAction.jspa
更改为AIConfigAction.saveService.jspa
,在这种情况下 JS 不工作。 How can I make JS work?我怎样才能让 JS 工作?
I have found the solution myself.我自己找到了解决方案。 So, the problem in my case was that I was including web-resources inside doExecute() method of the Webwork.因此,我的问题是我在 Webwork 的 doExecute() 方法中包含了 Web 资源。 That is why after calling other methods like doSave() web-resources stopped working.这就是为什么在调用 doSave() 等其他方法后网络资源停止工作的原因。
Solution - move web-resources inclusion to Webwork constructor:解决方案 - 将 Web 资源包含移动到 Webwork 构造函数:
@Inject
public AIConfigAction(WebResourceManager webResourceManager) {
webResourceManager.requireResourcesForContext("myPlugin");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.