Fórum

<alloy:commandButton> is not calling managed bean action

ramathulasi kudumula, modificado 9 Anos atrás.

<alloy:commandButton> is not calling managed bean action

Junior Member Postagens: 51 Data de Entrada: 06/10/11 Postagens Recentes
Hi,

I am trying to implement the <alloy:commandButton> in liferay portal 6.2. When i click the submit button the managed bean action or actionListener is not calling. But the same is working in Liferay Faces Alloy demo site.
View.xhtml Code:
============
<?xml version="1.0" encoding="UTF-8"?>
<f:view xmlns="http://www.w3.org/1999/xhtml" xmlns:alloy="http://liferay.com/faces/alloy"
xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets">
<alloy:head />
<alloy:body>
<alloy:form>
<alloy:commandButton actionListener="#{sampleBackingBean.actionListener}" immediate="true"
value="submit">
<f:ajax execute="@form" render="@form" />
</alloy:commandButton>
<alloy:outputText value="#{sampleBackingBean.text}" />
</alloy:form>
</alloy:body>
</f:view>

SampleBackingBean.java Code:
==========================

package com.tsky.selfcare.sampleportlet;


import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.event.ActionEvent;

import com.liferay.faces.util.logging.Logger;
import com.liferay.faces.util.logging.LoggerFactory;

@ManagedBean(name="sampleBackingBean")
@RequestScoped
public class SampleBackingBean {

private static final Logger logger = LoggerFactory.getLogger(SampleBackingBean.class);
private String text;


public String getText() {
return text;
}


public void setText(String text) {
this.text = text;
}


public void actionListener(ActionEvent actionEvent) {
logger.debug("Entered into actionListener");
logger.info("Entered into actionListener");
text="Hiiiiiii";
}
}
It would be helpful if some one share sample working code for this.

Regards
Thulasi
thumbnail
Juan Gonzalez, modificado 9 Anos atrás.

RE: <alloy:commandButton> is not calling managed bean action

Liferay Legend Postagens: 3089 Data de Entrada: 28/10/08 Postagens Recentes
Hi ramathulasi,

you don't need

immediate="true"


in your commandButton. Please remove it.

Additionally adding

execute="@form"


isn't needed in your test case. You can safely remove it.

Last thing you can check, did you add

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


to your liferay-portlet.xml?

Thanks.
ramathulasi kudumula, modificado 9 Anos atrás.

RE: <alloy:commandButton> is not calling managed bean action

Junior Member Postagens: 51 Data de Entrada: 06/10/11 Postagens Recentes
Thanks Juan..

Its working fine after adding <requires-namespaced-parameters>false</requires-namespaced-parameters> in liferay-portlet.xml file.

But i am facing another issue..I want to pass the parameter to bean action when i click the alloy:commandButton.
When i include the f:param inside alloy:commandButton the button itself not showing on the browser.

xhtml code :
=========
<alloy:commandButton action="#{sampleBackingBean.callPopup}" value="Submit">
<f:param name="sampleText" value="Hello"></f:param>
</alloy:commandButton>

Bean Code:
==========
public String callPopup()
{
String name="";
FacesContext fc = FacesContext.getCurrentInstance();
Map<String,String> params = fc.getExternalContext().getRequestParameterMap();
name = params.get("sampleText");
return null;
}
Regards
Thulasi
thumbnail
Juan Gonzalez, modificado 9 Anos atrás.

RE: <alloy:commandButton> is not calling managed bean action

Liferay Legend Postagens: 3089 Data de Entrada: 28/10/08 Postagens Recentes
Hi again,

seems you declared a local variable "name" and you stored the param value there. Probably you want to store in a class attribute and have setters and getters to render in the xhtml.
ramathulasi kudumula, modificado 9 Anos atrás.

RE: <alloy:commandButton> is not calling managed bean action

Junior Member Postagens: 51 Data de Entrada: 06/10/11 Postagens Recentes
Hi Juan,

I am trying to implement pass a parameter to bean action method on clicking a link or button.

In my code the parameter name is sampleText and name which is declared a local variable in my bean.
Here i am storing the parameter value in name variable only.

But my question is not able to pass the parameter to bean using f:param tag inside alloy:commandButton/CommandLink.

Regards
Thulasi
thumbnail
Juan Gonzalez, modificado 9 Anos atrás.

RE: <alloy:commandButton> is not calling managed bean action

Liferay Legend Postagens: 3089 Data de Entrada: 28/10/08 Postagens Recentes
Hi,

yes, I understood the question the first time emoticon.

It's working fine for me, my question is, why do you think isn't working? And that's why I said my thoughts that you are rendering the wrong managed bean attribute.
ramathulasi kudumula, modificado 9 Anos atrás.

RE: <alloy:commandButton> is not calling managed bean action

Junior Member Postagens: 51 Data de Entrada: 06/10/11 Postagens Recentes
Hi Juan,

Can you please share the working code?

Regards
Thulasi
thumbnail
Juan Gonzalez, modificado 9 Anos atrás.

RE: <alloy:commandButton> is not calling managed bean action

Liferay Legend Postagens: 3089 Data de Entrada: 28/10/08 Postagens Recentes
ramathulasi kudumula:
Hi Juan,

Can you please share the working code?

Regards
Thulasi


The alloy:commandButton snippet is same as yours. Please answer my question about how do you know it isn't working for you.

Thanks.
ramathulasi kudumula, modificado 9 Anos atrás.

RE: <alloy:commandButton> is not calling managed bean action

Junior Member Postagens: 51 Data de Entrada: 06/10/11 Postagens Recentes
ramathulasi kudumula:

xhtml code :
=========
<alloy:commandButton action="#{sampleBackingBean.callPopup}" value="Submit">
<f:param name="sampleText" value="Hello"></f:param>
</alloy:commandButton>

Bean Code:
==========
public String callPopup()
{
String name="";
FacesContext fc = FacesContext.getCurrentInstance();
Map<String,String> params = fc.getExternalContext().getRequestParameterMap();
name = params.get("sampleText");
return null;
}




I am trying to fetch the param value in action method as shown above. But the param value is not getting passed as expected. Button is also going to hidden mode.
thumbnail
Juan Gonzalez, modificado 9 Anos atrás.

RE: <alloy:commandButton> is not calling managed bean action

Liferay Legend Postagens: 3089 Data de Entrada: 28/10/08 Postagens Recentes
Please can you attach your portlet so I can make some checks?

Thanks.
ramathulasi kudumula, modificado 9 Anos atrás.

RE: <alloy:commandButton> is not calling managed bean action

Junior Member Postagens: 51 Data de Entrada: 06/10/11 Postagens Recentes
I am attaching portlet code.

Regards
Thulasi
thumbnail
Juan Gonzalez, modificado 9 Anos atrás.

RE: <alloy:commandButton> is not calling managed bean action

Liferay Legend Postagens: 3089 Data de Entrada: 28/10/08 Postagens Recentes
Hi ramathulasi,

thanks to you feedback we found that this was a bug caused by not adding other commandLink/commandButton to the page.

We fixed it here: https://issues.liferay.com/browse/FACES-2196

Thanks again!