Tuesday, August 16, 2016
Wednesday, June 10, 2015
new one
https://www.linkedin.com/profile/view?id=401708878&authType=name&authToken=Yao3&trk=hp-feed-member-name
<%@page import="com.test.userList"%>
<%@page import="com.liferay.portal.theme.ThemeDisplay"%>
<%@page import="com.liferay.portal.service.UserLocalServiceUtil"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.liferay.portal.model.User"%>
<%@page import="java.util.List"%>
<%@page import="javax.portlet.PortletSession"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
<%-- <portlet:actionURL var="userListURL" name="userList">
<portlet:param name="jspPage" value="/html/userlist/display.jsp"/>
</portlet:actionURL> --%>
<%-- <portlet:renderURL var="goBackURL">
<portlet:param name="jspPage" value="/html/userlist/view.jsp"/>
</portlet:renderURL> --%>
<h1>This is User List Page</h1>
<%-- <a href="<%=userListURL %>">Click to view users in log list</a><br/>
<a href="<%=goBackURL %>">Go Back</a> --%>
<%-- <%
PortletSession session2 = renderRequest.getPortletSession();
ArrayList<User> users = (ArrayList)session2.getAttribute("users");
%>
<%= users %> --%>
<%
List<User> users=UserLocalServiceUtil.getUsers(0, UserLocalServiceUtil.getUsersCount());
PortletSession session2 = renderRequest.getPortletSession();
%>
<%= users %>
<%@page import="com.test.userList"%>
<%@page import="com.liferay.portal.theme.ThemeDisplay"%>
<%@page import="com.liferay.portal.service.UserLocalServiceUtil"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.liferay.portal.model.User"%>
<%@page import="java.util.List"%>
<%@page import="javax.portlet.PortletSession"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
<%-- <portlet:actionURL var="userListURL" name="userList">
<portlet:param name="jspPage" value="/html/userlist/display.jsp"/>
</portlet:actionURL> --%>
<%-- <portlet:renderURL var="goBackURL">
<portlet:param name="jspPage" value="/html/userlist/view.jsp"/>
</portlet:renderURL> --%>
<h1>This is User List Page</h1>
<%-- <a href="<%=userListURL %>">Click to view users in log list</a><br/>
<a href="<%=goBackURL %>">Go Back</a> --%>
<%-- <%
PortletSession session2 = renderRequest.getPortletSession();
ArrayList<User> users = (ArrayList)session2.getAttribute("users");
%>
<%= users %> --%>
<%
List<User> users=UserLocalServiceUtil.getUsers(0, UserLocalServiceUtil.getUsersCount());
PortletSession session2 = renderRequest.getPortletSession();
%>
<%= users %>
gafaerwrassfdafasdfafwefaw
userList
userList.java
package com.test.UserList;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletSession;
import javax.portlet.ProcessAction;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.servlet.filters.invoker.Dispatcher;
import com.liferay.portal.model.Organization;
import com.liferay.portal.model.User;
import com.liferay.portal.service.OrganizationLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
/**
* Portlet implementation class userList
*/
public class userList extends MVCPortlet {
//public static Log log = Logger.getLogger(userList.class);
public static Log log = LogFactoryUtil.getLog(userList.class);
public void doView(RenderRequest renderRequest, RenderResponse renderResponse)throws IOException,PortletException{
log.info("doView called first when a portlet is loaded first");
String portletTitle= renderRequest.getParameter("custom-portlet");
PortletRequestDispatcher dispatcher = null;
PortletSession session = renderRequest.getPortletSession();
if((portletTitle != null)&&(portletTitle == "userList")){
dispatcher = getPortletContext().getRequestDispatcher("/html/userlist/userList.jsp");
dispatcher.forward(renderRequest, renderResponse);
}else if((portletTitle != null)&&(portletTitle == "userORG")){
dispatcher = getPortletContext().getRequestDispatcher("/html/userlist/orgList.jsp");
dispatcher.forward(renderRequest, renderResponse);
}
super.doView(renderRequest, renderResponse);
}
public void redirectUserList(ActionRequest actionRequest,ActionResponse actionResponse){
log.info("----Redirected to User List Action called -----");
actionResponse.setRenderParameter("custom-portlet", "userList");
}
public void redirectOrganizationList(ActionRequest actionRequest,ActionResponse actionResponse){
log.info("----Redirected to ORG List Action called -----");
actionResponse.setRenderParameter("custom-portlet", "userORG");
}
public void userList(ActionRequest actionRequest,ActionResponse actionResponse) throws SystemException {
// Todo Logic for user code
try {
int countUser = UserLocalServiceUtil.getUsersCount();
log.info("User Present In DB"+countUser);
List<User> users = UserLocalServiceUtil.getUsers(0, countUser);
PortletSession sessions = actionRequest.getPortletSession();
sessions.setAttribute("users", users);
log.info("Session set from My Portlet"+sessions.getAttribute("users"));
for (User user : users){
if (user != null){
log.info("UserID--:"+user.getUserId()+"UserCompanyID-:" +user.getCompanyId()+"UserEmail-:"+user.getEmailAddress()+
"UserScreenName--:"+user.getScreenName());
}
}
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// actionResponse.setRenderParameter("custom-portlet", "userORG");
}
public void organizationList(ActionRequest actionRequest,ActionResponse actionResponse) throws SystemException{
//Todo Logic for Organization code
// actionResponse.setRenderParameter("custom-portlet", "userORG");
try {
int countOrg = OrganizationLocalServiceUtil.getOrganizationsCount();
log.info("Organization list in DB"+countOrg);
List<Organization> organizations = OrganizationLocalServiceUtil.getOrganizations(0, countOrg);
actionRequest.getPortletSession().setAttribute("organizations", organizations, PortletSession.APPLICATION_SCOPE);
for (Organization org: organizations){
if(org != null){
log.info("ORG-:"+org.getName());
}
}
}
catch (SystemException e) {
e.printStackTrace();
}
/*if (organizations !=null){
log.info("OrganizationID-->"+organizations.get(countOrg));*/
}
public void serveResource(ResourceRequest resourceRequest,ResourceResponse resourceResponse) throws IOException,PortletException{
log.info("serverResource is called when view.jsp is loaded");
//String portletTitle= resourceRequest.getParameter("");
super.serveResource(resourceRequest, resourceResponse);
}
}
<---------------------------------------------------------------------------------------------------------------------------->
view.jsp
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<portlet:defineObjects />
<%-- <portlet:resourceURL var="getListUsersURL"/> --%>
<portlet:actionURL var="redirectUserListURL" name="redirectUserList"/>
<portlet:actionURL var="redirectOrganizationListURL" name="redirectOrganizationList"/>
Please select your options-:<br/>
<a href="<%= redirectUserListURL %>"> USER LIST</a><br/>
<a href="<%= redirectOrganizationListURL %>"> ORG LIST</a>
<--------------------------------------------------------------------------------------------------------------->
userList.jsp
<%@page import="java.util.ArrayList"%>
<%@page import="com.liferay.portal.model.User"%>
<%@page import="java.util.List"%>
<%@page import="javax.portlet.PortletSession"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<portlet:defineObjects />
<portlet:actionURL var="userListURL" name="userList">
<portlet:param name="jspPage" value="/html/userlist/display.jsp"/>
</portlet:actionURL>
<portlet:renderURL var="goBackURL">
<portlet:param name="jspPage" value="/html/userlist/view.jsp"/>
</portlet:renderURL>
<h1>This is User List Page</h1>
<a href="<%=userListURL %>">Click to view users in log list</a><br/>
<a href="<%=goBackURL %>">Go Back</a>
<%-- <%
PortletSession session2 = renderRequest.getPortletSession();
ArrayList<User> users = (ArrayList)session2.getAttribute("users");
%>
<%= users %> --%>
_________________________________________________________________________
orgList.jsp
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<portlet:defineObjects />
<portlet:actionURL var="organizationListURL" name="organizationList"/>
<portlet:renderURL var="goBackURL">
<portlet:param name="jspPage" value="/html/userlist/view.jsp"/>
</portlet:renderURL>
<h1>This is ORG List Page</h1><br/>
<a href="<%=organizationListURL %>">SHow ORganization</a>
<a href="<%=goBackURL %>">Go Back</a>
_______________________________________________________________
display.jsp
<%@page import="com.test.UserList.userList"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.liferay.portal.model.User"%>
<%@page import="java.util.List"%>
<%@page import="javax.portlet.PortletSession"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<portlet:defineObjects />
<%-- <%
PortletSession session2 = renderRequest.getPortletSession();
ArrayList<User> users = (ArrayList)session2.getAttribute("users");
if(users!=null){
%>
<b>Name: </b><%=users.get(users)%>
<%}%> --%>
_________________________________________________________________
init.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<portlet:defineObjects />
userList.java
package com.test.UserList;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletSession;
import javax.portlet.ProcessAction;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.servlet.filters.invoker.Dispatcher;
import com.liferay.portal.model.Organization;
import com.liferay.portal.model.User;
import com.liferay.portal.service.OrganizationLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
/**
* Portlet implementation class userList
*/
public class userList extends MVCPortlet {
//public static Log log = Logger.getLogger(userList.class);
public static Log log = LogFactoryUtil.getLog(userList.class);
public void doView(RenderRequest renderRequest, RenderResponse renderResponse)throws IOException,PortletException{
log.info("doView called first when a portlet is loaded first");
String portletTitle= renderRequest.getParameter("custom-portlet");
PortletRequestDispatcher dispatcher = null;
PortletSession session = renderRequest.getPortletSession();
if((portletTitle != null)&&(portletTitle == "userList")){
dispatcher = getPortletContext().getRequestDispatcher("/html/userlist/userList.jsp");
dispatcher.forward(renderRequest, renderResponse);
}else if((portletTitle != null)&&(portletTitle == "userORG")){
dispatcher = getPortletContext().getRequestDispatcher("/html/userlist/orgList.jsp");
dispatcher.forward(renderRequest, renderResponse);
}
super.doView(renderRequest, renderResponse);
}
public void redirectUserList(ActionRequest actionRequest,ActionResponse actionResponse){
log.info("----Redirected to User List Action called -----");
actionResponse.setRenderParameter("custom-portlet", "userList");
}
public void redirectOrganizationList(ActionRequest actionRequest,ActionResponse actionResponse){
log.info("----Redirected to ORG List Action called -----");
actionResponse.setRenderParameter("custom-portlet", "userORG");
}
public void userList(ActionRequest actionRequest,ActionResponse actionResponse) throws SystemException {
// Todo Logic for user code
try {
int countUser = UserLocalServiceUtil.getUsersCount();
log.info("User Present In DB"+countUser);
List<User> users = UserLocalServiceUtil.getUsers(0, countUser);
PortletSession sessions = actionRequest.getPortletSession();
sessions.setAttribute("users", users);
log.info("Session set from My Portlet"+sessions.getAttribute("users"));
for (User user : users){
if (user != null){
log.info("UserID--:"+user.getUserId()+"UserCompanyID-:" +user.getCompanyId()+"UserEmail-:"+user.getEmailAddress()+
"UserScreenName--:"+user.getScreenName());
}
}
} catch (SystemException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// actionResponse.setRenderParameter("custom-portlet", "userORG");
}
public void organizationList(ActionRequest actionRequest,ActionResponse actionResponse) throws SystemException{
//Todo Logic for Organization code
// actionResponse.setRenderParameter("custom-portlet", "userORG");
try {
int countOrg = OrganizationLocalServiceUtil.getOrganizationsCount();
log.info("Organization list in DB"+countOrg);
List<Organization> organizations = OrganizationLocalServiceUtil.getOrganizations(0, countOrg);
actionRequest.getPortletSession().setAttribute("organizations", organizations, PortletSession.APPLICATION_SCOPE);
for (Organization org: organizations){
if(org != null){
log.info("ORG-:"+org.getName());
}
}
}
catch (SystemException e) {
e.printStackTrace();
}
/*if (organizations !=null){
log.info("OrganizationID-->"+organizations.get(countOrg));*/
}
public void serveResource(ResourceRequest resourceRequest,ResourceResponse resourceResponse) throws IOException,PortletException{
log.info("serverResource is called when view.jsp is loaded");
//String portletTitle= resourceRequest.getParameter("");
super.serveResource(resourceRequest, resourceResponse);
}
}
<---------------------------------------------------------------------------------------------------------------------------->
view.jsp
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<portlet:defineObjects />
<%-- <portlet:resourceURL var="getListUsersURL"/> --%>
<portlet:actionURL var="redirectUserListURL" name="redirectUserList"/>
<portlet:actionURL var="redirectOrganizationListURL" name="redirectOrganizationList"/>
Please select your options-:<br/>
<a href="<%= redirectUserListURL %>"> USER LIST</a><br/>
<a href="<%= redirectOrganizationListURL %>"> ORG LIST</a>
<--------------------------------------------------------------------------------------------------------------->
userList.jsp
<%@page import="java.util.ArrayList"%>
<%@page import="com.liferay.portal.model.User"%>
<%@page import="java.util.List"%>
<%@page import="javax.portlet.PortletSession"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<portlet:defineObjects />
<portlet:actionURL var="userListURL" name="userList">
<portlet:param name="jspPage" value="/html/userlist/display.jsp"/>
</portlet:actionURL>
<portlet:renderURL var="goBackURL">
<portlet:param name="jspPage" value="/html/userlist/view.jsp"/>
</portlet:renderURL>
<h1>This is User List Page</h1>
<a href="<%=userListURL %>">Click to view users in log list</a><br/>
<a href="<%=goBackURL %>">Go Back</a>
<%-- <%
PortletSession session2 = renderRequest.getPortletSession();
ArrayList<User> users = (ArrayList)session2.getAttribute("users");
%>
<%= users %> --%>
_________________________________________________________________________
orgList.jsp
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<portlet:defineObjects />
<portlet:actionURL var="organizationListURL" name="organizationList"/>
<portlet:renderURL var="goBackURL">
<portlet:param name="jspPage" value="/html/userlist/view.jsp"/>
</portlet:renderURL>
<h1>This is ORG List Page</h1><br/>
<a href="<%=organizationListURL %>">SHow ORganization</a>
<a href="<%=goBackURL %>">Go Back</a>
_______________________________________________________________
display.jsp
<%@page import="com.test.UserList.userList"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.liferay.portal.model.User"%>
<%@page import="java.util.List"%>
<%@page import="javax.portlet.PortletSession"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
<portlet:defineObjects />
<%-- <%
PortletSession session2 = renderRequest.getPortletSession();
ArrayList<User> users = (ArrayList)session2.getAttribute("users");
if(users!=null){
%>
<b>Name: </b><%=users.get(users)%>
<%}%> --%>
_________________________________________________________________
init.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<portlet:defineObjects />
Monday, June 8, 2015
new links
http://www.opensourceforlife.com/2012/07/custom-landing-page-using-hook-liferay.html
_________________________________________________________________________
____________________________________________________________________
http://www.liferay.com/community/forums/-/message_boards/message/10756812
\http://sourceforge.net/p/lportal/news/2015/02/uploading-files-using-ajax-via-alloyui/
http://liferayvishal.blogspot.in/
v.imp
http://www.codeyouneed.com/liferay-portlet-file-upload-tutorial/
package com.test.upload;
import java.io.File;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import org.apache.commons.io.FileUtils;
import com.liferay.portal.kernel.upload.UploadPortletRequest;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.util.PortalUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
public class UploadDirectory extends MVCPortlet {
private final static int ONE_GB = 1073741824;
private final static String baseDir = "/home/neosoft/Test";
// private final static String deptListName = "type";
private final static String fileInputName = "fileupload";
public void upload(ActionRequest request, ActionResponse response)
throws Exception {
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);
long sizeInBytes = uploadRequest.getSize(fileInputName);
if (uploadRequest.getSize(fileInputName) == 0) {
throw new Exception("Received file is 0 bytes!");
}
File uploadedFile = uploadRequest.getFile(fileInputName);
String sourceFileName = uploadRequest.getFileName(fileInputName);
System.out.println(ParamUtil.getParameterValues(uploadRequest, "type"));
String paramFolder = uploadRequest.getParameter("folder");
File folder = new File(baseDir+"/"+paramFolder);
if (!folder.exists()) {
if (folder.mkdir()) {
System.out.println("Directory is created!");
} else {
System.out.println("Failed to create directory!");
}
}
if (folder.getUsableSpace() < ONE_GB) {
throw new Exception("Out of disk space!");
}
File filePath = new File(folder.getAbsolutePath() + File.separator + sourceFileName);
FileUtils.copyFile(uploadedFile, filePath);
}
/*public void option(ActionRequest request, ActionResponse response)
throws IOException, PortletException {
String[] item = request.getParameterValues("type");
File folder = new File(baseDir+"/"+item);
}*/
}
_________________________________________________________________________
____________________________________________________________________
http://www.liferay.com/community/forums/-/message_boards/message/10756812
\http://sourceforge.net/p/lportal/news/2015/02/uploading-files-using-ajax-via-alloyui/
http://liferayvishal.blogspot.in/
v.imp
http://www.codeyouneed.com/liferay-portlet-file-upload-tutorial/
package com.test.upload;
import java.io.File;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import org.apache.commons.io.FileUtils;
import com.liferay.portal.kernel.upload.UploadPortletRequest;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.util.PortalUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
public class UploadDirectory extends MVCPortlet {
private final static int ONE_GB = 1073741824;
private final static String baseDir = "/home/neosoft/Test";
// private final static String deptListName = "type";
private final static String fileInputName = "fileupload";
public void upload(ActionRequest request, ActionResponse response)
throws Exception {
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);
long sizeInBytes = uploadRequest.getSize(fileInputName);
if (uploadRequest.getSize(fileInputName) == 0) {
throw new Exception("Received file is 0 bytes!");
}
File uploadedFile = uploadRequest.getFile(fileInputName);
String sourceFileName = uploadRequest.getFileName(fileInputName);
System.out.println(ParamUtil.getParameterValues(uploadRequest, "type"));
String paramFolder = uploadRequest.getParameter("folder");
File folder = new File(baseDir+"/"+paramFolder);
if (!folder.exists()) {
if (folder.mkdir()) {
System.out.println("Directory is created!");
} else {
System.out.println("Failed to create directory!");
}
}
if (folder.getUsableSpace() < ONE_GB) {
throw new Exception("Out of disk space!");
}
File filePath = new File(folder.getAbsolutePath() + File.separator + sourceFileName);
FileUtils.copyFile(uploadedFile, filePath);
}
/*public void option(ActionRequest request, ActionResponse response)
throws IOException, PortletException {
String[] item = request.getParameterValues("type");
File folder = new File(baseDir+"/"+item);
}*/
}
Location:
Nevada, USA
Saturday, May 30, 2015
test
http://rsjblogs.blogspot.in/p/liferay-portlet-development.html
JAVA
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
package com.liferay.dlupload;
import java.io.File;
import java.io.IOException;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.upload.FileItem;
import com.liferay.portal.util.PortalUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
public class Document extends MVCPortlet {
public void uploadURL(ActionRequest req, ActionResponse resp)
throws PortalException,IOException
{System.out.println("inside upload action");
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
Properties properties = PortalUtil.getPortalProperties();
/*Creating parent directory where all file will be uploaded*/
File directory = NewFile(properties.getProperty("liferay.home") + "/home/Uploaded_File");
if(!directory.exists()){
directory.mkdirs();
System.out.println("type******************************dir existed");
}
/*Parsing action request to generate http servletRequest*/
HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(req);
try
{
List fields =upload.parseRequest(httpRequest);
Iterator<FileItem> it = fields.iterator();
While (it.hasNext());
{
FileItem fileItem = it.next();
if (!fileItem.isFormField())
{
String fileName = fileItem.getFileName();
File file = new File(directory, fileName);
String newFileName=generateFilename(file.getName().split("\\.")[0]);
File tempFile = File(directory, newFileName+"."+file.getName().split("\\.")[1]);
/*check the condition where same file exsist in the parent folder*/
boolean bool = file.renameTo(tempFile);
try
{
/*save the file to server*/
if(!file.exists()){
fileItem.write(file); //saving into folder
}else{
System.out.println("####################### file" +file.getName() +" exists ");
}
}
catch (Exception e)
{
System.err.println("File " + file.getName() + "could not be Saved");
}
}
}
}
private void While(boolean hasNext) {
// TODO Auto-generated method stub
}
private java.io.File NewFile(String string) {
// TODO Auto-generated method stub
return null;
}
private File File(File directory, String string) {
// TODO Auto-generated method stub
return null;
}
public String generateFilename(String name)
{
Calendar cal = Calendar.getInstance();
return(name+"_"+cal.get(Calendar.DAY_OF_MONTH)+(cal.get(Calendar.MONTH)+1)+cal.get(Calendar.YEAR)+cal.get(Calendar.HOUR_OF_DAY)+cal.get(Calendar.MINUTE)+cal.get(Calendar.SECOND));
}
}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
<%@ include file="/view.jsp"%>
<portlet:actionURL name="uploadURL" var="uploadURL" />
<aui:form action=<%="uploadURL.toString()" %> "enctype="multipart/form-data">
<aui:input name="normal" type="text"/>
<label>upload</label>
<input type="file" name"fileupload[]" multiple>
<aui:button name="upload" tupe="submit">upload</aui:button>
</aui:form>
JAVA
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
package com.liferay.dlupload;
import java.io.File;
import java.io.IOException;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.upload.FileItem;
import com.liferay.portal.util.PortalUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
public class Document extends MVCPortlet {
public void uploadURL(ActionRequest req, ActionResponse resp)
throws PortalException,IOException
{System.out.println("inside upload action");
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
Properties properties = PortalUtil.getPortalProperties();
/*Creating parent directory where all file will be uploaded*/
File directory = NewFile(properties.getProperty("liferay.home") + "/home/Uploaded_File");
if(!directory.exists()){
directory.mkdirs();
System.out.println("type******************************dir existed");
}
/*Parsing action request to generate http servletRequest*/
HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(req);
try
{
List fields =upload.parseRequest(httpRequest);
Iterator<FileItem> it = fields.iterator();
While (it.hasNext());
{
FileItem fileItem = it.next();
if (!fileItem.isFormField())
{
String fileName = fileItem.getFileName();
File file = new File(directory, fileName);
String newFileName=generateFilename(file.getName().split("\\.")[0]);
File tempFile = File(directory, newFileName+"."+file.getName().split("\\.")[1]);
/*check the condition where same file exsist in the parent folder*/
boolean bool = file.renameTo(tempFile);
try
{
/*save the file to server*/
if(!file.exists()){
fileItem.write(file); //saving into folder
}else{
System.out.println("####################### file" +file.getName() +" exists ");
}
}
catch (Exception e)
{
System.err.println("File " + file.getName() + "could not be Saved");
}
}
}
}
private void While(boolean hasNext) {
// TODO Auto-generated method stub
}
private java.io.File NewFile(String string) {
// TODO Auto-generated method stub
return null;
}
private File File(File directory, String string) {
// TODO Auto-generated method stub
return null;
}
public String generateFilename(String name)
{
Calendar cal = Calendar.getInstance();
return(name+"_"+cal.get(Calendar.DAY_OF_MONTH)+(cal.get(Calendar.MONTH)+1)+cal.get(Calendar.YEAR)+cal.get(Calendar.HOUR_OF_DAY)+cal.get(Calendar.MINUTE)+cal.get(Calendar.SECOND));
}
}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
<%@ include file="/view.jsp"%>
<portlet:actionURL name="uploadURL" var="uploadURL" />
<aui:form action=<%="uploadURL.toString()" %> "enctype="multipart/form-data">
<aui:input name="normal" type="text"/>
<label>upload</label>
<input type="file" name"fileupload[]" multiple>
<aui:button name="upload" tupe="submit">upload</aui:button>
</aui:form>
Friday, May 29, 2015
test
http://stackoverflow.com/questions/23452484/create-folder-and-upload-file-using-servlet
vivekliferayblogspote.blogspot.in/2013/12/liferay-61-multiple-image-upload.html
package com.upload.doc;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.ProcessAction;
import com.liferay.portal.kernel.upload.UploadPortletRequest;
import com.liferay.portal.kernel.util.FileUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.util.PortalUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
public class DocUpload extends MVCPortlet {
@ProcessAction(name = "addProduct")
public void addProduct(ActionRequest request, ActionResponse response) {
String name = ParamUtil.getString(request,"name");
String anotherTryForName = request.getParameter("name");
System.out.println(name);
System.out.println(anotherTryForName);
System.out.println(uploadImg(request));
}
private String uploadImg(ActionRequest request) {
String realPath = getPortletContext().getRealPath("/");
byte[] bytes = null;
try {
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);
String sourceFileName =uploadRequest.getFileName("imgFile");
/***********************************************
File newFile=null;
if ((bytes != null) && (bytes.length > 0)) {
File file = new File("/home/neosoft/test",file);
try {
newFile = new File(realPath+"html/portlet/"+sourceFileName);
FileInputStream fileInputStream = new FileInputStream(file);
FileOutputStream fileOutputStream = new FileOutputStream(newFile);
fileInputStream.read(bytes);
fileOutputStream.write(bytes, 0, bytes.length);
fileOutputStream.close();
fileInputStream.close();
}
************************************************/
File file = uploadRequest.getFile("imgFile");
try {
bytes = FileUtil.getBytes(file);
} catch (IOException e2) {
e2.printStackTrace();
}
File newFile = null;
if ((bytes != null) && (bytes.length > 0)) {
try {
newFile = new File(realPath + "demo/productimg/"+ sourceFileName);
FileInputStream fileInputStream = new FileInputStream(file);
FileOutputStream fileOutputStream = new FileOutputStream(newFile);
fileInputStream.read(bytes);
fileOutputStream.write(bytes, 0, bytes.length);
fileOutputStream.close();
fileInputStream.close();
} catch (FileNotFoundException e) {
System.out.println("File Not Found.");
e.printStackTrace();
} catch (IOException e1) {
System.out.println("Error Reading The File.");
e1.printStackTrace();
}
}
return sourceFileName;
} catch (Exception e) {
System.out.println("Exception::::" + e.getMessage());
return "";
}
}
}
****************************
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<portlet:actionURL var='create' name="addProduct">
</portlet:actionURL>
<form id="addform" action="<%=create%>" method="post" enctype="multipart/form-data">
<dl class="dl-horizontal">
<dt>Product Name</dt>
<dd>
<input type="text" name="name" />
</dd>
<dt>Image File</dt>
<dd>
<input type="file" name="imgFile" >
</dd>
</dl>
<button type="submit">Save</button>
</form>
JSP
vivekliferayblogspote.blogspot.in/2013/12/liferay-61-multiple-image-upload.html
package com.upload.doc;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.ProcessAction;
import com.liferay.portal.kernel.upload.UploadPortletRequest;
import com.liferay.portal.kernel.util.FileUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.util.PortalUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
public class DocUpload extends MVCPortlet {
@ProcessAction(name = "addProduct")
public void addProduct(ActionRequest request, ActionResponse response) {
String name = ParamUtil.getString(request,"name");
String anotherTryForName = request.getParameter("name");
System.out.println(name);
System.out.println(anotherTryForName);
System.out.println(uploadImg(request));
}
private String uploadImg(ActionRequest request) {
String realPath = getPortletContext().getRealPath("/");
byte[] bytes = null;
try {
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);
String sourceFileName =uploadRequest.getFileName("imgFile");
/***********************************************
File newFile=null;
if ((bytes != null) && (bytes.length > 0)) {
File file = new File("/home/neosoft/test",file);
try {
newFile = new File(realPath+"html/portlet/"+sourceFileName);
FileInputStream fileInputStream = new FileInputStream(file);
FileOutputStream fileOutputStream = new FileOutputStream(newFile);
fileInputStream.read(bytes);
fileOutputStream.write(bytes, 0, bytes.length);
fileOutputStream.close();
fileInputStream.close();
}
************************************************/
File file = uploadRequest.getFile("imgFile");
try {
bytes = FileUtil.getBytes(file);
} catch (IOException e2) {
e2.printStackTrace();
}
File newFile = null;
if ((bytes != null) && (bytes.length > 0)) {
try {
newFile = new File(realPath + "demo/productimg/"+ sourceFileName);
FileInputStream fileInputStream = new FileInputStream(file);
FileOutputStream fileOutputStream = new FileOutputStream(newFile);
fileInputStream.read(bytes);
fileOutputStream.write(bytes, 0, bytes.length);
fileOutputStream.close();
fileInputStream.close();
} catch (FileNotFoundException e) {
System.out.println("File Not Found.");
e.printStackTrace();
} catch (IOException e1) {
System.out.println("Error Reading The File.");
e1.printStackTrace();
}
}
return sourceFileName;
} catch (Exception e) {
System.out.println("Exception::::" + e.getMessage());
return "";
}
}
}
****************************
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<portlet:actionURL var='create' name="addProduct">
</portlet:actionURL>
<form id="addform" action="<%=create%>" method="post" enctype="multipart/form-data">
<dl class="dl-horizontal">
<dt>Product Name</dt>
<dd>
<input type="text" name="name" />
</dd>
<dt>Image File</dt>
<dd>
<input type="file" name="imgFile" >
</dd>
</dl>
<button type="submit">Save</button>
</form>
JSP
Monday, June 23, 2014
User Registration Portlet Customization
The registration or create account portlet in Liferay portal can be
customized to add/remove some of its field without any coding.
This blog explain some of these customization properties which developers can add them in portal-ext to change the behavior of user registration portlet.
users.screen.name.always.autogenerate - If you do not want your users to provide screen name, you can use this property hide screen name text field. The default value is false. If it is changed to true, the screen name field will not appear on the registration page and screen name will be auto generated by the portal.
login.create.account.allow.custom.password - The default registration portlet in Liferay doesn't provide option of password selection to user. If this property is set to true, the registration screen will show password fields to user and user can provide password of his/her choice.
field.enable.com.liferay.portal.model.Contact.male - If your site is not interested in knowing the gender of the user, you can remove gender selection from the page by setting false value of this property.
field.enable.com.liferay.portal.model.Contact.birthday - Last configuration is for birth date field. You can remove bith date selection by setting false value to this property.
Following screen shot shows customized registration portlet using above properties.
captcha.check.portal.create_account - This propery can be used to tell whether or not to use captcha checks for the account creation.
There are few other properties related to user registration which requires more attaention.
users.email.address.required - Set this to false if you want to be able to create users without an email address. An email address will be automatically assigned to a user based on the property "users.email.address.auto.suffix". If user is entering his email id, the system will not generate a new one. Usually, setting this property to false will make sense when you don't want user to use email address for login.
This blog explain some of these customization properties which developers can add them in portal-ext to change the behavior of user registration portlet.
users.screen.name.always.autogenerate - If you do not want your users to provide screen name, you can use this property hide screen name text field. The default value is false. If it is changed to true, the screen name field will not appear on the registration page and screen name will be auto generated by the portal.
login.create.account.allow.custom.password - The default registration portlet in Liferay doesn't provide option of password selection to user. If this property is set to true, the registration screen will show password fields to user and user can provide password of his/her choice.
field.enable.com.liferay.portal.model.Contact.male - If your site is not interested in knowing the gender of the user, you can remove gender selection from the page by setting false value of this property.
field.enable.com.liferay.portal.model.Contact.birthday - Last configuration is for birth date field. You can remove bith date selection by setting false value to this property.
Following screen shot shows customized registration portlet using above properties.
captcha.check.portal.create_account - This propery can be used to tell whether or not to use captcha checks for the account creation.
There are few other properties related to user registration which requires more attaention.
users.email.address.required - Set this to false if you want to be able to create users without an email address. An email address will be automatically assigned to a user based on the property "users.email.address.auto.suffix". If user is entering his email id, the system will not generate a new one. Usually, setting this property to false will make sense when you don't want user to use email address for login.
Subscribe to:
Posts (Atom)
