Fórum

How to read announcements in Liferay 6.x?

thumbnail
Jari Fredriksson, modificado 13 Anos atrás.

How to read announcements in Liferay 6.x?

Junior Member Postagens: 27 Data de Entrada: 14/09/10 Postagens Recentes
I need to get my hands really dirty with Liferay 6.x soon, but my first test drive is just to create a portlet that reads the three latest announcements, and put them to the screen.

I tried to copy jsp code from Liferay announcements portlet, but that way was doomed. My own portlet runs as its own portlet war, and has access only to the portlet-service.jar.

I have tried to look at the JavaDoc, and I see lots of classes, documented that "you must not use this" emoticon

So what classes to use? Anyone done this kind of a simple portlet, and has pointers?

I would love to get the book, but I think it is written for Liferay 5.x?
thumbnail
jelmer kuperus, modificado 13 Anos atrás.

RE: How to read announcements in Liferay 6.x?

Liferay Legend Postagens: 1191 Data de Entrada: 10/03/10 Postagens Recentes
probably something like

LinkedHashMap<long, long[]> scopes = AnnouncementsUtil.getAnnouncementScopes(user.getUserId());


List<announcementsentry> entries = AnnouncementsEntryLocalServiceUtil.getEntries(user.getUserId(), scopes, false, AnnouncementsFlagConstants.NOT_HIDDEN, 0, 3);</announcementsentry></long,>



There are a number of books out there

the packt development books are for 5.x,
the apress book is for 5.x too
liferay in action & portlets in action cover 6.x
the packt book about using liferay covers 6.x
thumbnail
Jari Fredriksson, modificado 13 Anos atrás.

RE: How to read announcements in Liferay 6.x?

Junior Member Postagens: 27 Data de Entrada: 14/09/10 Postagens Recentes
AnnouncementUtil is not available. It does not belong to portal-service.jar

Thanks for the book recommendations!
thumbnail
Jari Fredriksson, modificado 13 Anos atrás.

RE: How to read announcements in Liferay 6.x?

Junior Member Postagens: 27 Data de Entrada: 14/09/10 Postagens Recentes
I tried code:


&lt;%
LinkedHashMap<long, long[]> scopes = null; // AnnouncementsUtil.getAnnouncementScopes(user.getUserId());

List<announcementsentry> results = null;

int flagValue = AnnouncementsFlagConstants.NOT_HIDDEN;

// Get 3 last entries
results = AnnouncementsEntryLocalServiceUtil.getEntries(
        user.getUserId(), scopes, false, flagValue, 0, 3);

for (int i = 0; i &lt; results.size(); i++) {
	AnnouncementsEntry entry = results.get(i);

	String className = StringPool.BLANK;

	if (i == 0) {
		className += " first";
	}

	if ((i + 1) == results.size()) {
		className += " last";
	}
%&gt;
</announcementsentry></long,>


But it somehow causes MySQL syntax error. While I debugged, I saw that it was trying to get HIDDEN announces, no matter that the flagValue is NOT_HIDDEN. And then I took the SQL statement it generated, and tried it in MySQL query browser, it passed OK there. Then I tried the statement in Netbeans via JDBC, if it was a JDBC problem, but no, it works there too.

Then I changed the getEntries() in format


results = AnnouncementsEntryLocalServiceUtil.getAnnouncementsEntries(0, 3);


And that works! But I probably will need a more fine grained getter, to get different types of announcements...