h:commandLink with f:param doesn't work

I created a simple commandLink with a param. But clicking the link does nothing, not even a page reload.

<h:commandLink id="guess_100" value="100" action="#{NumberGuessBean.checkGuess}">

<f:param id="guessParam_100" name="userGuess" value="100"/>

</h:commandLink>

NumberGuessBean is in request scope. checkGuess is defined as public String checkGuess() {}. This method isn't being called when the link is clicked.

I'm using Glassfish with JavaServer Faces implementation 1.2_04-b10-p01.

Am I missing something here?

Thanks in advance.

[603 byte] By [1-1-1a] at [2007-11-27 3:54:18]
# 1
If you remove the f:param tag, the checkGuess method is invoked?Try to put the whole code of your page and NumberGuessBean.Regards,Alexandre
alexandre_correaa at 2007-7-12 8:58:24 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
refer this link, as Baluc done good job. http://balusc.xs4all.nl/srv/dev-jep-com.htmlsriaknth
srikanthga at 2007-7-12 8:58:24 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Is this link actually been put in a h:form?
BalusCa at 2007-7-12 8:58:24 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Looking at the generated html, i see this in the onclick event of the link:

document.forms['guessInputForm']['guess'].value='0'

Because there isn't a form field called "guess", a JavaScript error occurs.

Shouldn't JSF create the hidden field?

index.jsp:

<f:view>

<h:form id="guessInputForm">

<h:panelGrid id="userNumbersPanel" binding="#{NumberGuessBean.userNumbersPanel}"/>

</h:form>

</f:view>

getUserNumbersPanel() in NumberGuessBean.java:

public HtmlPanelGrid getUserNumbersPanel(){

FacesContext facesContext = FacesContext.getCurrentInstance();

Application application = facesContext.getApplication();

if(userNumbersPanel == null){

userNumbersPanel = new HtmlPanelGrid();

}

userNumbersPanel.setColumns(gameRandomNumber.getMaxNumber() + 1);

List<UIComponent> children = userNumbersPanel.getChildren();

HtmlCommandLink link;

UIParameter param

for (int i = 0; i <= gameRandomNumber.getMaxNumber(); i++) {

link = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE);

link.setActionExpression(application.getExpressionFactory()

.createMethodExpression(facesContext.getELContext(),

"#{NumberGuessBean.checkGuess}",

String.class,

new Class<?>[0])

);

link.setValue(String.valueOf(i));

param = new UIParameter();

param.setName("guess");

param.setValue(String.valueOf(i));

link.getChildren().add(param);

children.add(link);

}

return userNumbersPanel;

}

1-1-1a at 2007-7-12 8:58:24 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
If I have understood right, you are creating your link dinamically inside your panelGrid. Is that right?If you use your backingBean in session scope, does it works?
alexandre_correaa at 2007-7-12 8:58:24 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
And if it is dynamically created, make sure you explicitly assign an ID to it.
rlubkea at 2007-7-12 8:58:24 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

Thanks for the help.

Yes, I'm creating links in the backing bean. And using session scope has no effect.

However, in trying to debug this issue, I created a simple form with a commandLink and a param. I still get the javascript error... the onclick event is still trying to set a variable that doesn't exist.

Without the f:param, the link works and checkGuess is called.

Is there a setting in web.xml I need to specify?

index.jsp

<f:view>

<h:form id="guessInputForm">

<h:commandLink id="link1" action="#{NumberGuessBean.checkGuess}">

<h:outputText value="Link = 1000"/>

<f:param name="guess" value="1000" />

</h:commandLink>

</h:form>

</f:view>

and checkGuess():

public String checkGuess() {

System.out.println("checkGuess...");

return null;

}

1-1-1a at 2007-7-12 8:58:24 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
I'm not able to reproduce this.If you can create a testcase, please log an issue [1] and attach it. We'll look into it.[1] https://javaserverfaces.dev.java.net/issues
rlubkea at 2007-7-12 8:58:24 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...