Foros de discusión

How to create a really simple form portlet

Alessandro Violante, modificado hace 11 años.

How to create a really simple form portlet

New Member Mensajes: 9 Fecha de incorporación: 25/10/12 Mensajes recientes
Hi to all, i'm newbie to portlet development and newbie to Liferay in general,

I want to create a new portlet which is a form in which people can register to i.e. a newsletter, then a username and a password specified by users go into a database, and then users can log and obtain some privileges.

It will seem very simple but i can't understand well what i have to do, i've made the same thing with a servlet but i'm thinking that is so more difficult here.

Now, i've only made a form in the view.jsp file, in which action points to <portlet:actionURL/> and inputs looks like <portlet:namespace />name i.e., and i have a connection-pool.properties file with my credentials. I have a class called MVCPortlet that now is empty.

I've read on the book Liferay in action some explanation but 1) I've found the database part too expert-oriented for me at this time and, for the first part of portlet developing chapter, i've found that i can't deploy a simple portlet if i extend with the GeneralPortlet class, but i don't know why.

Which are the steps that i have to make? Try to be more precise you can because it's all new for me emoticon

1) The view
2) The Java class
3) The methods (ActionRequest / ActionResponse ok but how to use them?)

I'm stopped at the servlet methods doGet / doPost that were a lot easier emoticon

Thanks!

Alex
thumbnail
Juan Gonzalez P, modificado hace 11 años.

RE: How to create a really simple form portlet

Liferay Legend Mensajes: 3089 Fecha de incorporación: 28/10/08 Mensajes recientes
Did you try XMLPortletFactory?

http://www.xmlportletfactory.org/

Only have to configure a simple XML, and everything is built for you.
Alessandro Violante, modificado hace 11 años.

RE: How to create a really simple form portlet

New Member Mensajes: 9 Fecha de incorporación: 25/10/12 Mensajes recientes
Mh no but "the problem" is that i have to learn it, not "just" to use it emoticon
thumbnail
Juan Gonzalez P, modificado hace 11 años.

RE: How to create a really simple form portlet

Liferay Legend Mensajes: 3089 Fecha de incorporación: 28/10/08 Mensajes recientes
Alessandro Violante:
Mh no but "the problem" is that i have to learn it, not "just" to use it emoticon


Well, you can choose learn an xml (which will build all the code for you) or learn how portlet works.

Having all source generated will let you learn afterwards, but at least you have a solid base of a working app, instead of nothing.
Alessandro Violante, modificado hace 11 años.

RE: How to create a really simple form portlet

New Member Mensajes: 9 Fecha de incorporación: 25/10/12 Mensajes recientes
I've downloaded it but how i have to use it? emoticon

Sorry
thumbnail
Juan Gonzalez P, modificado hace 11 años.

RE: How to create a really simple form portlet

Liferay Legend Mensajes: 3089 Fecha de incorporación: 28/10/08 Mensajes recientes
You have two great tutorials in YouTube channel:

https://www.youtube.com/user/XMLPortletFactory
Alessandro Violante, modificado hace 11 años.

RE: How to create a really simple form portlet

New Member Mensajes: 9 Fecha de incorporación: 25/10/12 Mensajes recientes
Thanks, i'll study this and let you know emoticon
Alessandro Violante, modificado hace 11 años.

RE: How to create a really simple form portlet

New Member Mensajes: 9 Fecha de incorporación: 25/10/12 Mensajes recientes
Mmh i've understood nothing from the videos, so i've took another way.

My main problem is this: i cant' go out of this.

Here's my code

view.jsp

<%
/**
* Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
%>

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portlet:defineObjects />

<portlet:actionURL var="Invio" name="Invio"/>

<form method="post" action="<%=Invio%>">
<input type="text" name="username"/>
<input type="password" name="password"/>
<input type="submit" value="Invia"/>
</form>

connessione.java (connection)

package com.liferay.util.bridges.mvc;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;

public class Connessione extends MVCPortlet {

public static Connection con() {
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
System.out.println("Errore");
}

// APRI CONNESSIONE

try {
conn = DriverManager.getConnection("jdbc:mysql://localhost/db_alex","root","25071984");
System.out.println("Connessione effettuata");
return conn;
} catch (SQLException ex) {
System.out.println("SQlException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
return null;
}
}

public void Invio (ActionRequest actionRequest, ActionResponse actionResponse)
throws PortletException, IOException {

String username = actionRequest.getParameter("username");
String password = actionRequest.getParameter("password");

Connection conn = null;

conn = Connessione.con();

try {
Statement st = conn.createStatement();
st.executeUpdate("INSERT INTO contacts (username,password) values ('"+username+"','"+password+"')");
System.out.println("Dati inseriti correttamente");

} catch (Exception e) {
System.out.println("Errore di inserimento");
}
}
}

Inviodati.java

package com.liferay.util.bridges.mvc;

import java.io.IOException;
import java.sql.Connection;
import java.sql.Statement;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;

public class Inviodati extends MVCPortlet {

public void Invio (ActionRequest actionRequest, ActionResponse actionResponse)
throws PortletException, IOException {

String username = actionRequest.getParameter("username");
String password = actionRequest.getParameter("password");

Connection conn = null;

conn = Connessione.con();

try {
Statement st = conn.createStatement();
st.executeUpdate("INSERT INTO contacts (username,password) values ('"+username+"','"+password+"')");
System.out.println("Dati inseriti correttamente");

} catch (Exception e) {
System.out.println("Errore di inserimento");
}
}
}

Where is the problem?

When i install the portlet consolle says that is available, and it is, but in the installation manager it is unknown and yellow, and if i use it, it says red error "Portlet is unavailable to use"

What to do?
thumbnail
Juan Gonzalez P, modificado hace 11 años.

RE: How to create a really simple form portlet

Liferay Legend Mensajes: 3089 Fecha de incorporación: 28/10/08 Mensajes recientes
So at this point better read the development guide first:

http://www.liferay.com/documentation/liferay-portal/6.1/development
Alessandro Violante, modificado hace 11 años.

RE: How to create a really simple form portlet

New Member Mensajes: 9 Fecha de incorporación: 25/10/12 Mensajes recientes
Yeah but it's a hundred times i'm reading a lot of answers and replies, the guide, etc... but i can't understand wtf i have to do
thumbnail
Juan Gonzalez P, modificado hace 11 años.

RE: How to create a really simple form portlet

Liferay Legend Mensajes: 3089 Fecha de incorporación: 28/10/08 Mensajes recientes
It's a matter of reading. Guess is clear enough in development guide.

Anyway, you can download Liferay IDE with eclipse and start from there.

Simply go to New -> Liferay Project and from there you can continue investigating....
Alessandro Violante, modificado hace 11 años.

RE: How to create a really simple form portlet

New Member Mensajes: 9 Fecha de incorporación: 25/10/12 Mensajes recientes
Where, Dave?
thumbnail
dave ch, modificado hace 11 años.

RE: How to create a really simple form portlet

Regular Member Mensajes: 161 Fecha de incorporación: 7/02/12 Mensajes recientes
Hi Violante,

Der are few out of box portlets, you should go through as per your requirement.

Regards
Dave
thumbnail
Hitoshi Ozawa, modificado hace 11 años.

RE: How to create a really simple form portlet

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
Have you gone through the simple example in the Developer's guide? Should be enough information on posting values.

http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/portlet-developme-3

Section of Service Builder should be enough to give you an idea on how to save values to a database

http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/service-build-5