【问题标题】:Querying user profile repository ATG查询用户配置文件存储库 ATG
【发布时间】:2017-03-08 13:23:39
【问题描述】:

我在 ATG 的配置文件之上添加了一些自定义属性。当我想在 jsp 中读取配置文件值时,我只是导入 ATG 配置文件,然后将属性作为 profile.name 访问。

我面临一种情况,我需要为一种类型的用户返回 profile.lastName,为其他类型的用户返回 profile.firstName。这是基于说 profile.userType 属性。

是否可以在存储库中添加 userType 检查,以便在我读取 profile.name 时它应该返回 firstName 或 lastName。

由于在很多地方都提到了名称(1000),我无法在任何地方添加用户类型检查并相应地显示名称。所以如果可能的话,我们可以在 repo 中处理这个问题。

【问题讨论】:

    标签: repository user-profile atg


    【解决方案1】:

    是的,你可以。只需使用 RepositoryPropertyDescriptor。我匆忙拼凑了以下版本(未经测试,但应该足以让您继续使用):

    import atg.repository.RepositoryItem;
    import atg.repository.RepositoryItemImpl;
    import atg.repository.RepositoryPropertyDescriptor;
    
    public class AcmeRealUserName extends RepositoryPropertyDescriptor{
    
        @Override
        public Object getPropertyValue(RepositoryItemImpl profile, Object pValue) {
    
    
            String userType = (String) profile.getPropertyValue("userType");
            String lastName = (String) profile.getPropertyValue("lastName");
            String firstName = (String) profile.getPropertyValue("firstName");      
    
            if ("firstNameUser".equals(userType)) {
                return firstName;
            } else {
                return lastName;
            }
        }
    
        @Override
        public void setValue(String pAttributeName, Object pValue) {
            //Probably Do Nothing since this is a derived property
        }
    
        /**
         * A class specific logDebug method to output log messages. Unfortunately
         * using System.out as the mechanism.
         * 
         * @param pMessage
         */
        protected void logDebug(String pMessage) {
            System.out.println("### DEBUG(:" + getClass().getName() + getName() + ")" + pMessage);
        }
    }
    

    然后,您可以在 userprofiling.xml 中引用这个新属性,如下所示:

    <property name="name" property-type="com.acme.propertydescriptor.AcmeRealUserName" item-type="string" writable="false" readable="true" />
    

    【讨论】:

      猜你喜欢
      • 2012-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-05
      • 1970-01-01
      • 1970-01-01
      • 2018-03-17
      • 2012-11-14
      相关资源
      最近更新 更多