当前位置: 首页 > 知识库问答 >
问题:

覆盖用户操作。升级到Liferay 7.3后jsp失败

戴浩初
2023-03-14

我们在Liferay 7.0.6中实现了一个corejspook模块来定制user_action.jsp,它工作得很好。

升级到Liferay 7.3.6后,它停止工作。通过在gogo shell中搜索,我已经确保了我们将jsp替换成的模块是正确的。我还查看了源代码,以确认包含。jsp是对的。我将版本号更新为Liferay 7.3捆绑包版本(5.0.53)。我的bnd中的条目。bnd是:Fragment Host:com。利弗雷。用户。管理网状物捆绑版本=“5.0.53”

当我部署模块时,它不会像应该的那样重新启动片段主机包(在Liferay 7.0中也是如此)。手动重新启动该捆绑包也不起作用——已修改。没有使用jsp。

顺便说一下,我们还有其他工作正常的corejspook。这是唯一一个不起作用的,所以我一定错过了什么。

更新:我包含了所要求的代码。下面是模块中的四个文件(不包括创建模块时创建的build.gradle和Language_en.properties等默认文件)。

bnd。bnd

Bundle-Version: 7.3.6.1
Fragment-Host: com.liferay.users.admin.web;bundle-version="5.0.53"
-sources: true
-jsp: *.jsp,*.jspf

user_action.jsp

<%--
/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */
--%>

<%@ include file="/init.jsp" %>
 
<%@ page import="com.liferay.petra.encryptor.Encryptor" %>
<%@ page import="com.liferay.portal.kernel.util.HtmlUtil" %>

<%

UserSearch searchContainer = (UserSearch)request.getAttribute("liferay-ui:search:searchContainer");

String redirect = searchContainer.getIteratorURL().toString();

ResultRow row = (ResultRow)request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);

User user2 = (User)row.getObject();

long userId = user2.getUserId();

String userLandingPage = null;

User currentUser = user2;
List<Organization> userOrganizations = currentUser.getOrganizations();


if (Validator.isNotNull(userOrganizations) && !userOrganizations.isEmpty())
{
    // If user is member of more than one organization then it will take
    // first organization from list
    Organization organization = userOrganizations.get(0);
    if (Validator.isNotNull(organization))
    {
        Group organizationGroup = organization.getGroup();
        if (organizationGroup.getPrivateLayoutsPageCount() > 0)
        {
            
            String privateGroupURL = PropsUtil.get(PropsKeys.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING);
            String groupFriendlyURL = organizationGroup.getFriendlyURL();
            userLandingPage = privateGroupURL + groupFriendlyURL;

            String encDoAsUserId = Encryptor.encrypt(
                company.getKeyObj(), String.valueOf(userId));
            
            userLandingPage = userLandingPage + "?doAsUserId=" + HtmlUtil.escapeURL(encDoAsUserId);
            System.out.println("userLandingPage is: " + userLandingPage);
        } 
        else
        {
            System.out.println(organizationGroup.getName() + " organization site doesn't have any private page. So default landing page will be used");
        }
    }
}

// System.out.println("Landing page is: " + userLandingPage);

 
%>

<liferay-ui:icon-menu
    direction="left-side"
    icon="<%= StringPool.BLANK %>"
    markupView="lexicon"
    message="<%= StringPool.BLANK %>"
    showWhenSingleIcon="<%= true %>"
