Foros de discusión

using service module in faces portlet

Mohammad Bagheri, modificado hace 6 años.

using service module in faces portlet

New Member Mensajes: 6 Fecha de incorporación: 9/05/17 Mensajes recientes
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
Neil Griffin, modificado hace 6 años.

RE: using service module in faces portlet

Liferay Legend Mensajes: 2655 Fecha de incorporación: 27/07/05 Mensajes recientes
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
Mohammad Bagheri, modificado hace 6 años.

RE: using service module in faces portlet

New Member Mensajes: 6 Fecha de incorporación: 9/05/17 Mensajes recientes
Hi Neil

Thanks for your reply.emoticon

ServiceBuilder modules and JSF portlet module Attached.
thumbnail
Neil Griffin, modificado hace 6 años.

RE: using service module in faces portlet

Liferay Legend Mensajes: 2655 Fecha de incorporación: 27/07/05 Mensajes recientes
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
Neil Griffin, modificado hace 6 años.

RE: using service module in faces portlet

Liferay Legend Mensajes: 2655 Fecha de incorporación: 27/07/05 Mensajes recientes
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
Mohammad Bagheri, modificado hace 6 años.

RE: using service module in faces portlet

New Member Mensajes: 6 Fecha de incorporación: 9/05/17 Mensajes recientes
Hi Neil!

Sorry for the late reply, and thank you for responding so quickly.
IT WORKS LIKE A CHARM.emoticon
thumbnail
Neil Griffin, modificado hace 6 años.

RE: using service module in faces portlet

Liferay Legend Mensajes: 2655 Fecha de incorporación: 27/07/05 Mensajes recientes
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