0

I'm trying to fetch properties like first name and last name from profile repository, displaying it in jsp using droplet. Below is my sample code: 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>

I've tried displaying profileId in jsp it is working. But when i passed it to droplet it is showing 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

If anyone knows what is the issue please help me.

Thanks in advance

bated
  • 960
  • 2
  • 15
  • 29
Ramya jois
  • 29
  • 5
  • The issue is at line 26 and as we only have an extract of the code I cannot tell you where that is in the above. At a guess lProfileId is null ... – bated Jul 22 '16 at 14:57
  • yes, in droplet profileId is coming null. I tried displaying profileId in jsp without droplet, it's working but value is not passing into droplet – Ramya jois Jul 23 '16 at 06:14
  • Can you confirm if the Profile is transient? This can be obtained by Profile.isTransient in the JSP. – bated Jul 25 '16 at 15:17
  • 1. Your droplet should not be globally scoped (scope=global). Droplets in my experience are usually page scoped, which is the default scope if you do not provide a $scope property. This prevents having to worry about multi-thread issues. 2. Your scope property should actually be $scope, although I don't think that this is the issue 3. There is a type; ProfileAdaptarRepository should be ProfileAdapterRepository 4. You can simplify to – Matt Sidesinger Jul 25 '16 at 15:46
  • 1
    @MattSidesinger droplets should generally be Globally scoped with FormHandlers being request scoped (sometimes session scoped). – radimpe Jul 26 '16 at 09:55
  • @Ramyajois Do you have accessor methods for your `mProfileRepository` and as @MattSidesinger pointed out, you mistyped ProfileAdaptarRepository. – radimpe Jul 26 '16 at 09:57
  • @MattSidesinger yes i did a spelling mistake. It should be ProfileAdapterRepository. Now it's working fine. Thanks – Ramya jois Jul 27 '16 at 04:43

1 Answers1

2

it looks like problem is here:

profileRepository=/atg/userProfiling/ProfileAdaptarRepository

Nucleus can't find this component:

  1. "userprofiling" should be in lower case.
  2. ProfileAdaptarRepository -> ProfileAdapterRepository