cancel
Showing results for 
Search instead for 
Did you mean: 

Singleton Controller

former_member1191927
Participant
0 Kudos

Hi all,

I want to make a component controller class as Singleton, as I want it to have have only instance. Normal procedure for the same is as follows :-

// Singleton with final field

public class Elvis {

public static final Elvis INSTANCE = new Elvis();

private Elvis() {

...

}

... // Remainder omitted

}

But the class of the component controller looks some thing like the following :-

public class SingletonController

{

public SingletonController(IPrivateSingletonController wdThis)

{

this.wdThis = wdThis;

this.wdContext = wdThis.wdGetContext();

this.wdControllerAPI = wdThis.wdGetAPI();

this.wdComponentAPI = wdThis.wdGetAPI().getComponent();

}

.....

....

}

Even if i change the constructor to Private, it automatically changes it back to Public.

Please help me in doing this.

Regards,

Narahari

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

If you are trying to change the standard constructs generated then it will not allow you. Moreover to write your own code you need to write it at the

//@begin others

//@end

Only within the above block you can declare your local variables.

BTW why do u need a singleton controller and what is your scenario?

regards

Ravi

former_member1191927
Participant
0 Kudos

Hi Ravi,

I am developing a DC which will get some data related to all the portal users which i am storing in R/3(with normal RFC call).

Every other application in the portal will access this application to get the data which my application has already got from the back end(to avoid multiple hits to R/3).

I dont want multiple instances to be created for my component. I will the get the data from R/3 and initalize it once and every other application will call this applicaiton to get the same data(with out creating multiple instances).

So I want my component controller class to be Singleton.

Any idea, how to suffice this requirement?

Regards,

Narahari

Former Member
0 Kudos

hi

If your data that is fetched going to be the same for all the users then you are talking about a global context.

So within the portal you can make use of the Portal Service. What you can do is retrieve all the values from your WebDynpro call to RFC.

Then set all the data using setter methods in the Portal Service. The data set in the portal service will be once during the start of the Portal App server and will persist until the app server is shut down.

Let me know if that suffices your requirement. You can find information related to Portal Service in the help site of sap :).

Let me know if that helped.

regards

Ravi

Answers (0)