Forums

Home » Alloy UI » English

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Alessandro Violante
How to create a really simple form portlet
November 14, 2012 2:00 AM
Answer

Alessandro Violante

Rank: New Member

Posts: 9

Join Date: October 25, 2012

Recent Posts

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
November 14, 2012 2:41 AM
Answer

Juan Gonzalez

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1902

Join Date: October 28, 2008

Recent Posts

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
November 14, 2012 2:57 AM
Answer

Alessandro Violante

Rank: New Member

Posts: 9

Join Date: October 25, 2012

Recent Posts

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
November 14, 2012 3:22 AM
Answer

Juan Gonzalez

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1902

Join Date: October 28, 2008

Recent Posts

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
November 15, 2012 3:46 AM
Answer

Alessandro Violante

Rank: New Member

Posts: 9

Join Date: October 25, 2012

Recent Posts

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

Sorry
Juan Gonzalez
RE: How to create a really simple form portlet
November 15, 2012 7:11 AM
Answer

Juan Gonzalez

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1902

Join Date: October 28, 2008

Recent Posts

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
November 16, 2012 2:17 AM
Answer

Alessandro Violante

Rank: New Member

Posts: 9

Join Date: October 25, 2012

Recent Posts

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

Alessandro Violante

Rank: New Member

Posts: 9

Join Date: October 25, 2012

Recent Posts

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
November 19, 2012 7:15 AM
Answer

Juan Gonzalez

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1902

Join Date: October 28, 2008

Recent Posts

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
November 19, 2012 7:23 AM
Answer

Alessandro Violante

Rank: New Member

Posts: 9

Join Date: October 25, 2012

Recent Posts

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
November 19, 2012 7:26 AM
Answer

dave ch

Rank: Regular Member

Posts: 164

Join Date: February 6, 2012

Recent Posts

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
November 19, 2012 7:28 AM
Answer

Juan Gonzalez

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1902

Join Date: October 28, 2008

Recent Posts

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
November 19, 2012 7:31 AM
Answer

Alessandro Violante

Rank: New Member

Posts: 9

Join Date: October 25, 2012

Recent Posts

Where, Dave?
Hitoshi Ozawa
RE: How to create a really simple form portlet
November 20, 2012 1:40 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7990

Join Date: March 23, 2010

Recent Posts

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