掲示板

using service module in faces portlet

6年前 に Mohammad Bagheri によって更新されました。

using service module in faces portlet

New Member 投稿: 6 参加年月日: 17/05/09 最新の投稿
I want to create faces portlet(CDI) and use profservice module that I was created.
I can't create faces portlet in liferay workspace.
I was forced create faces portlet out of liferay workspace and add this line to build.gradle(relative path):
compile files('../LiferayWork/modules/profservice/profservice-api/build/libs/com.prof.demo.api-1.0.0.jar') 

when build my project I get this error
class file for com.liferay.portal.kernel.model.BaseModel not found

I was forced add this dependencies:
compileOnly group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "3.1.0"
compileOnly group: "com.liferay", name: "com.liferay.osgi.util", version: "3.0.0"
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"
compileOnly group: "org.osgi", name: "org.osgi.core", version: "6.0.0"


TestBean:
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import com.prof.demo.model.Prof;
import com.prof.demo.service.ProfLocalService;

@Named
@SessionScoped
public class TestBean implements Serializable {

	private ProfLocalServiceTracker profLocalServiceTracker;
	private ProfLocalService profLocalService;
	private String name;

	@PostConstruct
	public void postConstruct() {
		Bundle bundle = FrameworkUtil.getBundle(this.getClass());
		BundleContext bundleContext = bundle.getBundleContext();
		profLocalServiceTracker = new ProfLocalServiceTracker(bundleContext);
		profLocalServiceTracker.open();
	}

	@PreDestroy
	public void preDestroy() {
		profLocalServiceTracker.close();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void doTest() {
		try {		
			if (!profLocalServiceTracker.isEmpty()) {
				profLocalService = profLocalServiceTracker.getService();
				Prof prof = profLocalService.createProf(5);
				prof.setName("mahdi");
				profLocalService.addProf(prof);
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}
}


ProfLocalServiceTracker:
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import com.prof.demo.service.ProfLocalService;

public class ProfLocalServiceTracker extends ServiceTracker<proflocalservice, proflocalservice> {

	public ProfLocalServiceTracker(BundleContext bundleContext) {
		super(bundleContext, ProfLocalService.class, null);
	}
}
</proflocalservice,>

I follow steps in https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/services-in-jsf and follow instructions.
build my project successfully. but when deploy my project I get this error:
com.sun.proxy.$Proxy503 cannot be cast to com.prof.demo.service.ProfLocalService

how to resolve this problem?
thumbnail
6年前 に Neil Griffin によって更新されました。

RE: using service module in faces portlet

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
Hi Mohammad,

Thank you for providing the code samples in your post. They were helpful, but it would be even better if you could attach the full project source for your ServiceBuilder modules and your JSF portlet module. That way we can build the projects locally and try to reproduce the problem.

Kind Regards,

Neil
6年前 に Mohammad Bagheri によって更新されました。

RE: using service module in faces portlet

New Member 投稿: 6 参加年月日: 17/05/09 最新の投稿
Hi Neil

Thanks for your reply.emoticon

ServiceBuilder modules and JSF portlet module Attached.
thumbnail
6年前 に Neil Griffin によって更新されました。

RE: using service module in faces portlet

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
Hi Mohammad,

Thanks for attaching the full project source. Rather than try to fix what might be incorrect, I decided to study the code and re-create it using Liferay IDE 3.1.0 Beta1, which has improved support for creating JSF portlet projects.

I was able to create a working project, and I have attached the source code to this message. Please let me know if you have any questions.

Kind Regards,

Neil

添付ファイル:

thumbnail
6年前 に Neil Griffin によって更新されました。

RE: using service module in faces portlet

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
Hi Mohammad,

I just realized that there is a small change I should have made in the source I attached.

In profservice/profservice-service/src/main/java/com/prof/demo/service/impl/FooLocalServiceImpl.java you will find this method:
public long incrementCounter() {
	return counterLocalService.increment();
}


Instead, it should be a method that looks like this example.

The reason why, is because methods that are prefixed with "add*" are automatically made part of transactional boundaries (at least, that is my recollection).

If you add methods to FooLocalServiceImpl.java and then re-build the services, the FooLocalService.java API will be auto-generated. The ServiceBuilder code generator does this by reverse engineering the implementation.

Kind Regards,

Neil
6年前 に Mohammad Bagheri によって更新されました。

RE: using service module in faces portlet

New Member 投稿: 6 参加年月日: 17/05/09 最新の投稿
Hi Neil!

Sorry for the late reply, and thank you for responding so quickly.
IT WORKS LIKE A CHARM.emoticon
thumbnail
6年前 に Neil Griffin によって更新されました。

RE: using service module in faces portlet

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
Hi Mohammad,

It was my pleasure -- thanks for letting us know that it is working for you, and thanks for using Liferay Faces emoticon

Neil