Foros de discusión

error while calling method to insert data in custom portlet

thumbnail
Bhavik Kama, modificado hace 11 años.

error while calling method to insert data in custom portlet

Junior Member Mensajes: 55 Fecha de incorporación: 24/09/12 Mensajes recientes
Hi, I am using my custom portlet to add some data with the adAdvertise method of localserviceimpl and in my portlet class i have define addAdvertise.

i get following error while calling this addadvertise method

06:39:47,761 ERROR [http-bio-8080-exec-92][render_portlet_jsp:154] java.lang.NullPointerException
at com.advertise.database.service.impl.advertiseLocalServiceImpl.adAdvertise(advertiseLocalServiceImpl.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:122)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:71)
at com.liferay.portal.dao.jdbc.aop.DynamicDataSourceTransactionInterceptor.invoke(DynamicDataSourceTransactionInterceptor.java:44)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.security.pacl.PACLAdvice.invoke(PACLAdvice.java:51)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:211)
at com.advertise.database.service.advertiseLocalServiceUtil.adAdvertise(advertiseLocalServiceUtil.java:278)
at com.advertise.portlet.AdvertisePortlet.addAdvertise(AdvertisePortlet.java:36)

What is this error s about??i cant find out..please anyone can guide me?
thumbnail
Vishal Panchal, modificado hace 11 años.

RE: error while calling method to insert data in custom portlet

Expert Mensajes: 289 Fecha de incorporación: 20/05/12 Mensajes recientes
Bhavik Kama:
Hi, I am using my custom portlet to add some data with the adAdvertise method of localserviceimpl and in my portlet class i have define addAdvertise.

i get following error while calling this addadvertise method

06:39:47,761 ERROR [http-bio-8080-exec-92][render_portlet_jsp:154] java.lang.NullPointerException
at com.advertise.database.service.impl.advertiseLocalServiceImpl.adAdvertise(advertiseLocalServiceImpl.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:122)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:71)
at com.liferay.portal.dao.jdbc.aop.DynamicDataSourceTransactionInterceptor.invoke(DynamicDataSourceTransactionInterceptor.java:44)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:57)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.security.pacl.PACLAdvice.invoke(PACLAdvice.java:51)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:118)
at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:211)
at com.advertise.database.service.advertiseLocalServiceUtil.adAdvertise(advertiseLocalServiceUtil.java:278)
at com.advertise.portlet.AdvertisePortlet.addAdvertise(AdvertisePortlet.java:36)

What is this error s about??i cant find out..please anyone can guide me?



Hi Bhavik Kama,

we should not call the methods directly using localserviceimpl class, instead We should call them using LocalServiceUtil class.
So try the same using AdvertiseLocalServiceUtil.addAdvertise();

Thanks &Regards,
Vishal R. Panchal
thumbnail
Bhavik Kama, modificado hace 11 años.

RE: error while calling method to insert data in custom portlet

Junior Member Mensajes: 55 Fecha de incorporación: 24/09/12 Mensajes recientes
ya.i had done that same ..let me give u three class information
this is my advertiseLocalServiceUtil Class
public static com.advertise.database.model.advertise addadvertise(
com.advertise.database.model.advertise advertise)
throws com.liferay.portal.kernel.exception.SystemException {
return getService().addadvertise(advertise);
}


this is my LocalServiceImpl class

