cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatically getting iView Properties

former_member610333
Participant
0 Kudos

Alright.. I am about to throw my laptop out of the window.. So before I do that I thought I would post my issue here.

Basically, I am trying to get some properties of an iView. Should be pretty basic.. Here is a code snipet..

Hashtable env = new Hashtable();

env.put(Context.INITIAL_CONTEXT_FACTORY,IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);

env.put(Context.SECURITY_PRINCIPAL,request.getUser());

env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sapportals.portal.pcd.gl.PcdInitialContextFactory");

env.put("com.sap.portal.jndi.requested_aspect","com.sap.portal.pcd.gl.PersistencyAspect");

InitialContext iCtx = null;

iCtx = new InitialContext(env);

IiView result =(IiView)iCtx.lookup("portal_content/Folder/iView");

What ALWAYS happens is that I get a NULLPOINTEREXCEPTION at the 'IiView result=IiView result =(IiView)iCtx.lookup("portal_content/Folder/iView");' line..

Any ideas.. is it something to do with my content configuration??

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Craig,

Look in to this technical article.This will solve your problem.

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/6112ecb7-0a01-0010-ef90-941...

I think you have not updated your portalapp.xml.

Let me know if you need more info.

Regards,

Karthick Eswaran

former_member610333
Participant
0 Kudos

Nope.. Still getting the nullpointer error..

Former Member
0 Kudos

Craig,

I think you are passing the wrong iView id.

Check it out and let me know.

Karthick

Former Member
0 Kudos

Hi Craig,

don't panic. Here is your solution:

IPortalComponentRequest request;

IPortalComponentProfile profile = request.getComponentContext().getProfile();

String prop = profile.getProperty("propertyname");

Mate, it was a pleasure

Steffen

Former Member
0 Kudos

Craig,

Have you followed the same code as i've given in the article.I tested it and its working fine for me.

Have you updated you portalapp?

Regards,

Karthick

former_member610333
Participant
0 Kudos

I need to get the properties of a DIFFERENT iView then the one that is hosting the servlet.

Former Member
0 Kudos

Craig,

Try this line of code instead of your code.

IiView result =(IiView)iCtx.lookup("pcd:portal_content/Folder/iView");

Karthick

former_member610333
Participant
0 Kudos

As wierd as it sounds. If I modify the PCD PATH to an invalid value ( ie. doesn't actually go to anything ). I do get a 'Child Not Found Error'

Can you post the ENTIRE code that you used? Just to make sure..

I will start my project from stratch..

Former Member
0 Kudos

Should be no problem at all. I am using this:

getComponentContext(String urn) [from javadocs]

IPortalComponentProfile profile = componentRequest.getComponentContext("urn").getProfile();

Couldn't look it up that fast in my code.

Steffen

Former Member
0 Kudos

Craig,

I am not sure for which purpose you need this, but looks promising for me. I have just tested it quickly. This might only regard to master iViews.

IPortalComponentProfile otherProfile = request.getComponentContext("com.sweetlets.pct.test.Profile").getProfile();

Use the PAR file name together with the component name as the urn string. Such as "com.sweetlets.pct.test" + "." + "Profile". Use PortalAnywhere.Go to see all available master iViews.

I hope that helps.

former_member610333
Participant
0 Kudos

Well. I solved it.. Not really sure how.. But when I put the code into its own Try-Catch.. It magically worked..

String id = "pcd:portal_content/Folder/iView";

InitialContext iCtx = null;

try {

iCtx = new InitialContext(env);

IiView result = (IiView) iCtx.lookup(id);

response.write(result.getAttribute("com.sap.portal.pcm.Title",request.getLocale()));

} catch (Exception e) {

response.write(e.getMessage());

}

Hmm..

Former Member
0 Kudos

Craig,

Thats good.So now you dont need to throw your laptop out of window.

Karthick

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Craig,

Try adding pcd: while doing the context lookup

pcd:portal_content/Folder/iView

Regards,

Piyush

ps: please mark useful answers.