掲示板

Can't get actions to work in Liferay Faces

9年前 に Chris Dailey によって更新されました。

Can't get actions to work in Liferay Faces

Junior Member 投稿: 30 参加年月日: 14/11/24 最新の投稿
We are having issues with trying to use Liferay Faces along with any JSF components to fire action events.

I've gone through the first part of the "Developing JSF Portlets" instruction page up until the Internationalize JSF Portlets section with success. I went ahead and added some other JSF components with some success as well, however, events are not working.

The goal is to have a text box where the user can change the default text of "World", and a text area will update by AJAX on every keystroke with "Hello, XXX" (where XXX is the text from the box).

I am getting a postback to the server. The DebugPhaseListener is resulting in only BEFORE/AFTER RESTORE_VIEW 1, and BEFORE/AFTER RENDER_RESPONSE 6. There are no phases in between, which I presume is part of the problem.

Here are all of the assets and code that I think are relevant to figure out what is going on. Any help you can give would be greatly appreciated.

UPDATED: Using Liferay 6.2, running in Eclipse with the latest Tomcat bundle and latest eclipse plugin from the liferay update site. Java 1.7.0_71.
UPDATED 2: Yes, I have tried out the view.xhtml and TestBean.java in a separate JSF project and it works.

view.xhtml:

<!--?xml version="1.0"?-->

<f:view xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui">
	<h:head />
	<h:body>
		<h:form id="someForm">
			<p:calendar id="myCal" mode="inline" value="#{testBean.myDate}" actionlistener="#{testBean.updateDate}">
				<p:ajax actionListener="#{testBean.updateDate}" update="myMsgs" />
			</p:calendar>
			<br>
			<p:commandbutton value="Hi there" actionListener="#{testBean.updateDate}" update="myMsgs" />
			<br>
			<p:messages id="myMsgs" />
			<br>
			Test String=#{testBean.testString}
			<br>
			Output Text test string = <h:outputtext value="#{testBean.testString}" />


			<h:outputlabel value="Name" for="nameInput" />
			<h:inputtext id="nameInput" value="#{testBean.name}">
				<f:ajax render="output" event="keyup" />
			</h:inputtext>
			<br>

			<p>
				<h:panelgroup id="output">
					<strong> <h:outputtext value="Hello, #{testBean.name}" />
					</strong>
				</h:panelgroup>
			</p>

			<h:commandbutton id="reset" value="Reset" actionlistener="#{testBean.reset}">
				<f:ajax render="@form" />
			</h:commandbutton> - Reset The Form to "World"
			<br>

			<h:messages />

		</h:form>
	</h:body>
</f:view>


TestBean.java

import java.io.Serializable;
import java.util.Date;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;


@ManagedBean(name="testBean")
@SessionScoped
public class TestBean
	implements Serializable
{
	private static final long serialVersionUID = 1L;

	public String getTestString()
	{
		return "Test String";
	}

	private Date myDate = new Date();
	public Date getMyDate() { return myDate; }
	public void setMyDate(Date value) { System.out.println("setMyDate value="+value); myDate = value; }

	public void updateDate()
	{
		System.out.println("updateDate - myDate="+myDate);
	}

	/**
	 * Stores the name which will be used to greet the application user.
	 */
	private String name;

	/**
	 * Initializes {@link #name} with the value {@code "World"}.
	 */
	@PostConstruct
	public void postContruct()
	{
		this.name = "World";
	}

	/**
	 * Returns {@link #name}.
	 *
	 * @return {@link #name}
	 */
	public String getName()
	{
		return name;
	}

	/**
	 * Set {@link #name}.
	 *
	 * @param value
	 */
	public void setName(String value)
	{
		System.out.println("Setting name to " + value);
		name = value;
	}

	/**
	 * Resets {@link #name} to the default value {@code "World"}.
	 *
	 * @param ae
	 * ignored
	 */
	public void reset(ActionEvent ae)
	{
		setName("World");
	}
}


portlet.xml
<!--?xml version="1.0"?-->

<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0">
	
	<portlet>
		<portlet-name>my-calendar-portlet</portlet-name>
		<display-name>My Calendar Portlet</display-name>
		<portlet-class>
			javax.portlet.faces.GenericFacesPortlet
		</portlet-class>
		<init-param>
			<name>javax.portlet.faces.defaultViewId.view</name>
			<value>/views/my-calendar-portlet/view.xhtml</value>
		</init-param>
		<init-param>
			<name>javax.portlet.faces.defaultViewId.edit</name>
			<value>/views/my-calendar-portlet/edit.xhtml</value>
		</init-param>
		<expiration-cache>0</expiration-cache>
		<supports>
			<mime-type>text/html</mime-type>
			<portlet-mode>view</portlet-mode>
			<portlet-mode>edit</portlet-mode>
		</supports>
		<portlet-info>
			<title>My Calendar Portlet</title>
			<short-title>My Calendar Portlet</short-title>
			<keywords></keywords>
		</portlet-info>
		<security-role-ref>
			<role-name>administrator</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>guest</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>power-user</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>user</role-name>
		</security-role-ref>
	</portlet>
</portlet-app>


liferay-portlet
<!--?xml version="1.0"?-->