>

    <%
    boolean hasUpdatePermission = UserPermissionUtil.contains(permissionChecker, userId, ActionKeys.UPDATE);
    %>

    <c:if test="<%= hasUpdatePermission %>">
        <portlet:renderURL var="editUserURL">
            <portlet:param name="mvcRenderCommandName" value="/users_admin/edit_user" />
            <portlet:param name="redirect" value="<%= redirect %>" />
            <portlet:param name="p_u_i_d" value="<%= String.valueOf(userId) %>" />
        </portlet:renderURL>

        <liferay-ui:icon
            message="edit"
            url="<%= editUserURL %>"
        />
    </c:if>

    <c:if test="<%= UserPermissionUtil.contains(permissionChecker, userId, ActionKeys.PERMISSIONS) %>">
        <liferay-security:permissionsURL
            modelResource="<%= User.class.getName() %>"
            modelResourceDescription="<%= user2.getFullName() %>"
            resourcePrimKey="<%= String.valueOf(userId) %>"
            var="permissionsUserURL"
            windowState="<%= LiferayWindowState.POP_UP.toString() %>"
        />

        <liferay-ui:icon
            message="permissions"
            method="get"
            url="<%= permissionsUserURL %>"
            useDialog="<%= true %>"
        />
    </c:if>

    <c:if test="<%= (PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_ENABLED || PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_ENABLED) && hasUpdatePermission %>">

        <%
        PortletURL managePagesURL = PortletProviderUtil.getPortletURL(request, user2.getGroup(), Layout.class.getName(), PortletProvider.Action.EDIT);

        managePagesURL.setParameter("redirect", redirect);
        %>

        <liferay-ui:icon
            message="manage-pages"
            url="<%= managePagesURL.toString() %>"
        />
    </c:if>

    <c:if test="<%= !PropsValues.PORTAL_JAAS_ENABLE && PropsValues.PORTAL_IMPERSONATION_ENABLE && (userId != user.getUserId()) && !themeDisplay.isImpersonated() && UserPermissionUtil.contains(permissionChecker, userId, ActionKeys.IMPERSONATE) %>">
        <liferay-security:doAsURL
            doAsUserId="<%= userId %>"
            var="impersonateUserURL"
        />

        <liferay-ui:icon
            message="impersonate-user"
            target="_blank"
            url="<%= Validator.isNotNull(userLandingPage) ? userLandingPage : impersonateUserURL %>"
        />
    </c:if>

    <c:if test="<%= UserPermissionUtil.contains(permissionChecker, userId, ActionKeys.DELETE) %>">
        <c:if test="<%= !user2.isActive() %>">
            <portlet:actionURL name="/users_admin/edit_user" var="restoreUserURL">
                <portlet:param name="<%= Constants.CMD %>" value="<%= Constants.RESTORE %>" />
                <portlet:param name="redirect" value="<%= redirect %>" />
                <portlet:param name="deleteUserIds" value="<%= String.valueOf(userId) %>" />
            </portlet:actionURL>

            <liferay-ui:icon
                message="activate"
                url="<%= restoreUserURL %>"
            />
        </c:if>

        <portlet:actionURL name="/users_admin/edit_user" var="deleteUserURL">
            <portlet:param name="<%= Constants.CMD %>" value="<%= user2.isActive() ? Constants.DEACTIVATE : Constants.DELETE %>" />
            <portlet:param name="redirect" value="<%= redirect %>" />
            <portlet:param name="deleteUserIds" value="<%= String.valueOf(userId) %>" />
        </portlet:actionURL>

        <c:if test="<%= userId != user.getUserId() %>">
            <c:choose>
                <c:when test="<%= user2.isActive() %>">
                    <liferay-ui:icon-deactivate
                        url="<%= deleteUserURL %>"
                    />
                </c:when>
                <c:when test="<%= !user2.isActive() && PropsValues.USERS_DELETE %>">
                    <liferay-ui:icon-delete
                        url="<%= deleteUserURL %>"
                    />
                </c:when>
            </c:choose>
        </c:if>
    </c:if>

</liferay-ui:icon-menu>

corejsphook。UserActionCustomJspBag。JAVA

/**
 * Copyright 2000-present Liferay, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package corejsphook;

import com.liferay.portal.deploy.hot.CustomJspBag;
import com.liferay.portal.kernel.url.URLContainer;

import java.net.URL;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;

/**
 * @author Scott McIntosh, ICF
 */
@Component(
    immediate = true,
    property = {
        "context.id=UserActionCustomJspBag",
        "context.name=User Action Custom JSP Bag",
        "service.ranking:Integer=111"
    }
)
public class UserActionCustomJspBag implements CustomJspBag 
{
    @Override
    public String getCustomJspDir() {
        return "META-INF/resources/";
    }

    @Override
    public List<String> getCustomJsps() {
        System.out.println("In getCustomJsps().  _customJsps is null?");
        System.out.println(_customJsps == null);
        return _customJsps;
    }

    @Override
    public URLContainer getURLContainer() {
        System.out.println("In getURLContainer()");
        return _urlContainer;
    }

    @Override
    public boolean isCustomJspGlobal() {
        System.out.println("In isCustomJspGlobal()");
        return true;
    }

    @Activate
    protected void activate(BundleContext bundleContext) {
        System.out.println("In activate()");
        bundle = bundleContext.getBundle();

        _customJsps = new ArrayList<>();

        Enumeration<URL> entries = bundle.findEntries(
            getCustomJspDir(), "*.jsp", true);

        while (entries.hasMoreElements()) {
            URL url = entries.nextElement();
            System.out.println("Processing jsp: " + url);
            _customJsps.add(url.getPath());
        }
    }

    private List<String> _customJsps;

    private final URLContainer _urlContainer = new URLContainer() {

        @Override
        public Set<String> getResources(String path) {
            System.out.println("In getResources()");
            Set<String> paths = new HashSet<>();

            for (String entry : _customJsps) {
                if (entry.startsWith(path)) {
                    paths.add(entry);
                }
            }

            return paths;
        }

        @Override
        public URL getResource(String name) {
            System.out.println("In getResource()");
            return bundle.getEntry(name);
        }

    };