public advertise adAdvertise(advertise adsParam) {
advertise adVar;

try {
adVar =advertisePersistence.create(counterLocalService
.increment(advertise.class.toString()));
} catch (SystemException e) {
e.printStackTrace();
return adVar = null;
}

try {
resourceLocalService.addResources(adsParam.getCompanyId(),
adsParam.getGroupId(), adsParam.getUserId(),
advertise.class.getName(), adsParam.getPrimaryKey(),false,
true, true);
} catch (PortalException e) {
e.printStackTrace();
return adVar = null;
} catch (SystemException e) {
e.printStackTrace();
return adVar = null;
}

adVar.setTitle(adsParam.getTitle());
adVar.setCompanyId(adsParam.getCompanyId());
adVar.setTypeId(adsParam.getTypeId());

adVar.setGroupId(adsParam.getGroupId());
adVar.setDescription(adsParam.getDescription());
adVar.setUserId(adsParam.getUserId());

try {
return advertisePersistence.update(adVar, false);
} catch (SystemException e) {
e.printStackTrace();
return adVar = null;
}
}
This is my Portlet class
public void addAdvertise(ActionRequest request, ActionResponse response)
{
log.info("Ad portlet addAdvertise calling");
List<String> errors=new ArrayList<String>();
advertise ad=AdvertiseActionUtil.getAdvertiseFromRequest(request);

//boolean adValid=AdvertiseValidator.validateAdvertise(ad, errors);
//if(adValid) {
log.info(ad);
advertise adtest=advertiseLocalServiceUtil.adAdvertise(ad);
if(adtest==null) {
log.error("Ad was Found Null");
response.setRenderParameter("jspPage", errorJSP);
return ;
}
SessionMessages.add(request,"ad-added");
return ;
//}
//else {
// for (String error : errors) {
// SessionErrors.add(request, error);
// }
// SessionErrors.add(request, "error-while-adding");
// request.setAttribute("ad",ad);
// return ;
}


And in my view file i am calling this function as follows

<%@ include file="/init.jsp"%>
<%
advertise ad = (advertise) request.getAttribute("advertise");
if (ad == null) {
ad = new advertiseImpl();

ad.setAdvertiserId(1);

}
%>
<liferay-portlet:actionURL name="addAdvertise" var="addAdvertiseURL"></liferay-portlet:actionURL>
<liferay-ui:success key="ad-added" message="ad-added" />


<aui:form action="<%=addAdvertiseURL.toString() %>" method="post" name="fm">

<aui:fieldset>

<p>
<aui:input name="title" label="Title" type="text"
value="<%=ad.getTitle() %>"></aui:input>
</p>

<p>
<aui:input name="description" label="Description" type="text"
value="<%=ad.getDescription() %>"></aui:input>
</p>


<p>
<aui:input name="typeId" label="TypeId" type="text"
value="<%=String.valueOf(ad.getTypeId()) %>"></aui:input>
</p>
<p>
<aui:input type="file" name="UploadAdvertise" size="25"/>
<p>


<select name="ADvertise TYPE">
<option value="">-------Select-----</option>
<%
List<type> list=typeLocalServiceUtil.getAlltype();
for(type item:list){
%>



<option value="<%=item.getType_name()%>"></option>
<%
}

%>
</select>






<aui:button-row>
<p>
<aui:button class="aui-button-input" type="submit" value="Submit" />
<aui:button class="aui-button-input" type="reset" value="Reset" />
</p>
</aui:button-row>


</aui:fieldset>
</aui:form>

Please Tell me Where am doing mistake
Seeya S Kudtarker, modificado hace 11 años.

RE: error while calling method to insert data in custom portlet

Regular Member Mensajes: 187 Fecha de incorporación: 16/01/13 Mensajes recientes
Hi Bhavik Kama,
I am having the same problem. I am new to liferay here.

Here is my post...
Would you help me?

I do not know how to implement CRUDFromRequest(ActionRequest request) in the forum which I have mentioned..
thumbnail
Bhavik Kama, modificado hace 11 años.

RE: error while calling method to insert data in custom portlet

Junior Member Mensajes: 55 Fecha de incorporación: 24/09/12 Mensajes recientes
Seeya S Kudtarker:
Hi Bhavik Kama,
I am having the same problem. I am new to liferay here.

Here is my post...
Would you help me?

I do not know how to implement CRUDFromRequest(ActionRequest request) in the forum which I have mentioned..


I have Solved My Problem With The implementation suggested in this link..please Visit This Link it is very easy and in simple language...please give me feedback if u solved Ur problem from this link..thanx
http://liferay-by-akaram4u.blogspot.in/2012/05/service-builder-with-crud-operation-in.html

If you stil Dont Find solution then let me know
Seeya S Kudtarker, modificado hace 11 años.

RE: error while calling method to insert data in custom portlet

