掲示板

RE: How to Changing JSF portlet View Page in doView or in any managed Bean

11年前 に Muhammad Taha によって更新されました。

How to change JSF portlet view in doView

Junior Member 投稿: 63 参加年月日: 12/05/01 最新の投稿
I have two portlets, I'm triggering IPC event from portlet1's managed bean, able to get that in portlet 2 (target) action class, in order to display that value target portlets view, putting the value received from portlet1 in portlet session and again reading it in getter method of one the managed bean, I am also able to display that value in the default view of target portlet (i.e view.xhtml) , But how can i display that value in another page i.e. view2.xhtml.
thumbnail
11年前 に David H Nebinger によって更新されました。

RE: How to Changing JSF portlet View Page in doView or in any managed Bean (回答)

Liferay Legend 投稿: 14914 参加年月日: 06/09/02 最新の投稿
Portlets have different portlet sessions. The session for portlet 1 is not the same as the session for portlet 2.

You need to find another mechanism (i.e. portlet IPC, etc.) to transfer the value.
11年前 に Muhammad Taha によって更新されました。

RE: How to Changing JSF portlet View Page in doView or in any managed Bean

Junior Member 投稿: 63 参加年月日: 12/05/01 最新の投稿
inside portlet1 .xhtml file

<h:inputText value="#{helloBean.name}"></h:inputText>
<h:commandButton action="#{helloBean.set}" value="Add Entry" />

inside portlet1 managed bean

