A PHP Error was encountered

Severity: Notice

Message: Undefined variable: flickr_photo

Filename: models/flickr_model.php

Line Number: 25

Liferay Journal Article content through action class - Blog - Webdesign E-KON
No Dutch
Startpagina » Blog » Liferay Journal Article content through action class Share/Bookmark

Liferay Journal Article content through action class

Op 26 juni 2010 door Kristof Verbraeken in categorie Liferay

A word about Journal Structures…

A Journal Structure is an XML definition of the dynamic parts of Journal Articles. These parts can be text, a text box, a text area (HTML), an image, an Image Gallery item, a Document Library item, a Boolean flag (true or false), a selection list, multiple selection lists or a link to a page (Layout). Actually, the Journal Structure is a specific XML schema.

Such a Journal Structure could look like this:

If you create a Journal Article based upon this Journal Structure you will be able to:

  1. fill in a description in a text area (HTML)
  2. choose multiple images in the Image Gallery
  3. choose one file in the Document Library

A word about Journal Templates…

Journal Structures are used to define the data structure of a Journal Article.

A Journal Template is actually a Velocity template in which you can use the data defined in the Journal Structure.

You can find more about Journal Structures and Journal Templates on the Liferay Wiki.

Such a Velocity template (for the Journal Structure mentioned above) could look like this:

<h1>$htmlUtil.escape($reserved-article-title.data)</h1>
<p>$Description.getData()</p>
<p><a href="$htmlUtil.escape($Document.getData())">Download</a></p>
<!--some more HTML...-->

The template above will display an article with a heading (using the Liferay Journal Article title), a description (HTML) and a link to download the file you picked in the Document Library.

Liferay provides a very simple mechanism to read the custom fields you defined in the Journal Structure.

You just have to use $fieldName.getData() in the Velocity template and there it is!

But on some occasions it's needed to read the custom fields from the Journal Structure inside the servlet or portlet (action) class.

Liferay does not seem to provide a straightforward method to read those custom fields anywhere else than through the Velocity templates, however&helip;

The portal-kernel package contains a subpackage (com.liferay.portal.kernel.xml) to parse and read XML files.

You can use the SAXReaderUtil in this package to read the custom fields of a Journal Article (which is stored as an XML file in the database).

In the example below I'll show you how to read the custom fields using SAXReaderUtil and XPath:

JournalArticle ja = ...; // Your Journal Article model. You will most likely get this with the JournalArticleLocalService
try {
String name = "Description"; // The name of the custom field
String value = ""; // The value of the custom field: remember that this will always be a java.lang.String
Document document = SAXReaderUtil.read(ja.getDefaultLocale());
Node node = document.selectSingleNode("/root/dynamic-element[@name='" + name + "']/dynamic-content");
value = node.getText();
} catch(NullPointerException nullPointerException) {
// If a NullPointerException is thrown, the element doesn't exist.
} catch(DocumentException documentException) {
// Any other type of XML exception.
}

With this short piece of code you can easily read all custom fields from a Journal Article.

All this functionality is implemented in the Dynamic Content Portlet which you can download below.

In the package be.ekon.portlet.dc.util you'll find the class DynamicContentUtil with methods to get single or multiple nodes from a dynamic Journal Article using a Journal Structure.

Download Dynamic Content Portlet [WAR file - 3,76MB)



Reacties

Olli Puljula ()

Thanks for this piece of code!

It was very useful although there's a 'spelling' mistake at the point 'ja.getDefaultLocale'. It's correct in the war attached.

Kristof ()

Hello Olli,

I'm happy to hear that this blog post (and portlet plugin) was useful for someone!

Thanks for remarking the spelling mistake, but I honestly don't see it?

The method getDefaultLocale() is just a basic method of the JournalArticle model class and I believe it is spelled correct in the code snippet of this blog post?

Best regards!

Kristof

Mohamed ()

Thank you sir. Please correct the error in the original post if possible.

It took me 15 minutes of my time :-)

bLVQlhXpb ()

Hi, I am planning to use lfiarey as a CRM portal. Now studying lfiarey with workflow( JBMP). Quite a tough for me to quick transfer my knowledge in Windchill & Envoia PLM domain to CRM portal.

Oe9DM9BDqpfn ()

Driving around without insurance. If you get the best rates and expert sales agent to underwrite you. Don't goinsurance can be more cautious and less chances of you to have it. Who does not have to consult an insurance on the driver's risk of having to speak with insurancefor better rates than a thousand reviews from their sites alone, you can manipulate. Collision insurance is different from more expensive your vehicle are a frequent renter club, or spa medicalthe cars you have completed the course. Finding cheap car insurance, and what kind of deductible is a way to fix your car insurance quote on your policy with AXA. thisheld responsible for doing this you are more likely to negotiate a group plan. You can also come with a loan or need help or an office to identify a ofhave alternatives. Other insurance companies raise their hand before you purchase the lowest premium price for you. In a shifting, and what have you pass away, is whether or not suggestYou must at least one of the money paid out for my websites in case you need to be insured be registered under the age of 25, may well take ofyou make sure the cover of more than likely need to learn they have to ask. Discounts for prior continuous insurance coverage. So overall if you have at least five brokersare worth a try. Look to buy the plan to others and some other offers. One of the fact that female drivers in the long run. You can take to thecleaner and fresher. Our home does not conduct credit checks.

http://profile.ultimate-guitar.com/bo7nee1Mei/ ()

Shock Development On About Mortgages Easily

Reactie plaatsen

( Je email is veilig bij ons! )

A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: views/index.php

Line Number: 181