cancel
Showing results for 
Search instead for 
Did you mean: 

Access session attribute in WD java

Former Member
0 Kudos

Hi,

In our landscape, we have one j2ee application and one Web Dynpro Java application.

J2EE application sets one session attribute(Constant for user session) which needs to be then accessed from WD java application.

Is there any way of achieving this?

Suppose I add one intermediate J2ee application , which reads this session variable and pass it on to WD java application?

But how to call j2ee application from WD java?

Please help.

Regards,

Apurva

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Apurva,

This can be achived by means of, a hidden iView with JavaScript to read the session attributes and portal eventing.

Steps:

1. Create a DC of type Portal Application Standalone and add a JSP page to it. If you already have a DC of this type you can use it to create the JSP.

2. In the JSP page, subscribe an event by using EPCM object i.e. EPCM.subscribeEvent( <nameSpace>, <eventName>, <eventHandler>);  where the eventHandler will be a javascript method.

3. In the javascript method, read the session attribute (using scriptlets) and fire an event again by using EPCM object i.e. EPCM.raiseEvent( <nameSpace>, <eventName>, dataObject), where dataObject will be a javascript variable holding the session attribute's value to be passed to WDJ app.

i.e. write the below lines of code in the JSP page,

<html>

<head>    

     <%String sessionVal =  session.getAttribute(<attrName>);%>

<script>

     function getSessionValue(){

          var dataObject = "<%= sessionVal%>";

          EPCM.raiseEvent("urn:com.test", "JSPEvent", dataObject);

     }

</script>

</head>

<body>

<script>

     EPCM.subscribeEvent("urn:com.test1","WDJEvent", getSessionValue);

</script>

</body>

</html>

 

4. Deploy this DC and create an IView out of this portal component.

5. In the wdinit() method, of the default view of your WDJ app, fire an event (which will be subscribed by the above JSP) and subscribe the event raised by the above JSP. i.e. write the below line of code in init method

WDPortalEventing.subscribe("urn:com.test", "JSPEvent", wdThis.wdGetReactPortalEventingAction());

WDPortalEventing.fire("urn:com.test1", "WDJEvent", " ");

Different namespace and event name should be used for fire and subscribe. The event fired in WDJ should be subscribed in JSP and the event raised in JSP will be subscribed in WDJ.

6. Create an eventHandler named onActionReactPortalEventing() with an input argument of type String, in the WDJ app's default view. This input arg holds the dataObject passed by the javascript EPCM.fire() method.

7.Create a Portal Page and add the IViews of both JSP page and WDJ application to this page and use this page in place of the WDJ app IView. Also uncheck the Visible checkbox of the JSP Iview added in the Portal Page, to make it invisible.

Regards,

Vishweshwara P.K.M.

Former Member
0 Kudos

Hi Vishweshwara ,

Your solution helped me a lot.

However, still there is an issue.

My first application is j2ee application and not portal application so I cant use EPCM event in that.

I tried approach of creating intermediate portal standalone application and

1. passing data from j2ee to portal jsp dynpage using session attributes and then

2. passing data from jsp dynpage to web dynpro using EPCM event

J2ee -> JSP Dynpage -> WD JAVA

Point 2 works fine, but not point 1.

session.getAttribute always gives me null value in jsp dynpage

I guess its because session context is not shared between web applications.

Is there any other way to achieve data passing between j2ee and WD Java?

Regards,

Apurva

Former Member
0 Kudos

Hi Apurva,

As pointed by you, the j2ee app and jsp dynpage doesn't share the session context. Alternative approch will be to pass this attribute as url parameter from j2ee app to the jsp dynpage, whenever you change this session attr. In the jsp page read the url param and store it in its session, which can later be read by the wdj app.

Regards,

Vishweshwara P.K.M.

Answers (1)

Answers (1)

DeeptiChavare
Active Participant
0 Kudos
Former Member
0 Kudos

Hi Deepti,

Thank you.

But, I have already seen this link.

I need to set data from j2ee application and not WD java application.

So I cant use class in WDScopeUtil.

Regards,

Apurva