<liferay-portlet-app>
	
	<portlet>
		<portlet-name>my-calendar-portlet</portlet-name>
		<icon>/icon.png</icon>
		<header-portlet-css>/css/main.css</header-portlet-css>
		<footer-portlet-javascript>
			/js/main.js
		</footer-portlet-javascript>
		<css-class-wrapper>
			my-calendar-portlet-portlet
		</css-class-wrapper>
	</portlet>
	<role-mapper>
		<role-name>administrator</role-name>
		<role-link>Administrator</role-link>
	</role-mapper>
	<role-mapper>
		<role-name>guest</role-name>
		<role-link>Guest</role-link>
	</role-mapper>
	<role-mapper>
		<role-name>power-user</role-name>
		<role-link>Power User</role-link>
	</role-mapper>
	<role-mapper>
		<role-name>user</role-name>
		<role-link>User</role-link>
	</role-mapper>
</liferay-portlet-app>


Debug output from each key pressed:

22:18:22,328 DEBUG [DebugPhaseListener:64] BEFORE phaseId=[RESTORE_VIEW 1] viewId=[null]
22:18:22,328 DEBUG [DebugPhaseListener:48] AFTER phaseId=[RESTORE_VIEW 1] viewId=[/views/my-calendar-portlet/view.xhtml]
22:18:22,328 DEBUG [DebugPhaseListener:64] BEFORE phaseId=[RENDER_RESPONSE 6] viewId=[/views/my-calendar-portlet/view.xhtml]
22:18:22,338 DEBUG [DebugPhaseListener:48] AFTER phaseId=[RENDER_RESPONSE 6] viewId=[/views/my-calendar-portlet/view.xhtml]
thumbnail
9年前 に Neil Griffin によって更新されました。

RE: Can't get actions to work in Liferay Faces

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

I am not certain but this might be caused by FACES-1993. For now, I recommend that you try removing the paragraph that surrounds the h:panelGroup component tag:

<p>...</p>

And then try this:

<f:ajax render=":someForm:output" event="keyup" />


Kind Regards,

Neil
9年前 に Chris Dailey によって更新されました。

RE: Can't get actions to work in Liferay Faces

Junior Member 投稿: 30 参加年月日: 14/11/24 最新の投稿
Hi, Neil,

Thanks for the response (which you were also kind enough to post on stackoverflow, where I posted there because this post was marked as spam and the long US Thanksgiving holiday delayed administrators from clearing it).

As I said on stackoverflow, the changes you suggested did not seem to fix the issue. I also tried using p:ajax, but to no avail.

Given my experience with JSF, I'm confident the Bean and .xhtml file are correct. I'm thinking the problem is either in the Liferay faces bridge itself or there is some configuration item I am missing somewhere. Being new to Liferay, I have no idea where to look.
thumbnail
9年前 に Neil Griffin によって更新されました。

RE: Can't get actions to work in Liferay Faces

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

If it is OK with you, let's keep the conversation going here in the Liferay Faces forums. I should have some time later today to take a closer look. I'll get back to you.

Kind Regards,

Neil
9年前 に Chris Dailey によって更新されました。

RE: Can't get actions to work in Liferay Faces

Junior Member 投稿: 30 参加年月日: 14/11/24 最新の投稿
Thanks, Neil! I'm attaching the project which lives under liferay-plugins-sdk-6.2\portlets if that helps to make sure working on the same code. The view in question is under docroot/view/my-calendar-portlet, and it currently has p:ajax instead of f:ajax but you can easily switch it back.

Regards,
Chris

添付ファイル:

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

RE: Can't get actions to work in Liferay Faces (回答)

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

I found the problem -- the <portlet>...</portlet> section of your WEB-INF/liferay-portlet.xml descriptor was missing some entries. When I changed it to look like this:

    <portlet>
        <portlet-name>my-calendar-portlet</portlet-name>
        <icon>/icon.png</icon>
        <instanceable>true</instanceable>
        <remoteable>true</remoteable>
        <requires-namespaced-parameters>false</requires-namespaced-parameters>
        <ajaxable>false</ajaxable>
        <header-portlet-css>/css/main.css</header-portlet-css>
        <footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
        <css-class-wrapper>my-calendar-portlet-portlet</css-class-wrapper>
    </portlet>


... then it started working. emoticon

The problem stems from the fact that our Ivy project templates are missing the ajaxable and requires-namespaced-parameters elements. So every time a new project is created, they need to be added.

If you are using Liferay IDE to develop your portlets, then a potential workaround for this bug should be found in verson 2.0.1 (and higher) of Liferay IDE, as documented in IDE-1389. As of the time of this writing, the latest version of Liferay IDE is 2.2.1, as documented in a recent blog post by Greg Amerson.

Kind Regards,

Neil
9年前 に Chris Dailey によって更新されました。

Working!

Junior Member 投稿: 30 参加年月日: 14/11/24 最新の投稿
Hey, it's working! There is much dancing going on here!

The other thing we had on that page was a button that when clicked would display the current date selected in the calendar, and that worked, as well!

I also changed the calendar tag to look like this:
<p:calendar id="myCal" mode="inline" value="#{testBean.myDate}">
	<p:ajax event="dateSelect" listener="#{testBean.updateDate}" update="myMsgs" />
</p:calendar>

and added the output of myDate:
<h:panelgroup id="myMsgs">
	#{testBean.myDate}
</h:panelgroup>


Thank you so much for seeing this through with me, Neil!

The version of Liferay IDE I have installed is 2.2.1.201411200728-ga2, and Eclipse is Luna 4.4.1, so I am installed the E4 RCP Patch in Eclipse. Thanks for the links, as well.
thumbnail
9年前 に Neil Griffin によって更新されました。

RE: Working!

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

It was my pleasure -- so glad to hear that it is working for you now. Thanks for hanging in there and for using Liferay Faces. emoticon

Kind Regards,

Neil