Foros

Inicio » Alloy UI » English

Vista combinada Visión Plana Vista de árbol
Discusiones [ Anterior | Siguiente ]
toggle
Alessandro Violante
How to create a really simple form portlet
14 de noviembre de 2012 2:00
Respuesta

Alessandro Violante

Ranking: New Member

Mensajes: 9

Fecha de incorporación: 25 de octubre de 2012

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
Juan Gonzalez
RE: How to create a really simple form portlet
14 de noviembre de 2012 2:41
Respuesta

Juan Gonzalez

LIFERAY STAFF

Ranking: Liferay Legend

Mensajes: 1841

Fecha de incorporación: 28 de octubre de 2008

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
RE: How to create a really simple form portlet
14 de noviembre de 2012 2:57
Respuesta

Alessandro Violante

Ranking: New Member

Mensajes: 9

Fecha de incorporación: 25 de octubre de 2012

Mensajes recientes

Mh no but "the problem" is that i have to learn it, not "just" to use it emoticon
Juan Gonzalez
RE: How to create a really simple form portlet
14 de noviembre de 2012 3:22
Respuesta

Juan Gonzalez

LIFERAY STAFF

Ranking: Liferay Legend

Mensajes: 1841

Fecha de incorporación: 28 de octubre de 2008

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
RE: How to create a really simple form portlet
15 de noviembre de 2012 3:46
Respuesta

Alessandro Violante

Ranking: New Member

Mensajes: 9

Fecha de incorporación: 25 de octubre de 2012

Mensajes recientes

I've downloaded it but how i have to use it? emoticon

Sorry
Juan Gonzalez
RE: How to create a really simple form portlet
15 de noviembre de 2012 7:11
Respuesta

Juan Gonzalez

LIFERAY STAFF

Ranking: Liferay Legend

Mensajes: 1841

Fecha de incorporación: 28 de octubre de 2008

Mensajes recientes

You have two great tutorials in YouTube channel:

https://www.youtube.com/user/XMLPortletFactory
Alessandro Violante
RE: How to create a really simple form portlet
16 de noviembre de 2012 2:17
Respuesta

Alessandro Violante

Ranking: New Member

Mensajes: 9

Fecha de incorporación: 25 de octubre de 2012

Mensajes recientes

Thanks, i'll study this and let you know emoticon
Alessandro Violante
RE: How to create a really simple form portlet
19 de noviembre de 2012 5:42
Respuesta

Alessandro Violante

Ranking: New Member

Mensajes: 9

Fecha de incorporación: 25 de octubre de 2012

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?
Juan Gonzalez
RE: How to create a really simple form portlet
19 de noviembre de 2012 7:15
Respuesta

Juan Gonzalez

LIFERAY STAFF

Ranking: Liferay Legend

Mensajes: 1841

Fecha de incorporación: 28 de octubre de 2008

Mensajes recientes

So at this point better read the development guide first:

http://www.liferay.com/documentation/liferay-portal/6.1/development
Alessandro Violante
RE: How to create a really simple form portlet
19 de noviembre de 2012 7:23
Respuesta

Alessandro Violante

Ranking: New Member

Mensajes: 9

Fecha de incorporación: 25 de octubre de 2012

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
dave ch
RE: How to create a really simple form portlet
19 de noviembre de 2012 7:26
Respuesta

dave ch

Ranking: Regular Member

Mensajes: 164

Fecha de incorporación: 6 de febrero de 2012

Mensajes recientes

Hi Violante,

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

Regards
Dave
Juan Gonzalez
RE: How to create a really simple form portlet
19 de noviembre de 2012 7:28
Respuesta

Juan Gonzalez

LIFERAY STAFF

Ranking: Liferay Legend

Mensajes: 1841

Fecha de incorporación: 28 de octubre de 2008

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
RE: How to create a really simple form portlet
19 de noviembre de 2012 7:31
Respuesta

Alessandro Violante

Ranking: New Member

Mensajes: 9

Fecha de incorporación: 25 de octubre de 2012

Mensajes recientes

Where, Dave?
Hitoshi Ozawa
RE: How to create a really simple form portlet
20 de noviembre de 2012 13:40
Respuesta

Hitoshi Ozawa

Ranking: Liferay Legend

Mensajes: 7990

Fecha de incorporación: 23 de marzo de 2010

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