Integrate Jsf application into Liferay

流过昼夜 提交于 2019-12-08 09:19:29

问题


I am developing a JSF 2.0 (with primefaces 3.2) application, and I want to integrate my JSF application inside Liferay. I am new to Liferay and the requirement is that the application will have entrance through Liferay.

That means User will login, which should happen through Liferay. Then as I have seen in liferay basic videos after login in liferay 'Liferayhomepage' comes.

Now please guide me, inside that homepage or after login I should be able to see a JSF application that I am developing, (you can say my application will be a portlet inside liferay) right? and should be able to navigate according to 'roles' that you have applied in Liferay. How can I do that?

Second question is once I have entered inside my JSF aplication, definitely I will need 'userId' which will be unique, to perform insertion and retrieval of data from database. How can I use it inside my JSF applcation? If anybody can explain with a simple example, it will be really helpful, as this is the point where I am stuck. Please help me out.

In short is it possible to call separate JSF application through liferay? here I am giving entrance through liferay because liferay provides "roles", so that once the logs in through liferay he should be able to enter my JSF application based on the roles (like admin, power user etc..) (This is what exactly I want to do)

Please let me know if anybody needs more clarification on my question.


回答1:


as Mark already mentioned you can find jsf portlet examples (also with primefaces) here http://www.liferay.com/community/liferay-projects/liferay-faces/demos

inside your jsf portlet you can get the user object (containing the roles) by this way:

public static User getCurrentUser(){
    User u = null;
    FacesContext fc = FacesContext.getCurrentInstance();
    ExternalContext externalContext = fc.getExternalContext();
    if (externalContext.getUserPrincipal() != null) {
        Long id = Long.parseLong(externalContext.getUserPrincipal().getName());
        try {
            u = UserLocalServiceUtil.getUserById(id);
        }
        catch (Exception ex) {
            LOG.error(ex.getMessage());
        }
    }
    return u;
}



回答2:


Install Liferay IDE and its help you to create simple JSF-2 Portlet. You found some examples at portletfaces page http://www.portletfaces.org/projects/portletfaces-bridge/liferay-ide

fyi portlet-faces is now liferay-faces: http://www.portletfaces.org/projects/liferayfaces




回答3:


You should get the Liferay IDE and create a new project File->New->Liferay Project. Then select Portlet give the project a name and Display name

then select JSF2.x and PrimeFaces

You should end up with something like:

you add portlets by adding information in liferay-display.xml, liferay-portlet.xml, and portlet.xml. portlet.xml will map the jsf page to the portlet view

    <init-param>
    <name>javax.portlet.faces.defaultViewId.view</name>
    <value>/views/view.xhtml</value>
    </init-param>


来源:https://stackoverflow.com/questions/10257967/integrate-jsf-application-into-liferay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!