Daniel Storch
Daniel Storch

Reputation: 989

Portlet event send array of objects

We have multiple projects with multiple portlets and need to send an array of objects between them.

Our situation:

One of the porlets is like a "Master-portlet", it will be responsible for all the REST-calls and consume json-data and parse it to Java-Objects. All the other portlets will receive an array of objects and show them to the user.

Our thoughts and solution:

We wanted to implement this by sending arrays of objects trough events. One of the "smaller" portlets will send an event to the "Master-portlet" and the "Master-portlet" will then answer with a new event and send the right array of objects back.

Our problem:

We dont know how to send arrays of objects trough events. Is this even possible? Also we are not sure if this is the right way to solve this. Are events ment to send a bigger amount of data? Is there a better solution for our case? Maybe it would be better to implement a database and all the portlets get the information from there?

Upvotes: 2

Views: 116

Answers (1)

Olaf Kock
Olaf Kock

Reputation: 48067

Consider portlet events (and portlets) the UI layer of your application. Based on this, judge if the amount of data that you send back and forth makes sense or not. Also, if you closely couple the portlets, you're just hiding the fact that they can only function together - at least a questionable idea. You rather want them to react to common circumstances (events), but not rely on a specific source of events (master portlet) being available.

That being said: The more complex the data is that you send as payload of a JSR-286 event, the easier you run into classloading problems in cases where your portlets are in different webapplications. If you restrict yourself to Java native types (e.g. String, Map, etc) you will omit problems with the classloader.

Typically you want to communicate changes to the current context (e.g. new "current customer" selected - and an identifier) but not all of the particular data (e.g. the new customer's name and order history). The rest of the data typically comes through the business layer anyway.

That's not to say that you absolutely must not couple your portlets - just that my preference is to rather have them very loosely coupled, so that I can add individual small portlets that replace those that I thought of yesterday.

If you have some time, I've covered a bit of this in a webinar last year, I hope that this adds some clarification where I was too vague in this quick answer.

Upvotes: 2

Related Questions