cancel
Showing results for 
Search instead for 
Did you mean: 

Create a bean to be share with different component.

Former Member
0 Kudos

Hi all,

I am now trying to create a bean which will store and share the data which will be used by all custom iView under the same IE session.

How should I code my bean? What type of project should I create for? Service or component? Besides, how can I reference it from different component? (I don't want to place the code of bean everywhere)

Thanks a lot

Sam

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

You should place Your Bean in the HttpSession.

There every iView can get the Bean with the according methodes.

You can get the HttpSession from the componentSession:

session = componentSession.getHttpSession();

But you have to take care in JSP the normal Taglib <jsp:..> won't work. You have to use

<%

...

session = componentSession.getHttpSession();

...

%>

instead.

Try it

Walter

Message was edited by: Walter Mattes

You can also have a look at

which explains the same issue

Former Member
0 Kudos

Hi Walter,

Thanks for your fast response.

However, my problem is at the time when I code the component. As I haven't copy the code of the bean in to my project (the bean is not located in my project folder), so I cannot get a reference to it.

For example: myBean = (MyBean) myProfile.getValue("myBeanName");

My component don't know what is "myBean".

Thanks

Sam

Former Member
0 Kudos

In this case You just have to cpoy Your bean in Your project and make shure that it is in the PAR-file.

Is the problem solved? If yes You can quote the star...

Walter

detlev_beutner
Active Contributor
0 Kudos

Hi Sam, hi Walter,

what Sam wants is to place the bean once into the portal and to reference it from different components and applications, if I got him right.

If such a usage is wanted, it also makes sense to implement it once and not to copy it into different projects, because this would lead to ClassCastExceptions.

Sam, just implement the bean into the public part (src.api) of an application (com.sam.common.bean); this app consists of no components! Deploy this app into the portal and within your different apps using it use SharingReference set to "com.sam.common.bean". Beneath this, for compile time, you have to add the project into the Java Build Path (Project Properties -- Java Build Path -- Projects -- mark "com.sam.common.bean" project).

Hope it helps

Detlev

Former Member
0 Kudos

Dear Sam,

I think Detlev caught Your problem incl. solution 100%.

Cheers Walter

Former Member
0 Kudos

Hi Walter & Detlev,

Thanks a lot for Walter help first, although Detlev got my thinking.

Detlev, I think you've solved my problem. However, I am not clearly understand what should I do. I can find out the last steps "To add the project into the jave build path". But I still don't know how / where to put my bean. What type of project should I create for the bean? and where can I find the "SharingReference" to add?

Sorry that I am just a beginner on Portal development and ask so many question.

Thanks

Sam

Former Member
0 Kudos

Hi Sam,

Yes Detlev is THE portal guru

But I think I can help you meanwhile...

Thats in eclipse. If You don't do this the compilation won't work. Editable in the projectrefences

> find out the last steps "To add the project into the

> jave build path". But I still don't know how / where

> to put my bean.

Next one:

> What type of project should I create

> for the bean?

Just another ordinary Portal project

Next one:

> and where can I find the

> "SharingReference" to add?

in the portalapp.xml of the iView/project which calls the bean (Not where the Bean is located)

e.g.

....

<application-config>

<property name="SharingReference" value="htmlb, <b>insert Your bean class here</b>"/>

</application-config>

Next one:

> Sorry that I am just a beginner on Portal development

> and ask so many question.

no worries but don't forget to quote the answers by clicking at the yellow star...

<b>and greetings to Detlev</b> maybe he finds some more hints for You....

Walter

detlev_beutner
Active Contributor
0 Kudos

Hi Walter, hi Sam,

> Yes Detlev is THE portal guru

Oh nooo... If you would know what I don't - you would be the guru

It's more a mixture of some Java knowledge, portal experience and an attitude to learn and to help every day... Some miles behind being a guru

Sam: The forum has it's own search engine. If questions stay open, a quick search for "SharingReference" will bring you much faster results than asking again. This is just a kind hint for your convenience Don't feel kept from asking, no problem, I just want to show you <i>even faster</i> ways to gain some knowledge.

So far for the moment.

Greetings to both of you

Detlev

Former Member
0 Kudos

Hi Walter & Detlev,

Of course, I remember to give the point for all your help after the problem is solved.

I found this "https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/external libraries" from SDN, and it describe several way to share resource. What I need and Detlev said should be the last method. However, I still cannot use the referenced bean.

The following is what I have done:

1. create my shared bean "PageStatusBean" which located in project "CommonBean" under folder "/public/api/PageStatusBean.java"

2. mark this project as shared (set "SharingAccess=shared" in default.properties)

3. export this project (.par) to my PDK

4. create a project "BrowsePath" which use the shared bean and set the sharing reference (SharingReference=CommonBean) in default.properties

5. selected the "CommonBean" in the Java Build Path of the project "BrowsePath"

However I still can't get a reference from the code in project "BrowsePath" by:

CommonBean myCommonBean = new CommonBean();

Do you know how should I use it in the code?

Thanks

Sam

detlev_beutner
Active Contributor
0 Kudos

Hi Sam,

first of all: You are on EP5. Always give this information! I think a remember now that in some other thread you gave this information, but EP5 for most people here is really just the past... I'm still on EP6 SP2 (quite satisfied, it's stable, patches / hotfixes do work... ), but sometimes feeling like a grandpa, with all these young vegetables around me

So, as you find out by yourself, portalapp.xml is EP6 slang. OK so far.

What <i>cannot</i> work is the line "CommonBean myCommonBean = new CommonBean();". If you want to create an instance of a class, you have to reference the class, not the project... --> PageStatusBean psBean = new PageStatusBean();

If the rest is deployed correctly, it should work...?!

Hope it helps

Detlev

Former Member
0 Kudos

Hi Walter & Detlev,

Yes, I can make it finally. Really thanks a lot. Both of you are guru of me. And I will specify I am using old old version (EP5) next time.

Sorry to Walter that I can only give 10 pt to 1 person (by restriction). So hope you don't mind that I give this 10 pt to Detlev as he figure out my problem first.

Haha, EP6 SP2 is grandpa, then my EP5 is the father of grandpa. Seems upgrade is a must.

Thanks a lot

Sam

Former Member
0 Kudos

> Sorry to Walter that I can only give 10 pt to 1

> person (by restriction). So hope you don't mind that

> I give this 10 pt to Detlev as he figure out my

> problem first.

That's absolutely correct!

Greetings Walter

Answers (0)