Regular Member Mensajes: 187 Fecha de incorporación: 16/01/13 Mensajes recientes
Bhavik Kama:
Seeya S Kudtarker:
Hi Bhavik Kama,
I am having the same problem. I am new to liferay here.

Here is my post...
Would you help me?

I do not know how to implement CRUDFromRequest(ActionRequest request) in the forum which I have mentioned..


I have Solved My Problem With The implementation suggested in this link..please Visit This Link it is very easy and in simple language...please give me feedback if u solved Ur problem from this link..thanx
http://liferay-by-akaram4u.blogspot.in/2012/05/service-builder-with-crud-operation-in.html

If you stil Dont Find solution then let me know


Hi Bhavik Kama,
Thanks for the link. Yes it helped me in adding the data to the database. I am having a little difficulty here in update and delete. I am trying it out and let you know if I get any difficulty. I will post my difficulties regarding them here in your forum..
thanks again for the link emoticon
Seeya S Kudtarker, modificado hace 11 años.

RE: error while calling method to insert data in custom portlet

Regular Member Mensajes: 187 Fecha de incorporación: 16/01/13 Mensajes recientes
Hi Bhavik Kama,

Thanks a lot for the link :
http://liferay-by-akaram4u.blogspot.in/2012/05/service-builder-with-crud-operation-in.html

It helped me a lot. The update and delete which wasn't working works now.

Thanks again!! All the CRUD operations are implemented properly. For retrieval of data I had to make modifications for which I got help in another forum.

Rest all operations mentioned in the link were simple and easy to understand. emoticon

Thanks!

Regards

Seeya
thumbnail
Bhavik Kama, modificado hace 11 años.

RE: error while calling method to insert data in custom portlet

Junior Member Mensajes: 55 Fecha de incorporación: 24/09/12 Mensajes recientes
Seeya S Kudtarker:
Hi Bhavik Kama,

Thanks a lot for the link :
http://liferay-by-akaram4u.blogspot.in/2012/05/service-builder-with-crud-operation-in.html

It helped me a lot. The update and delete which wasn't working works now.

Thanks again!! All the CRUD operations are implemented properly. For retrieval of data I had to make modifications for which I got help in another forum.

Rest all operations mentioned in the link were simple and easy to understand. emoticon

Thanks!

Regards

Seeya

...
Hmmm...i was having lots of problem to understand the structure of liferay for CRUD operation before visiting this link but after this link its all look like easy..anyways...your welcome...enjoy coding.i have send frend request to u ..pls accept it if u can on fb as well as here..
Seeya S Kudtarker, modificado hace 11 años.

RE: error while calling method to insert data in custom portlet

Regular Member Mensajes: 187 Fecha de incorporación: 16/01/13 Mensajes recientes
Thanks Bhavik.. I cannot see your friend request here in Liferay.. emoticon Anyway I will send you. You cancel it I will send you the request.

Btw I am having another problem here.
I am trying to define two entities n service.xml but only one table gets created in the database. Only the first entity gets created as table..
thumbnail
Bhavik Kama, modificado hace 11 años.

RE: error while calling method to insert data in custom portlet

Junior Member Mensajes: 55 Fecha de incorporación: 24/09/12 Mensajes recientes
Seeya S Kudtarker:
Thanks Bhavik.. I cannot see your friend request here in Liferay.. emoticon Anyway I will send you. You cancel it I will send you the request.

Btw I am having another problem here.
I am trying to define two entities n service.xml but only one table gets created in the database. Only the first entity gets created as table..


there should be two reason i guess..
1)..
u have any error in service.xml?
and if there is no error in service.xml and if u can successfully build the service the try following
2)....
if u created one entity and then builded the service and deploy the portlet then if u changing anythng in Service.xml then u should remove the portelt from server ..rebuild the service and then again deploy the portlet..try this...and let me know
Seeya S Kudtarker, modificado hace 11 años.

RE: error while calling method to insert data in custom portlet

Regular Member Mensajes: 187 Fecha de incorporación: 16/01/13 Mensajes recientes
Hey Bhavik,

