Can Liferay portlets get parameters? - java

I am having trouble understanding the concept of portlets in a CMS.
Let's say I write a weather portlet to display current temperature. I build it, package it in a war, deploy the war in Liferay.
Now I created a page, and I want to create 2 instances of the portlet I wrote. I want to display the weather in Seattle and the weather in Miami.
Can I do this? How do I pass the portlet a parameter to tell it which city to display?

Portlet has so-called EDIT-mode. You can implement EDIT mode to show the form to choose which city you want to show the temperature for. Save this to portlet preferences. And when you will render the portlet in normal(VIEW) mode, look at the preferences for the city.
http://portals.apache.org/pluto/portlet-api/apidocs/javax/portlet/PortletPreferences.html
http://onjava.com/pub/a/onjava/2006/02/01/what-is-a-portlet-2.html?page=2

Another option is PortletConfig - which is generally configured in portlet.xml and is similar to Servlet init params. Preferences is probably your best bet.
If you're working in Liferay in particular, LR's model-builder infrastructure will get you much of this functionality including editing quick/cheap at the cost of cross-container portability. On the plus side it will integrate well with LR's (limited) RBAC which tends to be important in distributed content authoring environments

Related

Addapt bootstrap theme for web application

So I was trying to make web app. And because I'm not very good with frontend I decided to buy bootstrap theme. When I inspected it, I realised it's just static theme. I can't use it for my web app with Java backend and REST end points. It's like I just bought good wireframes. I need REST functions implemented. Now first thing that came to my mind is to learn Angular and create those pages by myself, but that is time consuming. What is the fastest way to make those pages usable.
I will try to be the clearest I can be.
The theme you purchaised is just plain html with css (Bootstrap)
What you have to do now is:
define a new frontend project with AngularJS, maybe using some Yeoman generator
add Bootstrap as Bower dependency
define all your AngularJS views (or templates, or partials)
copy the theme html fragments into your views
customized it using an additional css file (i.e. custom.css) that overrides the theme original ones
use all the theme components to design your specific UI.
Also keep in mind that purchaising an html/css theme does not mean to buy a frontend skeleton application. It's just a way to accelerate the UX/UI design and development of a complete new frontend application from scratch and you must have some kind of web design/web development basic skills in order to use it properly.
Hope this could help you

How to distinguish between staging and live on a JSP portlet?

I’m beginning to make a JSP form portlet and I have 2 doubts.
1)
I’ve made a structure and the respective template, and created several web contents with this.
Now I’m creating a JSP portlet to display the web contents, I’m getting all the contents with the JournalArticleLocalServiceUtil.getStructureArticles(), but whenever I add more content, it automatically appears in Live and Staging instead of only appearing in staging.
How can I fix this?
2)
Does Liferay sanitizes all the inputs automatically to prevent SQL injections and XSS attacks?
Thank you.
1) if you're always using the same groupId, you'll always get the same content: The Live and Staging Sites have different group Ids. You'll typically use the "current" groupId, which means the staging one when in staging and the live one when in live.
2) Servicebuilder typically is safe from SQL-injections unless you construct your SQL queries manually. As there are some legitimate uses of scripting content, you'll have to determine the level of escaping user-generated content for yourself, Liferay provides the class HtmlUtil with various escaping methods. Pick the ones you need. For general use, e.g. to sanitize WebContent, Blogs etc., you might want to deploy the AntiSamy plugin from Liferay's Marketplace

Adding content to Liferay via API

