0
votes

I'am using JBoss 7.1.1 with Liferay 6.2GA. I need a portlet instance on each page. The constructor of the MVCPortlet class is only called after deploying the portlet, so it's just instantiate one time (after deploying).

I tried

<instanceable>true</instanceable>

in liferay-portlet.xml but this didn't changed anything.

How can I create a new instance of my portlet when I drag the portlet out of the 'add application' menu to place it on a, just for this instance, created page?

In order to control the number of instances, I did:

public class Controller extends MVCPortlet {
private final static Logger log = Logger.getLogger("Controller");
private int instance = 0;
public Controller() {
        instance++;
        log.info("instance: " + instance);
    }
}
1
Why do you need to call a constructor on each add?Aleksandr M
I have built the project in the idea that it would be instantiated for each page. I have a special application, in which each user has exactly one page, but the user isn't logged in.jcomouth

1 Answers

2
votes

It's not your business to instantiate portlet classes. The portal will do so for you. A portlet has no state in the class: As soon as you have a member variable in your portlet, keeping any personal state, that's a potential problem.

The portal typically will only have a single object for portlets (just like with servlets). All of the state that you'd like to add to the portlet itself goes into the request and response objects that are handled during the various lifecycle methods.

Whatever you're attempting that does rely on multiple (java) objects: It's wrong. You need to change your architecture