2
votes

I have just made a portlet with web service for liferay to learn how it works. It's working fine, and the GET method via http is also working, although throwing exception because the database is empty, but it's ok.

So what I'm trying now is to full the data base from the same portlet by editing my view.jsp.

My question is, how or where should I put my code in the jsp to send a POST request to add a row in the database? I'd like to use the aui to show a field and a button, so that you write what you want to insert, click submit, and send the POST Request.

<%@ page import="javax.portlet.PortletPreferences" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>

<portlet:defineObjects />

<% 
PortletPreferences prefs = renderRequest.getPreferences(); 
String name = (String)prefs.getValue("name", "Employee name");  
%>

Please insert you new <b>Employee</b> name.

<form method="post">
<aui:form method="post">
<aui:input label="New Employee: " name="name" type="text" value="<%=name%>"/> 
<aui:button type="submit" /> 
</aui:form> 
</form>

This code is showing correctly the button and the field. I just want to know where I have to put the code and how, to send this request and store something in the DB:

serviceClassName:xxx.service.XServiceUtil

serviceMethodName:methodName

servletContextName:X-portlet

serviceParameters:["param1","paramN"]

param1:n

paramN:m

The web service is built and working.

Thank you very much,

Rafa

1

1 Answers

1
votes

I think your code is almost correct, just remove the outer form and keep the aui:form. And that should work for you

<aui:form method="post">
<aui:input label="New Employee: " name="name" type="text" value="<%=name%>"/> 
<aui:button type="submit" /> 
</aui:form> 

The name parameter should be sent using post. One other thing that I noticed is in your form you havent given the action url. So you should write something like the following

<portlet:actionURL var="configurationURL" />

<aui:form method="post" action="<%=configurationURL%>">

Then your portlet should have processAction method, which would call the appropriate business logic using your localServiceUtil class.

For more on complete portlet creation refer the following link

http://www.liferay.com/documentation/liferay-portal/6.0/development/-/ai/portlet-development