1

Some problem with embedding other ZK portlet in Liferay

asked 2014-01-02 09:38:21 +0800

mistww gravatar image mistww
13 1

Hi all, In our business, we hope can embedding ZK portlet in other ZK portlet. I have try to do this as www.liferay.com//zh//community//forums//-//messageboards//message//6472424 It works good as those two portlet in two war file, but can't work when they in same war. I use an RuntimePortletEmbedUtil(thanks Bert Willems) class to render the embeded portlet and return the html fragment. When the two portlet in difference war file ,display as HTML, but if two portlet in same war file,display as TXT, as if the script tag and other important code lost. Debug with the code lead to org.zkoss.zk.ui.sys.HtmlPageRenders, many configuratin,I lost. Here is my work Environment: ZK6.5.2,Liferay6.1.1, liferay-plugins-sdk-6.1.1, JDK1.6.026. Render method in RuntimePortletEmbedUtil: public static String renderPortlet(final HttpServletRequest request, final HttpServletResponse response, final String portletId, final String queryString) throws SystemException, IOException, ServletException, ValidatorException { // Get servlet request / response

    HttpServletRequest servletRequest = request;
    HttpServletResponse servletResponse = response;
    // Get theme display
    final ThemeDisplay themeDisplay = (ThemeDisplay) servletRequest
            .getAttribute(WebKeys.THEME_DISPLAY);
    // Backup current state
    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();
    PortletDisplay portletDisplayClone = new PortletDisplay();
    portletDisplay.copyTo(portletDisplayClone);
    final Map<String, Object> requestAttributeBackup = new HashMap<String, Object>();
    for (final String key : Collections
            .list((Enumeration<String>) servletRequest.getAttributeNames())) {
        requestAttributeBackup.put(key, servletRequest.getAttribute(key));
    }
    // Render the portlet as a runtime portlet
    String result="";
    try {
        PortletBag implPortletBag = PortletBagPool.get(PortletKeys.JOURNAL);
        com.liferay.portal.model.Portlet portlet = PortletLocalServiceUtil
                .getPortletById(PortalUtil.getCompanyId(request), portletId);
        servletRequest.setAttribute(WebKeys.RENDER_PORTLET_RESOURCE,
                Boolean.TRUE);
        result = PortalUtil.renderPortlet(
                implPortletBag.getServletContext(), servletRequest,
                servletResponse, portlet, queryString, false);

// Here I got the Wrong result }catch(Exception e) { e.printStackTrace(); }finally { // Restore the state portletDisplay.copyFrom(portletDisplayClone); portletDisplayClone.recycle(); for (final String key : Collections .list((Enumeration<string>) servletRequest .getAttributeNames())) { if (!requestAttributeBackup.containsKey(key)) { servletRequest.removeAttribute(key); } } for (final Map.Entry<string, object=""> entry : requestAttributeBackup .entrySet()) { servletRequest.setAttribute(entry.getKey(), entry.getValue()); } } return result; }

The right result should include: //zkmx([0,"xZCP",{dt:"z5ej",cu:"/mytask-portlet",uu:"/mytask-portlet/zkau",ru:"/html/workflowlogViewer/view.zul",style:"width:100%;",ct:true},[["zul.wnd.Window","xZCP0",{$$onSize:false,$$onMaximize:false,$$onOpen:false,$$onMinimize:false,$$onZIndex:false,$onClose:true,$$onMove:false,hflex:"true"},[["zul.sel.Listbox","xZCP1",{$$onRender:true,$$onSelect:false,$$onDataLoading:true,$$onAnchorPos:false,$$onAcrossPage:true,$$onInnerWidth:false,$$onPageSize:true,$$onScrollPos:false,pagingPosition:"both",model:true,topPad:0,totalSize:3,offset:0,paginal:{$u:"xZCP2"}},[["zul.sel.Listhead","xZCP3",{$$onColSize:false},[["zul.sel.Listheader","xZCP4",{$onSort:true,width:"55px",style:"text-align:center;",label:"XXXX",align:"center"},[]],["zul.sel.Listheader","xZCP5",{$onSort:true,style:"text-align:center;",label:"XXXXX",align:"center"},[]]]],["zul.sel.Listitem","xZCPc",{height:"45px",loaded:true,index:0},[["zul.sel.Listcell","xZCPd",{label:"1"},[]],["zul.sel.Listcell","xZCPe",{style:"text-align:left;')",label:"XXXX"},[]]]],["zul.sel.Listitem","xZCPf",{height:"45px",loaded:true,index:1},[["zul.sel.Listcell","xZCPg",{label:"2"},[]],["zul.sel.Listcell","xZCPh",{style:"text-align:left;')",label:"XXXXXXXX"},[]]]],["zul.sel.Listitem","xZCPi",{height:"45px",loaded:true,_index:2},[["zul.sel.Listcell","xZCPj",{label:"3"},[]],["zul.sel.Listcell","xZCPk",{style:"text-align:left;')",label:"XXXXXX"},[]]]],["zul.mesh.Paging","xZCP2",{$$onPaging:false,$onPaging:true,totalSize:3,pageSize:10,detailed:true,autohide:true},[]]],"paging"]]]]]);/]]>

The wrong result include:

zkx( [0,'yQ0Q',{dt:'zeu1',cu:'/mytask-portlet',uu:'/mytask-portlet/zkau',ru:'/html/workflowlogViewer/view.zul',style:'width:100%;',ct:true},[ ['zul.wnd.Window','yQ0Q0',{$$onSize:false,$$onMaximize:false,$$onOpen:false,$$onMinimize:false,$$onZIndex:false,$onClose:true,$$onMove:false,hflex:'true'},[ ['zul.sel.Listbox','yQ0Q1',{$$onRender:true,$$onSelect:false,$$onDataLoading:true,$$onAnchorPos:false,$$onAcrossPage:true,$$onInnerWidth:false,$$onPageSize:true,$$onScrollPos:false,pagingPosition:'both',model:true,topPad:0,totalSize:3,offset:0,paginal:{$u:'yQ0Q2'}},[ ['zul.sel.Listhead','yQ0Q3',{$$onColSize:false},[ ['zul.sel.Listheader','yQ0Q4',{$onSort:true,width:'55px',style:'text-align:center;',label:'XX',align:'center'},[]], ['zul.sel.Listheader','yQ0Q5',{$onSort:true,style:'text-align:center;',label:'XXXXX',align:'center'},[]]]], ['zul.sel.Listitem','yQ0Qc',{height:'45px',loaded:true,index:0},[ ['zul.sel.Listcell','yQ0Qd',{label:'1'},[]], ['zul.sel.Listcell','yQ0Qe',{style:'text-align:left;\')',label:'XXXXXX'},[]]]], ['zul.sel.Listitem','yQ0Qf',{height:'45px',loaded:true,index:1},[ ['zul.sel.Listcell','yQ0Qg',{label:'2'},[]], ['zul.sel.Listcell','yQ0Qh',{style:'text-align:left;\')',label:'XXXXXX'},[]]]], ['zul.sel.Listitem','yQ0Qi',{height:'45px',loaded:true,_index:2},[ ['zul.sel.Listcell','yQ0Qj',{label:'3'},[]], ['zul.sel.Listcell','yQ0Qk',{style:'text-align:left;\')',label:'XXXXXXX'},[]]]], ['zul.mesh.Paging','yQ0Q2',{$$onPaging:false,$onPaging:true,totalSize:3,pageSize:10,detailed:true,autohide:true},[]]],'paging']]]]]);

Any suggestions would be greatly appreciated.

delete flag offensive retag edit
Be the first one to answer this question!
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2014-01-02 09:38:21 +0800

Seen: 21 times

Last updated: Jan 02 '14

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More