Fórum

Inserting data into database in liferay

cya k, modificado 11 Anos atrás.

Inserting data into database in liferay

Regular Member Postagens: 187 Data de Entrada: 16/01/13 Postagens Recentes
I am trying to add data in the database(Mysql) in liferay.
Here is my view.jsp for adding data:
<portlet:actionURL name="addProduct" var="addProductURL"/>
<aui:form action="<%= addProductURL.toString() %>" method="post">
<aui:fieldset>
<aui:input name="productName" size="45" />
<aui:input name="serialNumber" size="45" />
<aui:button-row>
<aui:button type="submit" />
</aui:button-row>
</aui:fieldset>
</aui:form>


This is my addProduct() function in crudAdminPortlet java class in my com.crud.internet.cruddisplay.portlet package :
public void addProduct(ActionRequest request, ActionResponse response) throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
CRUD product = ActionUtil.CRUDFromRequest(request);
ArrayList<String> errors = new ArrayList<String>();
if (CRUDValidator.validateProduct(product, errors)) {
CRUDLocalServiceUtil.addProduct(product,themeDisplay.getUserId());
SessionMessages.add(request, "product-saved-successfully");
}
else {
SessionErrors.add(request, "fields-required");
}
}


And this is my addProduct function in CRDULocalServiceImpl class which is in com.crud.internet.cruddisplay.servce.impl:
public CRUD addProduct(CRUD newProduct, long userId) throws SystemException, PortalException {
CRUDPersistenceImpl crudPersistenceImpl = null;
@SuppressWarnings("null")
CRUD product = crudPersistenceImpl.create(counterLocalService.increment(CRUD.class.getName()));

resourceLocalService.addResources(
newProduct.getCompanyId(),
newProduct.getGroupId(), userId,
CRUD.class.getName(),
product.getPrimaryKey(), false,true, true);
product.setProductName(newProduct.getProductName());
product.setSerialNumber(newProduct.getSerialNumber());
product.setCompanyId(newProduct.getCompanyId());
product.setGroupId(newProduct.getGroupId());
return crudPersistence.update(product, false);
}


The error I am getting is :
04:03:43,619 ERROR [http-bio-8080-exec-1][render_portlet_jsp:154] java.lang.NullPointerException
at com.crud.internet.cruddisplay.portlet.ActionUtil.CRUDFromRequest(ActionUtil.java:23)
at com.crud.internet.cruddisplay.portlet.crudAdminPortlet.addProduct(crudAdminPortlet.java:24)
at com.liferay.portal.kernel.portlet.LiferayPortlet.callActionMethod(LiferayPortlet.java:153)
at com.liferay.util.bridges.mvc.MVCPortlet.callActionMethod(MVCPortlet.java:250)
at com.liferay.portal.kernel.portlet.LiferayPortlet.processAction(LiferayPortlet.java:80)
at com.liferay.util.bridges.mvc.MVCPortlet.processAction(MVCPortlet.java:220)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:70)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:48)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:593)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:530)
at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:534)


I am having dificulty in implementing crudfromrequest() function which should be implemented in ActionUtil. Can anyone help me with this? I do not know how to implement it
thumbnail
David H Nebinger, modificado 11 Anos atrás.

RE: Inserting data into database in liferay

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
cya k:
04:03:43,619 ERROR [http-bio-8080-exec-1][render_portlet_jsp:154] java.lang.NullPointerException
at com.crud.internet.cruddisplay.portlet.ActionUtil.CRUDFromRequest(ActionUtil.java:23)


It's a stack trace. It gives you the line number and file where the error occurred, and it even tells you what your error is.

On line 23 of ActionUtil.java, you're accessing an object which was not defined/populated/available.
cya k, modificado 11 Anos atrás.

RE: Inserting data into database in liferay

Regular Member Postagens: 187 Data de Entrada: 16/01/13 Postagens Recentes
Thanks for replying David H Nebinger.
Yes I know I was just tinkering with the code since I am new to liferay. I defined my function CRUDfromrequest() as follows since I do not know what code to put into it.

@SuppressWarnings("null")
public static CRUD CRUDFromRequest(ActionRequest request) {
// TODO Auto-generated method stub
CRUD crudProd = null;



return crudProd;

}

It is eident that this function returns a null.
I need help as to what code should be put into the above function

Thanks
Seeya S Kudtarker, modificado 11 Anos atrás.

RE: Inserting data into database in liferay

Regular Member Postagens: 187 Data de Entrada: 16/01/13 Postagens Recentes
I tried eveything and for past 3 days I am struggling with this function. Same is the case when I try to access data from the database
Please help!!