掲示板

JSF Portlet Namespacing

9年前 に Roberfroid Vincent によって更新されました。

JSF Portlet Namespacing

New Member 投稿: 10 参加年月日: 14/05/26 最新の投稿
Hello,

We are using Liferay 6.2 with JSF 1.2 (Mojarra implementation) and the Bridge 2.2.4-ga5.
By default, Liferay only allows namespaced parameters to access portlets.

In the method init of PortletRequestImpl (in the portal-impl) we have :

        if ((invokerPortlet != null) &&
					invokerPortlet.isFacesPortlet()) {

					if (name.startsWith(portletNamespace) ||
						!portlet.isRequiresNamespacedParameters()) {

						dynamicRequest.setParameterValues(name, values);
					}
				}


As a consequence, the jsf view state parameter (javax.faces.ViewState that is not namespaced) is not set in the DynamicRequest.

Moreover, the isPostBack method of the ResponseStateManager of jsf check that the javax.faces.ViewState is present in the parameters:

              public boolean isPostback(FacesContext context) {
                             return context.getExternalContext().getRequestParameterMap().
                                      containsKey(ResponseStateManager.VIEW_STATE_PARAM);
                             }


As a consequence, the restore view phase of jsf assumes that the form has not been submitted.

The only solution to submit a form is so to set the parameter "requires-namespaced-parameters" to false in liferay-portlet.xml.

Does it exist a solution to submit a form by keeping namespacing in JSF 1.2 in Liferay?
A filter or a listener could be maybe provided in the bridge to prepend all parameters (and in particular javax.faces.ViewState) by the id of the active portlet.

Thanks in advance for your help,
Vincent
thumbnail
9年前 に Neil Griffin によって更新されました。

RE: JSF Portlet Namespacing (回答)

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

The results of your research is exactly correct.

Mojarra 2.1 has been patched via JAVASERVERFACES-3031 and Mojarra 2.2 via JAVASERVERFACES-3184 to support the following WEB-INF/web.xml parameter:

<context-param>
	<param-name>com.sun.faces.namespaceParameters</param-name>
	<param-value>true</param-value>
</context-param>


This will cause Mojarra 2.1/2.2 to prepend the portlet namespace to all its hidden fields and parameters, including javax.faces.ViewState.

However there is no backport for Mojarra 1.2 emoticon

Therefore the only way to get JSF 1.2 portlets to work correctly in Liferay Portal 6.2 is to specify the following in WEB-INF/liferay-portlet.xml:

<requires-namespaced-parameters>false</requires-namespaced-parameters>


Kind Regards,

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

RE: JSF Portlet Namespacing

New Member 投稿: 10 参加年月日: 14/05/26 最新の投稿
Hello Neil,
Thank you for your answer.
We will have to find a workaround in order to avoid duplicated id's in a page that could cause troubles with our javascript emoticon
Kind Regards,
Vincent
thumbnail
9年前 に Neil Griffin によって更新されました。

RE: JSF Portlet Namespacing

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

When you wrote "duplicated id's" are you referring to the javax.faces.ViewState hidden field?

Thanks,

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

RE: JSF Portlet Namespacing

New Member 投稿: 10 参加年月日: 14/05/26 最新の投稿
Hello Neil,

No I was talking about the id of JSF components.
Example, the HTML produced by ou JSF client component looks like :
<input id="client" onchange="getAjaxLabel(this);"> 


The javascript function getAjaxLabel looks like:

function getAjaxLabel(comp) {
	var sourceId = comp.id;
        ...


So there is a risk that the label of the input text on another portlet will be updated.
The namespace in front of the id would solve the problem.

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

RE: JSF Portlet Namespacing

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

If I understand the problem correctly, I think that id="client" needs to be namespaced. For example: id="1_WAR_myportlet_:client"

Does that look correct to you?

Thanks,

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

RE: JSF Portlet Namespacing

New Member 投稿: 10 参加年月日: 14/05/26 最新の投稿
Hello Neil,

You are right. So that we guarantee uniqueness of id's in the page.
Should the bridge manage this? Or should we do it in our application?

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

RE: JSF Portlet Namespacing

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

Is your JSF client component something written in JavaScript? If so does it inject an <input> into the DOM?

Kind Regards,

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

RE: JSF Portlet Namespacing

New Member 投稿: 10 参加年月日: 14/05/26 最新の投稿
Hello Neil,
no the javascript does not include any <input> in the DOM.
Kind Regards,
Vincent
thumbnail
9年前 に Neil Griffin によって更新されました。

RE: JSF Portlet Namespacing

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

OK, I think I may have misunderstood when you wrote:
the HTML produced by ou JSF client component


Could you provide a detailed explanation of what you mean by that?

Thanks,

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

RE: JSF Portlet Namespacing

New Member 投稿: 10 参加年月日: 14/05/26 最新の投稿
Hello Neil,

Sorry I was not enough clear in my explanations. Our problem is that when we have multiple portlets containing the same JSF web application, there is the possibility that our custom JSF components render the same fragment of HTML in 2 portlets.
We could have for example the following HTML generated in 2 different portlets:
<input id="client" onchange="getAjaxLabel(this);"> 

As a consequence our javascript that is based on the id does not know which input tag to be changed.

However we have finally decided from now to use only one portlet per JSF application. So don't worry, this problem can be postponed.
Thanks anyway for your responsiveness!

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

RE: JSF Portlet Namespacing

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

You're quite welcome. FWIW, if you were to use <h:inputText /> instead of plain <input /> then the bridge would automatically namespace the name attribute.

Kind Regards,

Neil