Foren

Liferay 7 - How to add several css files to a portlet?

thumbnail
Alex Pierce, geändert vor 7 Jahren.

Liferay 7 - How to add several css files to a portlet?

New Member Beiträge: 12 Beitrittsdatum: 30.11.16 Neueste Beiträge
Hello!
I am trying to add several .css files (except main.css) to a new portlet by pasting this in my liferay-portlet.xml.

<liferay-portlet-app>
    <portlet>
        <portlet-name>Catalogue</portlet-name>
        <icon>/icon.png</icon>
        <header-portlet-css>/css/main.css</header-portlet-css>
        <header-portlet-css>/css/search_form.css</header-portlet-css>
        <header-portlet-css>/css/search_results.css</header-portlet-css>
        <footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
    </portlet>
    ...
</liferay-portlet-app>


But only main.css is loaded by the link:

http://test.domain.ru/combo?browserId=firefox&minifierType=&themeId=librarytheme_WAR_librarytheme&languageId=en_US&b=7002&Catalog_WAR_catalogueportlet:%2Fcss%2Fmain.css&Catalog_WAR_catalogueportlet:%2Fcss%2Fsearch_form.css&Catalog_WAR_catalogueportlet:%2Fcss%2Fsearch_results.css&com_liferay_product_navigation_product_menu_web_portlet_ProductMenuPortlet:%2Fcss%2Fmain.css&t=1484135256000

How cat I add more than one .css to a portlet?
thumbnail
Andrew Jardine, geändert vor 7 Jahren.

RE: Liferay 7 - How to add several css files to a portlet? (Antwort)

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
I thought in Liferay 7 you were supposed to use the annotations on the portlet class instead of the XML files? In which case, according to the mapping page (https://dev.liferay.com/develop/reference/-/knowledge_base/7-0/portlet-descriptor-to-osgi-service-property-map#two) the property is

com.liferay.portlet.header-portlet-css=<string></string>


.. of which you can have multiple. Can you try using that method?
thumbnail
Alex Pierce, geändert vor 7 Jahren.

RE: Liferay 7 - How to add several css files to a portlet?

New Member Beiträge: 12 Beitrittsdatum: 30.11.16 Neueste Beiträge
Thanks for the reply, Andrew!
I cat'n find more information about how to use annotations (where to place it?). May you give me a short example or a link, please?
I found this:
https://web.liferay.com/web/user.26526/blog/-/blogs/liferay-7-development-part-5
...and does this mean that I have to create a portlet class? Now I use default MVCPortlet in my simple test project (which contains only one jsp).
As far as I understand if I build WAR file, I should use XML, and annotations is for OSGI modules.
thumbnail
Andrew Jardine, geändert vor 7 Jahren.

RE: Liferay 7 - How to add several css files to a portlet?

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
Hi Alex,

Personally, I always create a portlet class for my portlet, even if it is just a simple view. I'm sure you, like everyone else, has come across the heated debates on sites like stack overflow about that correctness of having JSP scriptlets in a view emoticon. At the very least, you could use your custom portlet class to pass attributes to the jsp so that you can use JSTL, but of you don't want to do that you can go as back as just

public class Test extends MVCPortlet {
}


and call it a day emoticon. You might not have to, but I have always encouraged my clients to define their own class regardless. With this in ind, all the stuff I have done with 7 has been based on using annotations so I'm not sure if the old liferay-portlet.xml style still works the same.

David has written (and continues to write) some awesome blog posts on how to do things in 7 so his stuff is always worth a cup of coffee and a read. You could also use some of the guides that Liferay have published. They're much simpler, but might be all you need for now. For example: https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/liferay-mvc-portlet
thumbnail
Alex Pierce, geändert vor 7 Jahren.

RE: Liferay 7 - How to add several css files to a portlet?

New Member Beiträge: 12 Beitrittsdatum: 30.11.16 Neueste Beiträge
Thank you, Andrew!
I'll try this way.
thumbnail
Alex Pierce, geändert vor 7 Jahren.

RE: Liferay 7 - How to add several css files to a portlet?

New Member Beiträge: 12 Beitrittsdatum: 30.11.16 Neueste Beiträge
You were right. Annotations works emoticon