I am starting using Liferay Portal and I have two basic needs which I would like to achieve with Liferay.
Is there a posibility to add content to CMS through API level? I would like to insert some data "from code".
More important. How to achieve such situation that for every created user there will be its own homepage generated with some predefined template elements on it?
I have tried to Google something so far, but I did not find it helpful. Maybe some keywords?
After some analysis of documentation devoted to services and ServiceBuilder I realized that it is not what I want.
Let me show an example based on Websphere.
In Websphere we have bunch of EJB components available to perform some actions, exchange information with portal, easy to use. Isn't there any similar mechanism in Liferay not involving web services?
My recommendation for this kind of question is to take a look at the sevencogs-hook sourcecode. The structure of this hook is basically just a long script that runs once, setting up a complete demo site with users, sites, pages, content etc. The code runs once (after the first deployment) and then never again. There are no (obvious) conditionals, no context to understand etc.
You can basically just step through everything and - in that process - understand how content (and pages, images, blog posts, etc.) are created and positioned on pages in Liferay.
This hook accesses the Java API, a very similar API is available through Webservices. Basically all of Liferay's portlets also use the same API to do their business.
Edit: Additional information to keep this answer valuable/current: Sevencogs is discontinued, but still available in old releases (source & binary). The API has slightly changed, so compiling/running it will need a bit of work. James Falkner has blogged about the leftovers and lessons learnt - those snippets are extracted from sevencogs and contain the relevant code pieces to work with the API.
Looking at this page from the documentation: It smells like a SOAP interface (they mention some sort of document uploader service and I've read axis).
You'll find some url examples that should give a list of available webservices.
For number 1, you can use the one of the:
JournalArticleLocalServiceUtil.addArticle()
methods to programmatically add Liferay Web Content from a portlet. If you download the Liferay Portal Source you can see the structure of these methods.
For number 2, can create page templates with preconfigured portlets on them (through the Plugins-SDK), and then use the API to programmatically create the pages using one of the:
LayoutLocalServiceUtil.addLayout()
methods.
If you have any more speific questions about these comment back, and I hope this helps!

Liferay Customization of Management Pages

I'd like to understand how can I customize different pages in the Liferay management screens. For example:
I'd like to add a few fields to images that are being uploaded to the Image Gallery
I'd like to add new field types that I can use when creating new structures (for example, add a "phone number" field type so I can add it to new structures I'd like to create).
Another example would be to customize the Web Content search page and add/remove fields and customize it's look & feel.
Any pointers would be helpful, as I've read most of the stuff about developing for Liferay but could figure our where to start with doing stuff like that (without changing core Liferay files)
I don't think 2) can be done without changing Liferay itself (e.g. patching the source code).
You can customize all built-in JSP pages using so called "JSP Hooks". I have done that to customize the pages for the user administration (mainly removing confusing fields from them).
The basic idea is to provide a modified version of the core JSP page. Upon deploying the hook, Liferay will replace the built-in page with the customized version. When the hook is undeployed, Liferay activates the original page again.
The following pages should have enough information to get you started:
http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Portal+Hook+Plugins
http://www.liferay.com/community/wiki/-/wiki/1071674/Custom+Fields+and+JSP+Hooks
http://wikis.sun.com/display/websynergy/Customizing+JSPs+using+hooks+plugin
Make sure you search in the Liferay forum as well.

How to make a nice jsp GUI without using HTML tags?

I'm new to servlets and JSP and I'm trying to discover forms, and how to make my own web form. I know HTML but and I see examples for using HTML tags in the servlets, but isn't there a more higher level way to just say "Make a form here, make a table there" without getting my hands dirty with HTML tags?
I want to build a war file and drop it on my jboss/tomcat server for testing. Then when its ready to go, I want to be able to distribute that war file and for it to be plug and play.
The end goal is to have a web site with some interaction (dropdowns, text fields) and some graphs that are drawn based on the user inputs.
Sorry so vague, I need some direction in the Java GUI department.
Check out Java Server Faces. (http://java.sun.com/javaee/javaserverfaces/)
ps, I just noticed Wikipedia has a nice list of web-application frameworks for the various languages/environments.
One of the most difficult things to do absolutely right in a browser, is form submittal. That is, form submittal with error recovery.
Hence, it is a natural sweet spot for a helping library and many exist. I would suggest you look into JavaServer Faces where 2.0 with facelets is very powerful and default in Java EE6, but right now only ships with Glassfish 3.
If this is for learning, I would suggest using Glassfish instead of Tomcat, so you get a prepackaged learning environment.
You may be interested in the echo framework.
Try Google Web Toolkit
code.google.com/webtoolkit/

Categories