Tribune

Home » Alloy UI » English

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Alessandro Violante
How to create a really simple form portlet
14 novembre 2012 2.00
Risposta

Alessandro Violante

Punteggio: New Member

Messaggi: 9

Data di Iscrizione: 25 ottobre 2012

Messaggi recenti

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 novembre 2012 2.41
Risposta

Juan Gonzalez

LIFERAY STAFF

Punteggio: Liferay Legend

Messaggi: 2805

Data di Iscrizione: 28 ottobre 2008

Messaggi recenti

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 novembre 2012 2.57
Risposta

Alessandro Violante

Punteggio: New Member

Messaggi: 9

Data di Iscrizione: 25 ottobre 2012

Messaggi recenti

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 novembre 2012 3.22
Risposta

Juan Gonzalez

LIFERAY STAFF

Punteggio: Liferay Legend

Messaggi: 2805

Data di Iscrizione: 28 ottobre 2008

Messaggi recenti

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 novembre 2012 3.46
Risposta

Alessandro Violante

Punteggio: New Member

Messaggi: 9

Data di Iscrizione: 25 ottobre 2012

Messaggi recenti

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 novembre 2012 7.11
Risposta

Juan Gonzalez

LIFERAY STAFF

Punteggio: Liferay Legend

Messaggi: 2805

Data di Iscrizione: 28 ottobre 2008

Messaggi recenti

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 novembre 2012 2.17
Risposta

Alessandro Violante

Punteggio: New Member

Messaggi: 9

Data di Iscrizione: 25 ottobre 2012

Messaggi recenti

Thanks, i'll study this and let you know emoticon
Alessandro Violante
RE: How to create a really simple form portlet
19 novembre 2012 5.42
Risposta

Alessandro Violante

Punteggio: New Member

Messaggi: 9

Data di Iscrizione: 25 ottobre 2012

Messaggi recenti

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 novembre 2012 7.15
Risposta

Juan Gonzalez

LIFERAY STAFF

Punteggio: Liferay Legend

Messaggi: 2805

Data di Iscrizione: 28 ottobre 2008

Messaggi recenti

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 novembre 2012 7.23
Risposta

Alessandro Violante

Punteggio: New Member

Messaggi: 9

Data di Iscrizione: 25 ottobre 2012

Messaggi recenti

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 novembre 2012 7.26
Risposta

dave ch

Punteggio: Regular Member

Messaggi: 164

Data di Iscrizione: 6 febbraio 2012

Messaggi recenti

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 novembre 2012 7.28
Risposta

Juan Gonzalez

LIFERAY STAFF

Punteggio: Liferay Legend

Messaggi: 2805

Data di Iscrizione: 28 ottobre 2008

Messaggi recenti

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 novembre 2012 7.31
Risposta

Alessandro Violante

Punteggio: New Member

Messaggi: 9

Data di Iscrizione: 25 ottobre 2012

Messaggi recenti

Where, Dave?
Hitoshi Ozawa
RE: How to create a really simple form portlet
20 novembre 2012 13.40
Risposta

Hitoshi Ozawa

Punteggio: Liferay Legend

Messaggi: 7949

Data di Iscrizione: 23 marzo 2010

Messaggi recenti

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