public void set(){
QName qName = new QName("http://liferay.com", "empinfo", "x");
ActionResponse response = (ActionResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
response.setEvent(qName, name);
}

inside portlet 2 action

public void processEvent(EventRequest request, EventResponse response)throws PortletException, IOException {
Event event = request.getEvent();
String value = (String) event.getValue();
request.getPortletSession().setAttribute("myvalue", value);
}

inside portlet 2 bean (some IpcBean)

public String ipcValue() {
PortletRequest req = (PortletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
String myvalue=(String)req.getPortletSession().getAttribute("myvalue");
return myvalue;
}

inside portlet 2 view.xhtml

<h4>Welcome #{ipcBean.ipcValue()}</h4>

Its working for me.. I want to get value in some other eg. view2.xhtml....
thumbnail
11年前 に Neil Griffin によって更新されました。

RE: How to Changing JSF portlet View Page in doView or in any managed Bean

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
When you wrote:

I want to get value in some other eg. view2.xhtml


Do you mean that, when an event occurs, that you want to navigate from view1.xhtml to view2.xhtml and then display the received event payload in view2.xhtml?
11年前 に Muhammad Taha によって更新されました。

RE: How to Changing JSF portlet View Page in doView or in any managed Bean

Junior Member 投稿: 63 参加年月日: 12/05/01 最新の投稿
Yes Neil.. U r correct...
thumbnail
11年前 に Neil Griffin によって更新されました。

RE: How to Changing JSF portlet View Page in doView or in any managed Bean (回答)

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
I would recommend that you look at the jsf2-ipc-events-customers-portlet and jsf2-ipc-events-bookings-portlet demo portlets. They are designed to be used together on the same portal page. When you click on a customer in the customers portlet, it sends an event that is received by the bookings portlet. The bookings portlet then triggers a navigation-rule to fire because of the CustomerSelectedEventHandler.java class. This is a JSR 329 standard feature.
11年前 に Muhammad Taha によって更新されました。

RE: How to Changing JSF portlet View Page in doView or in any managed Bean

Junior Member 投稿: 63 参加年月日: 12/05/01 最新の投稿
Im unable to post new thread using my network....

How to change portlet page using a hidden method (<h:inputHidden > )... waiting for ur reply...
thumbnail
11年前 に Neil Griffin によって更新されました。

RE: How to Changing JSF portlet View Page in doView or in any managed Bean

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

When you wrote:
How to change portlet page


Do you mean navigating to a different JSF view within the same portlet, or navigating to a totally different Liferay Portal page URL? Also, is this still related to Events IPC?

Thanks,

Neil
11年前 に Muhammad Taha によって更新されました。

RE: How to Changing JSF portlet View Page in doView or in any managed Bean

Junior Member 投稿: 63 参加年月日: 12/05/01 最新の投稿
its different JSF view within the same portlet. When IPC Event is recieved it has to display a different page instead of page defined in portlet.xml
thumbnail
11年前 に Neil Griffin によって更新されました。

RE: How to Changing JSF portlet View Page in doView or in any managed Bean

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
Did you get an opportunity to try the jsf2-customers-portlet and jsf2-bookings-portlet that I mentioned earlier in this thread? The bookings portlet shows how to execute a navigation-rule -- I think this might be a good match for your requirement of navigating to a different JSF view when the event occurs.
11年前 に Muhammad Taha によって更新されました。

RE: How to Changing JSF portlet View Page in doView or in any managed Bean

Junior Member 投稿: 63 参加年月日: 12/05/01 最新の投稿
Thanks Neil & David. Its done. I've downloaded bookings-portlet using another network..
Im able to do with following code

In porltlet.xml

<init-param>
<name>javax.portlet.faces.bridgeEventHandler</name>
<value>EventHandler</value>
</init-param>

<init-param>
<name>com.liferay.faces.bridge.preferPreDestroy</name>
<value>false</value>
</init-param>

In EventHandler.java

public class EventHandler implements BridgeEventHandler{

public EventNavigationResult handleEvent(FacesContext facesContext, Event event) {
EventNavigationResult eventNavigationResult = null;
String eventName = event.getName().toString();

if (eventName.equals("applicationtrackingnumber")) {

String value=(String) event.getValue();
TargetMO targetMO= getTargetMO(facesContext);

targetMO.setValue(value);

String fromAction = null;
String outcome = "ipc.customerSelected";
eventNavigationResult = new EventNavigationResult(fromAction, outcome);
}

return eventNavigationResult;
}

protected TargetMO getTargetMO(FacesContext facesContext) {

String elExpression = "#{targetMO}";
ELContext elContext = facesContext.getELContext();
ValueExpression valueExpression = facesContext.getApplication().getExpressionFactory().createValueExpression(
elContext, elExpression, TargetMO.class);
return (TargetMO) valueExpression.getValue(elContext);
}
}

in FacesConfig.xml

<navigation-rule>
<navigation-case>
<from-outcome>ipc.customerSelected</from-outcome>
<to-view-id>/views/success.xhtml</to-view-id>
</navigation-case>
</navigation-rule>

Thanks.
11年前 に Muhammad Taha によって更新されました。

RE: How to change JSF portlet view in doView

Junior Member 投稿: 63 参加年月日: 12/05/01 最新の投稿
Hi Neil,

Navigation is working when both source and target portlets are on same page. but when the target portlet is on another page (layout), Eventhandler is invoking but page navigation is not happening.

In source portlet im redirecting and setting event with the follow code

externalContext.redirect(portletURL.toString());
response.setEvent(qNameAppTrackingNumber, applicationTrackingNumber);
thumbnail
11年前 に Neil Griffin によって更新されました。

RE: How to Changing JSF portlet View Page in doView or in any managed Bean

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
Do you have the portlet.event.distribution property set to layout-set in your portal-ext.properties file?

Here is a description from the portal.properties file. Note that a "layout" means a portal page within a site, and "layout-set" means all portal pages within a site.
    #
    # Set this property to specify how events are distributed. If the value is
    # "layout-set", then events will be distributed to all portlets contained in
    # a layout set. If the value is "layout", then events will be distributed to
    # all portlets that are present in a layout.
    #
    portlet.event.distribution=layout-set


Also, the following need to be set in order for the layout-set distribution feature to work:

layout.default.p_l_reset=false
tags.compiler.enabled=false
11年前 に Muhammad Taha によって更新されました。

RE: How to Changing JSF portlet View Page in doView or in any managed Bean

Junior Member 投稿: 63 参加年月日: 12/05/01 最新の投稿
yes i've already set that. but I don't know why its not working...
thumbnail
11年前 に Neil Griffin によって更新されました。

RE: How to Changing JSF portlet View Page in doView or in any managed Bean

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
I have reproduced the problem and just created FACES-1465 in order to track it to closure. Please click on the "watch" link in JIRA in order to stay informed on progress.
thumbnail
11年前 に Neil Griffin によって更新されました。

RE: How to Changing JSF portlet View Page in doView or in any managed Bean

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
This issue is now fixed and will appear in the GA3 release of Liferay Faces. See FACES-1465 for more info.
11年前 に Muhammad Taha によって更新されました。

RE: How to Changing JSF portlet View Page in doView or in any managed Bean

Junior Member 投稿: 63 参加年月日: 12/05/01 最新の投稿
I tried with EventPayloadWrapper ..but portlet page is not navigating after portal page redirect.

Do I need to wait for latest version of bridge-impl jar ?
thumbnail
11年前 に Neil Griffin によって更新されました。

RE: How to Changing JSF portlet View Page in doView or in any managed Bean

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
You would have to use liferay-faces-bridge-impl-3.1.2-ga3-SNAPSHOT.jar in order for it to work.

For testing in your environment, I would recommend that you download version 3.1.2-ga3-SNAPSHOT of the jsf2-ipc-events-customers-portlet and jsf2-ipc-events-bookings-portlet from the snapshot repository.
11年前 に Muhammad Taha によって更新されました。

RE: How to Changing JSF portlet View Page in doView or in any managed Bean

Junior Member 投稿: 63 参加年月日: 12/05/01 最新の投稿
Now its working for me Neil...emoticon
I had to use liferay-faces-util-3.1.2-ga3-SNAPSHOT.jar, liferay-faces-bridge-api-3.1.2-ga3-SNAPSHOT.jar along with liferay-faces-bridge-impl-3.1.2-ga3-SNAPSHOT.jar.

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

RE: How to Changing JSF portlet View Page in doView or in any managed Bean

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
I'm so glad to hear that it's working emoticon

Regarding getting the portal page, there is a contextual class called ThemeDisplay that has lots of getter methods on it that will help you.

You can get it like this in a backing bean:
FacesContext facesContext = FacesContext.getCurrentInstance();
ThemeDisplay themeDisplay = (ThemeDisplay) facesContext.getExternalContext.getRequestMap().get(WebKeys.THEME_DISPLAY);


Or if you are using the liferay-faces-portal.jar dependency, you can do this:
LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
ThemeDisplay themeDisplay = liferayFacesContext.getThemeDisplay();


In order to get the base URL for the portal, you can call methods like PortalUtil.getPortalURL(PortletRequest);
11年前 に Muhammad Taha によって更新されました。

RE: How to Changing JSF portlet View Page in doView or in any managed Bean

Junior Member 投稿: 63 参加年月日: 12/05/01 最新の投稿
Thanks Neil.
thumbnail
11年前 に Neil Griffin によって更新されました。

RE: How to Changing JSF portlet View Page in doView or in any managed Bean

Liferay Legend 投稿: 2655 参加年月日: 05/07/27 最新の投稿
My pleasure.