在ATG中从存储库中获取属性时获取NullPointerException

时间:2016-07-22 09:57:31

标签: atg oracle-commerce atg-droplet

我尝试从配置文件存储库中获取名字和姓氏等属性,并使用droplet在jsp中显示它。以下是我的示例代码: SampleDroplet.java

public class SampleDroplet extends DynamoServlet {

private Repository mProfileRepository;
@Override
public void service(DynamoHttpServletRequest pReq, DynamoHttpServletResponse pRes)
        throws ServletException, IOException {

    String lFirstName = null;
    String lLastName = null;
    String lProfileId = pReq.getParameter("profileId");     
    try {
        RepositoryItem lItem = getProfileRepository().getItem(lProfileId, "user");
        lFirstName = (String) lItem.getPropertyValue("firstName");
        lLastName = (String) lItem.getPropertyValue("lastName");
    } catch (RepositoryException e) {
        e.printStackTrace();
    }
    pReq.setParameter("firstName", lFirstName);
    pReq.setParameter("lastName", lLastName);
    pReq.serviceParameter("output", pReq, pRes);
}

SampleDroplet.properties

$class=com.tap.droplet.SampleDroplet
scope=global
profileRepository=/atg/userProfiling/ProfileAdaptarRepository

SampleDroplet.jsp

<dsp:page>
<dsp:importbean bean="/atg/userprofiling/Profile" var="profile" />
<dsp:importbean bean="/com/tap/droplet/SampleDroplet" />
<dsp:getvalueof var="profileId" bean="Profile.id"/>
    <dsp:droplet name="SampleDroplet">
        <dsp:param name="profileId" value="${profileId}" />
        <dsp:oparam name="output">
            Profile's First Name : <dsp:valueof param="firstName"/>
                      Last Name : <dsp:valueof param="lastName"/>
        </dsp:oparam>
    </dsp:droplet>
</dsp:page>

我尝试在jsp中显示profileId它正在运行。但是当我将它传递给Droplet时,它显示出NullPointerException

java.lang.NullPointerException
at com.tap.droplet.SampleDroplet.service(SampleDroplet.java:26)
at atg.servlet.DynamoServlet.service(DynamoServlet.java:152)
at atg.taglib.dspjsp.DropletTag.invokeServlet(DropletTag.java:420)
at atg.taglib.dspjsp.DropletTag.doAfterBody(DropletTag.java:705)
at     jsp_servlet._test._droplet.__sampledroplet._jsp__tag18(__sampledroplet.java:874)
Truncated. see log file for complete stacktrace

如果有人知道这是什么问题,请帮助我。

提前致谢

1 个答案:

答案 0 :(得分:2)

看起来问题就在这里:

profileRepository=/atg/userProfiling/ProfileAdaptarRepository

Nucleus找不到这个组件:

  1. “userprofiling”应为小写。
  2. ProfileAdaptarRepository - &gt; ProfileAdapterRepository