我看到自己面临着一项可能很容易的任务,我觉得自己走错了方向。当用户访问默认目标网页时,我需要弹出一个窗口。这个弹出窗口应该在iframe中显示一个外部网页(我们无法通过单点登录来解决这些问题)。由于只有部分用户必须使用此对话框,我们希望有机会不再使用此弹出窗口(通过cookie或DB,如果重置此选项必须由管理员手动完成,则可以)。所以基本上我们需要一个“不要再问”-popup和iframe。
我们决定将MVC portlet放在没有大小的登陆页面上;只有弹出窗口。我有一个带有iframe的AlloyUI弹出框,一个复选框,感觉这是错误的方式,因为当弹出窗口关闭时我无法从该复选框中获取信息。
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<portlet:defineObjects />
<aui:script>
AUI().ready('aui-dialog', 'aui-overlay-manager', 'dd-constrain', 'console',
function(A) {
var bodyNode = A.Node.create('<div><iframe src="http://www.dummysite.com"></iframe> </div>');
var footerNode = A.Node.create('<input name="donotaskagain" type="checkbox"></input> <label for="donotaskagain">Do not ask again</label>');
var dialog = new A.Dialog({
title: 'DISPLAY CONTENT',
centered: true,
modal: true,
resizable: false,
width: 510,
height: 430,
bodyContent: bodyNode,
footerContent: footerNode
});
dialog.render();
}
);
</aui:script>
我希望你能帮助我。有关如何在该上下文中正确使用JSP,AlloyUI和Java的所有背景信息将非常受欢迎。
答案 0 :(得分:0)
我们通过为用户点击保存按钮时提交的弹出窗口的页脚引入一个表单来规避问题。它不是最佳的,因为页面需要刷新,但由于弹出窗口不再发生,因此可以接受。也许其他人可以使用AJAX发布帖子解决方案,因此这种行为更加顺畅。
首先我们有view.jsp:
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<portlet:defineObjects />
<portlet:actionURL name="storeDoNotAskAgain" var="storeDoNotAskAgainURL"></portlet:actionURL>
<!-- Check here whether or not the popup should be shown. We used JSP tags (an "if" around the script)
and a JAVA helper class to access the Expandobridge to get a variable from the Liferay DB
to decide whether or not the user had chosen not to display the popup again.
<!-- Create Alloy UI dialog with iframe pointing to the specified site as a body and form as footer.
The form can be submitted to store the "do not ask again"-checkbox value in DB.
It is connected with an action from of the portlet. -->
<aui:script>
AUI().ready('aui-dialog', 'aui-overlay-manager', 'dd-constrain',
function(A) {
var bodyNode = A.Node.create('<div><iframe src="http://www.dummysite.com"> </iframe> </div>');
var footerNode = A.Node.create('<form action="<%= storeDoNotAskAgainURL%>" method="post"><input type="submit" value="Save" class="submit"><input name="donotaskagain" type="checkbox"></input> <label for="donotaskagain">Do not ask again.</label></form>');
var dialog = new A.Dialog({
title: "Title",
bodyContent: bodyNode,
footerContent: footerNode
});
dialog.render();
}
);
</aui:script>
然后我们创建了一个新的portlet主类来处理表单引用的store-action。
package com.example.portlet;
import ...
public class MyPortlet extends MVCPortlet {
@ProcessAction(name = "storeDoNotAskAgain")
public void storeDoNotAskAgain(ActionRequest request, ActionResponse response) throws Exception {
boolean val = ParamUtil.getBoolean(request, "donotaskagain", false);
// store boolean in db or a file
}
}
备考:您需要调整portlet.xml以将portlet主类指向新的portlet类
<portlet-class>com.example.portlet.MyPortlet</portlet-class>