Forums

Home » Liferay IDE » English

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Seeya S Kudtarker
Inserting data into database in liferay
February 4, 2013 8:11 PM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

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
David H Nebinger
RE: Inserting data into database in liferay
February 4, 2013 8:23 PM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11046

Join Date: September 1, 2006

Recent Posts

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.
Seeya S Kudtarker
RE: Inserting data into database in liferay
February 4, 2013 8:48 PM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

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
RE: Inserting data into database in liferay
February 4, 2013 8:36 PM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

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!!