I got my problem solved. I created a new project and typed the entire xml file again and it worked.
The entities got created.
But now I am having another problem. I am having mapping-key in one of the tables. The tables get created but they don't show the mapping-key column in the DDL definition.
What could be the problem?
thumbnail
Bhavik Kama, modificado hace 11 años.

RE: error while calling method to insert data in custom portlet

Junior Member Mensajes: 55 Fecha de incorporación: 24/09/12 Mensajes recientes
Seeya S Kudtarker:
Hey Bhavik,

I got my problem solved. I created a new project and typed the entire xml file again and it worked.
The entities got created.
But now I am having another problem. I am having mapping-key in one of the tables. The tables get created but they don't show the mapping-key column in the DDL definition.
What could be the problem?


I am Not aware of this scenario as i never implemented this mapping key concept in liferay....but if this link can help u...http://liferaydemystified.blogspot.jp/2011/08/table-relationships.html
Seeya S Kudtarker, modificado hace 11 años.

RE: error while calling method to insert data in custom portlet

Regular Member Mensajes: 187 Fecha de incorporación: 16/01/13 Mensajes recientes
Thanks Bhavik.. Will check n let you know.. emoticon Will figure out what happens and share it here.

btw could you help me with this link?

http://www.liferay.com/community/forums/-/message_boards/message/21395092
thumbnail
Bhavik Kama, modificado hace 11 años.

RE: error while calling method to insert data in custom portlet

Junior Member Mensajes: 55 Fecha de incorporación: 24/09/12 Mensajes recientes
Seeya S Kudtarker:
Thanks Bhavik.. Will check n let you know.. emoticon Will figure out what happens and share it here.

btw could you help me with this link?

http://www.liferay.com/community/forums/-/message_boards/message/21395092



I seen that link..but i think ur problem is solved in there??rig8?
Seeya S Kudtarker, modificado hace 11 años.

RE: error while calling method to insert data in custom portlet

Regular Member Mensajes: 187 Fecha de incorporación: 16/01/13 Mensajes recientes
Yes! emoticon emoticon
Thanks anyways!
I am not able to accept your request here in liferay. Will yo remove it so I will send you and you can accept..

Btw if you have any good tutorials on user groups and roles and how to assign permissions to users in liferay, it would be of help!

Thanks!

Regards
Seeya
Seeya S Kudtarker, modificado hace 11 años.

RE: error while calling method to insert data in custom portlet

Regular Member Mensajes: 187 Fecha de incorporación: 16/01/13 Mensajes recientes
kk.. Accpeted your request..
I would like to know about user roles in liferay
thumbnail
Bhavik Kama, modificado hace 11 años.

RE: error while calling method to insert data in custom portlet

Junior Member Mensajes: 55 Fecha de incorporación: 24/09/12 Mensajes recientes
Seeya S Kudtarker:
Yes! emoticon emoticon
Thanks anyways!
I am not able to accept your request here in liferay. Will yo remove it so I will send you and you can accept..

Btw if you have any good tutorials on user groups and roles and how to assign permissions to users in liferay, it would be of help!

Thanks!

Regards
Seeya


have u gone through with the liferay documentation about user roles and group ?
http://www.liferay.com/documentation/liferay-portal/6.1/user-guide/-/ai/lp-6-1-ugen12-user-groups-0 this the link
Seeya S Kudtarker, modificado hace 11 años.

RE: error while calling method to insert data in custom portlet

Regular Member Mensajes: 187 Fecha de incorporación: 16/01/13 Mensajes recientes
Thanks!

Will let you know once get it

Regards
Seeya
thumbnail
Hitoshi Ozawa, modificado hace 11 años.

RE: error while calling method to insert data in custom portlet

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
ad = new advertiseImpl();

ad.setAdvertiserId(1);


Liferay is using factory pattern (if you've read Gamma pattern book).
So, you don't do new, do ad = AdvertiseLocalServiceImpl.add(1);

You're suppose to add "add" method the the AdvertiseLocalServiceImpl class generated by the Service Builder.

If you don't know what I'm talking about, go through the following tutorial:
http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/service-build-5