    private Bundle bundle;

}

gov.nysdot。骑野兔。Nyridenhareenus资源包。JAVA

ackage gov.nysdot.rideshare;

import com.liferay.portal.kernel.language.UTF8Control;

import java.util.Enumeration;
import java.util.ResourceBundle;
import org.osgi.service.component.annotations.Component;

@Component(
        property = { "language.id=en_US" }, 
        service = ResourceBundle.class
    )
    public class NYRideshareEnUsResourceBundle extends ResourceBundle {

        @Override
        protected Object handleGetObject(String key) {
            return _resourceBundle.getObject(key);
        }

        @Override
        public Enumeration<String> getKeys() {
            return _resourceBundle.getKeys();
        }

        private final ResourceBundle _resourceBundle = ResourceBundle.getBundle(
            "content.Language_en_US", UTF8Control.INSTANCE);

    }

更新:我从零开始,但我得到了同样的结果。我使用以下方法创建了一个新模块:

$ blade create -t fragment gov.nysdot.user-action-hook --host-bundle-symbolic-name com.liferay.users.admin.web --host-bundle-version 5.0.53

然后,我从源代码(/模块/应用程序/用户-admin/用户-admin-web/src/main/资源/META-INF/资源/user_action.jsp)复制user_action.jsp。

为了测试,我简单地复制了第156行()处的分隔线,以便获得视觉线索。如果超控成功,我会看到两条分隔线。

我使用“grade build”构建并部署到我的服务器。它没有重新启动com。利弗雷。用户。管理web捆绑包,未发生任何更改。

现在,模块创建脚本创建的内容几乎没有变化。

共有1个答案

齐泰
2023-03-14

你的代码/描述让我印象深刻:

  • jsp是模块的jsp,而不是核心jsp。因此,我不期望CustomJspBag,而是遵循module_jsp_override示例
  • 片段捆绑包永远不会是活动的,只会被解析(如OSGi捆绑包生命周期)。因此,它可以传递覆盖主机包文件的文件,但不能传递自己的代码。你提供的是单独的服务,这肯定是不可用的,也不会开始——他们应该生活在其他捆绑包中。将片段包视为被动的。

因此,如果不把你的文件变成一个项目来尝试的话,我认为这就是问题所在。

将捆绑包转换为模块jsp覆盖项目(无java代码,请注意bnd.bnd)。确保JSP仍然是它所需要的:您不能只是将7.0 JSP复制到7.3,并假设这些更改仍然准确地实现了您所需要的。相反,您需要在stock 7.0版本、您的修改和stock 7.3 jsp之间进行三方合并。

 类似资料:
  • 我有以下HTML: 这是,它在悬停时导致图像上的覆盖: 以上所有的工作都很好,我很高兴。 问题是,我在标记中还有一个“阅读更多”按钮,当它悬停在上面时,我也想显示覆盖图像。我想我应该使用jQuery来实现这一点。 我有以下脚本: 脚本工作得很好,但当我将按钮悬停并尝试将图像时,覆盖层将不再出现。 所以总结一下: 当使用类悬停在上时,我使用CSS显示一个覆盖层,它起作用了。我使用jQuery在悬停在

  • 我们最近将VS 2010和.NET 4应用程序升级为VS 2012和.NET 4.5。我们有一个构建脚本来在测试服务器上部署应用程序。我们有两个框-一个是Windows 8和VS 2012(新安装),另一个是Windows 7和VS 2010和VS 2012(新安装)。 从Windows 8运行构建脚本时,box构建脚本运行良好,并将应用程序部署到测试服务器。但从Windows 7 box部署应用

  • 我最近更新了我的项目的gradle版本,从2.14.1到3.0。从那以后,gradle构建每次都失败,出现以下错误: 错误:原因:org.gradle.api.internal.tasks.defaultTaskinputs$TaskinputUnionFileCollection无法强制转换为org.gradle.api.internal.file.Collections.defaultConf

  • 我正在运行《docker compose》中的jenkins,来自图片jenkins/jenkins。升级到Jenkins 2.277.1后,LDAP身份验证停止工作,我无法登录。我收到以下错误: 詹金斯。docker。new\u 1 | 2021 06-04 14:49:31.3110000[id=138]警告o.j.p.p.DiskUsageCollector#collect:无法获取磁盘使用

  • 我不是SSL/TLS专家。但遇到以下情况 我们从一个供应商连接到一个webservice并且“安全策略”是TLSv1,所有的工作都像一个魅力。该供应商将该安全策略升级到TLSV1_2016。 从那时起通信就失败了。当他们重新回滚所有的工作。 这似乎已经足够了。 在AWS上,我发现了以下概述 TLSV1.2支持足以支持SSLv3 TLSV1.0 TLSv1_2016 TLSV1.1_2016 TLS