Liferay研究之十四:子窗口向父窗口的值传递(字典项的实现)

44 篇文章 0 订阅
43 篇文章 0 订阅

 

描述:在文档库中,“Add Shortcut”会弹出一个先选择Group,后选择文档的对话框;

实现机制:

在document_library/edit_file_shortcut.jsp中

<input type="button" value="<liferay-ui:message key="select" />" onClick="var toGroupWindow = window.open('<portlet:renderURL windowState="<%= LiferayWindowState.POP_UP.toString() %>"><portlet:param name="struts_action" value="/document_library/select_group" /></portlet:renderURL>', 'toGroup', 'directories=no,height=640,location=no,menubar=no,resizable=yes,scrollbars=no,status=no,toolbar=no,width=680'); void(''); toGroupWindow.focus();" />


在onClick事件中,打开一个窗口,该窗口打开一个renderURL,该URL会执行对应的Action.render方法,find the right forwarding, 最终打开select_group.jsp页面。为什么不直接打开select_group.jsp页面呢?这样可以用liferay的方式来进行参数传递,还可以指定窗口的模式;

需要注意的是使用renderURL时,引号的使用方法。一般是:在外围用但引号,里面正常的使用双引号, <portlet:renderURL>中的双引号与html input中的双引号不会冲突,因为系统会将<Portlet:renderURL>解析为对应的http://xxxxxxx字符串。

执行正确的话,上面会打开弹出窗口。

在select_xxxx.jsp页面中,查询到一个list之后,会通过:
 StringMaker sm = new StringMaker();

 sm.append("javascript: opener.");
 sm.append(renderResponse.getNamespace());
 sm.append("selectGroup('");
 sm.append(group.getGroupId());
 sm.append("', '");
 sm.append(UnicodeFormatter.toString(group.getName()));
 sm.append("'); window.close();");

 String rowHREF = sm.toString();


来调用父窗口中的selectXxxx JS 代码,向父窗口传递一个id参数,然后将本窗口关闭。

在父窗口(edit_file_shortcut.jsp)中,声明JS function如下:
 function <portlet:namespace />selectGroup(groupId, groupName) {
  if (document.<portlet:namespace />fm.<portlet:namespace />toGroupId.value != groupId) {
   <portlet:namespace />selectFileEntry("", "", "");
  }

  document.<portlet:namespace />fm.<portlet:namespace />toGroupId.value = groupId;
  document.<portlet:namespace />fm.<portlet:namespace />toFolderId.value = "";
  document.<portlet:namespace />fm.<portlet:namespace />toName.value = "";

  var nameEl = document.getElementById("<portlet:namespace />toGroupName");

  nameEl.innerHTML = groupName + "&nbsp;";

  document.getElementById("<portlet:namespace />selectToFileEntryButton").disabled = false;
 }


这样就完成了子窗口向父窗口的值传递过程。 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值