Foren

Passing Parameters through JSF Pages Inside a Portlet

Celil Uzunel, geändert vor 11 Jahren.

Passing Parameters through JSF Pages Inside a Portlet

New Member Beiträge: 4 Beitrittsdatum: 09.12.12 Neueste Beiträge
HI Guys,


I'm new in developing Liferay Portlets with JSF 2.0. Before that i developed JSF 2 Webapplication and now I'm trying to develop it as a Portlet, but i have some problems:

I want to pass parameters from one JSF page to another JSF page using <f:param> and <f:viewParam>. As pure JSF Webapplication its working great, but as Portlet, its not working anymore. I tried to find solutions in the net, but i hadnt success. To be simple, i created a simple small portlet, where i can type a text and this text should be shown in the next JSF page. Here is my code:

BackingBean:

@SuppressWarnings("serial")
@ManagedBean
@ViewScoped
public class BackingBean implements Serializable {
	
	private String text;

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}
	
	public String navigate(){
		
		Map<string, string> param = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
		this.text = param.get("text");
		return "/views/view2.xhtml";
	}

}</string,>


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">
	<h:head />
	<h:body>
		<h:outputtext value="Type something:" />
		<h:form>
			<h:inputtext value="#{backingBean.text}" />
			<h:commandbutton action="#{backingBean.navigate()}" value="Send">
				<f:param name="text" value="#{backingBean.text}"></f:param>
			</h:commandbutton>
		</h:form>
	</h:body></f:view>


view2.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">
<f:metadata>
	<f:viewparam name="text" value="#{backingBean.text}"></f:viewparam>
</f:metadata>
	<h:head />
	
	<h:body>
		<h:outputtext value="Given text: #{backingBean.text}" />
	</h:body>
</f:view>


I would be glad about every help!


Celil
Andreas Feldmann, geändert vor 11 Jahren.

RE: Passing Parameters through JSF Pages Inside a Portlet

New Member Beiträge: 3 Beitrittsdatum: 10.12.12 Neueste Beiträge
Interesting! I am trying to do the same thing:


I want to pass parameters from one JSF page to another JSF page using <f:param> and <f:viewParam>. As pure JSF Webapplication its working great, but as Portlet, its not working anymore.


I would be glad if anybody is able to help!

Thanks in advance!

Andi
thumbnail
Jan Geißler, geändert vor 11 Jahren.

RE: Passing Parameters through JSF Pages Inside a Portlet

Liferay Master Beiträge: 735 Beitrittsdatum: 05.07.11 Neueste Beiträge
I haven't used JSF at all, but my guess is, that the action method doesn't pass the parameter to the render method..
The difference from Servlet to portlet is, that a portlet has 2 phases. An Action and a render Phase to encapsulate the Action (DataManipulation) from the Rendering of a page. If you want to pass something from the Action Method to the RenderMEthod you should set it as attribute or as renderParameter in your action method.
Hope this helps, even if I am completely out of my comfort zone ;)

So long
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: Passing Parameters through JSF Pages Inside a Portlet

Liferay Legend Beiträge: 14916 Beitrittsdatum: 02.09.06 Neueste Beiträge
Celil Uzunel:
	public String navigate(){
		
		Map<string, string> param = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
		this.text = param.get("text");
		return "/views/view2.xhtml";
	}</string,>



Parameters are namespaced. You will not have a request parameter named "text", but based on your code you really don't need it.

Basically how you defined your form, the backing bean text field will be populated by the input field during form submit. However, you're trying to access the parameter directly via the request parameter map. The value of text will be null and you're overriding the value of text sent in during the submit process.

Take out the first two lines (the Map and the this.text lines) and your code should work fine.
thumbnail
Jan Geißler, geändert vor 11 Jahren.

RE: Passing Parameters through JSF Pages Inside a Portlet

Liferay Master Beiträge: 735 Beitrittsdatum: 05.07.11 Neueste Beiträge
I stand corrected! emoticon
Celil Uzunel, geändert vor 11 Jahren.

RE: Passing Parameters through JSF Pages Inside a Portlet

New Member Beiträge: 4 Beitrittsdatum: 09.12.12 Neueste Beiträge
Hi guys,

thanks for your repliesemoticon. But deleting the two lines didn't help me, its still the same.
I checked the sample portlets of liferay and i saw, that they used there the Flash Scope, which is also working for me. Would you recommend to use it? If not, what can i do to pass parameters?
thumbnail
Jan Geißler, geändert vor 11 Jahren.

RE: Passing Parameters through JSF Pages Inside a Portlet

Liferay Master Beiträge: 735 Beitrittsdatum: 05.07.11 Neueste Beiträge
Maybe it DOES have something to do with my post, that parameters which get send to an action method are not available in the Render Method....
thumbnail
David H Nebinger, geändert vor 11 Jahren.

RE: Passing Parameters through JSF Pages Inside a Portlet

Liferay Legend Beiträge: 14916 Beitrittsdatum: 02.09.06 Neueste Beiträge
JSF lifecycle has some similarities to the portlet lifecycle, but you shouldn't necessarily consider the two the same, Jan.

Flash scope is used when you're doing redirects as a result of your navigation. Normal request scope would keep the backing bean alive during the request processing, but if you're doing redirects (or perhaps the bridge is doing redirects on your behalf), you may need to use flash scope to keep the backing bean alive during the redirect...
Andreas Feldmann, geändert vor 11 Jahren.

RE: Passing Parameters through JSF Pages Inside a Portlet

New Member Beiträge: 3 Beitrittsdatum: 10.12.12 Neueste Beiträge
Ah, thanks for the solution. I have found an example of this flash scope in this sample project:

https://github.com/liferay/liferay-faces/blob/master/demos/bridge/jsf2-portlet/src/main/webapp/views/confirmation.xhtml

Have a look :-)
thumbnail
Neil Griffin, geändert vor 11 Jahren.

RE: Passing Parameters through JSF Pages Inside a Portlet

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
Just wanted to mention that the JSF 2.0 f:viewParam feature isn't working yet in Liferay Faces Bridge. For more info, see: FACES-224.
Celil Uzunel, geändert vor 11 Jahren.

RE: Passing Parameters through JSF Pages Inside a Portlet

New Member Beiträge: 4 Beitrittsdatum: 09.12.12 Neueste Beiträge
Thanks for your infos emoticon...

I think, for now i will use the Flash-Scope.
Thanks for your helps!
Cristhian Camilo Lopez, geändert vor 10 Jahren.

RE: Passing Parameters through JSF Pages Inside a Portlet

New Member Beiträge: 15 Beitrittsdatum: 11.04.08 Neueste Beiträge
Neil Griffin:
Just wanted to mention that the JSF 2.0 f:viewParam feature isn't working yet in Liferay Faces Bridge. For more info, see: FACES-224.



Hi Neil,

I'm trying to use f:viewParam on Liferay Faces Bridge 3.1.2-ga3 builded from git source today but I couldn't get it working.. any advice on this ?? since FACES-224 is fixed now...
thumbnail
Neil Griffin, geändert vor 10 Jahren.

RE: Passing Parameters through JSF Pages Inside a Portlet

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
The FACES-224 issue has an issue test portlet that you can find here.

Similarly, FACES-257 has an issue test portlet here.

Both of them make use of f:viewParam. The one for FACES-257 is really fun because it takes advantage of Liferay Friendly URLs. emoticon