After you have created service buider as I mentioned in my previous post.
1. Go to your view.jsp and create a form.For now, I will be using html <form> tag
2. Now open your .java file and add the following method
public void processAction(
ActionRequest actionRequest, ActionResponse actionResponse)
throws IOException, PortletException {
String fname=actionRequest.getParameter("fname");
String lname=actionRequest.getParameter("lname");
Date dob=new Date(actionRequest.getParameter("dob"));
int gender=Integer.parseInt(actionRequest.getParameter("gender"));
String address=actionRequest.getParameter("address");
long phone=Long.parseLong(actionRequest.getParameter("phone"));
String email=actionRequest.getParameter("email");
empLocalServiceUtil.add(fname, lname, dob, gender, address, phone,
email);
}
3. After this go to the xxLocalServiceImpl and add the following method.
public void add(String fname, String lname, Date dob, int gender,
String address, long phone, String email) {
try {
emp employee = empLocalServiceUtil
.createemp(CounterLocalServiceUtil.increment());
employee.setFname(fname);
employee.setLname(lname);
employee.setDob(dob);
employee.setGender(gender);
employee.setAddress(address);
employee.setPhone(phone);
employee.setEmail(email);
empLocalServiceUtil.updateemp(employee);
} catch (SystemException e) {
e.printStackTrace();
}
4. Build-Services again. Refresh the project.
5. Deploy the portlet.
Ummhmmm.... it feels great to see the portlet helping us, taking our values to the database..NO????
Thanks
1. Go to your view.jsp and create a form.For now, I will be using html <form> tag
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<portlet:defineObjects />
<form action='<portlet:actionURL/>' method="post">
<table>
<tr>
<td>Fname:</td>
<td><input type="text" name="fname" /></td>
</tr>
<tr>
<td>Lname:</td>
<td><input type="text" name=lname " /></td>
</tr>
<tr>
<td>Gender:</td>
<td><select name="gender" >
<option value="0">Male</option>
<option value="1">Female</option>
</select></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="address" /></td>
</tr>
<tr>
<td>Phone:</td>
<td><input type="text" name="phone" /></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<td>Date of Birth:</td>
<td><input type="text" name="dob" /></td>
</tr>
<tr>
<td colspan=2><input type="submit" value="submit" /></td>
</tr>
</table>
</form>
<portlet:defineObjects />
<form action='<portlet:actionURL/>' method="post">
<table>
<tr>
<td>Fname:</td>
<td><input type="text" name="fname" /></td>
</tr>
<tr>
<td>Lname:</td>
<td><input type="text" name=lname " /></td>
</tr>
<tr>
<td>Gender:</td>
<td><select name="gender" >
<option value="0">Male</option>
<option value="1">Female</option>
</select></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="address" /></td>
</tr>
<tr>
<td>Phone:</td>
<td><input type="text" name="phone" /></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<td>Date of Birth:</td>
<td><input type="text" name="dob" /></td>
</tr>
<tr>
<td colspan=2><input type="submit" value="submit" /></td>
</tr>
</table>
</form>
2. Now open your .java file and add the following method
public void processAction(
ActionRequest actionRequest, ActionResponse actionResponse)
throws IOException, PortletException {
String fname=actionRequest.getParameter("fname");
String lname=actionRequest.getParameter("lname");
Date dob=new Date(actionRequest.getParameter("dob"));
int gender=Integer.parseInt(actionRequest.getParameter("gender"));
String address=actionRequest.getParameter("address");
long phone=Long.parseLong(actionRequest.getParameter("phone"));
String email=actionRequest.getParameter("email");
empLocalServiceUtil.add(fname, lname, dob, gender, address, phone,
email);
}
3. After this go to the xxLocalServiceImpl and add the following method.
String address, long phone, String email) {
try {
emp employee = empLocalServiceUtil
.createemp(CounterLocalServiceUtil.increment());
employee.setFname(fname);
employee.setLname(lname);
employee.setDob(dob);
employee.setGender(gender);
employee.setAddress(address);
employee.setPhone(phone);
employee.setEmail(email);
empLocalServiceUtil.updateemp(employee);
} catch (SystemException e) {
e.printStackTrace();
}
4. Build-Services again. Refresh the project.
5. Deploy the portlet.
Ummhmmm.... it feels great to see the portlet helping us, taking our values to the database..NO????
Thanks
Hi Priyanka,
ReplyDeleteHow do I check a attribute of a table if it exist? For example, I have a table named "User". In this table, I create 2 columns, first is the primary key, namely "UserID", and the second is "Name". I want to check if there is a user name called, for instance, "Aqua". Please help me!
so you want to know search...in other words? then just implement finder in service.xml
Deletei cant see my liferay table in mysql database
Deletei use liferay tomcate 6.1 in ubuntu
very well explained,just the material what i needed .Thank you very much
ReplyDeletewhen i put portal-ext.properties in classes folder i cant login in liferay..
ReplyDeletebut when i delete portal-ext.properties and try to run it work fine...
i want to create table using service.xml and i want to see where is my table in mysql database...
pls help me ... as soon as posible
From... Kapil
Please provide the content of your portal-ext.properties
Deletewhere we have to write the processAction method
ReplyDeleteAnd what are the changes we have to do in service.xml file after using processAction method
ReplyDelete