Is there any bug using commandLink tag inside the dataTable tag?

Hi all!

I trying to use the commandLink tag inside the dataTable tag, but when I clik in the link it does nothing. The most interesting part is that if I put the commandLink tag outside of dataTable tag it works properly.

Look the code below:

<h:form binding="#{backing_pages_teste.form1}">

<h:dataTable rows="5"

value="#{backing_pages_PesquisaAvaliadorFormulario.pesquisaAvaliadorLista}"

var="avaliado"

binding="#{backing_pages_teste.dataTable1}">

<h:column>

<h:commandLink binding="#{backing_pages_teste.commandLink1}"

action="#{backing_pages_teste.recuperarGestaoPerformance}">

<h:outputText value="#{avaliado.funcionarioAvaliado.nomeColaborador}"/>

</h:commandLink>

</h:column>

</h:dataTable>

<h:commandLink binding="#{backing_pages_teste.commandLink1}"

action="#{backing_pages_teste.recuperarGestaoPerformance}">

<h:outputText value="TEST"/>

</h:commandLink>

</h:form>

Any help?

Thanks in advance.

[1115 byte] By [jrogerio69a] at [2007-10-2 4:45:18]
# 1
it is a known bug if your bean is a request scope bean. If it is the case, turn it into a session scope bean and it should work.
nboudania at 2007-7-16 0:50:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

I used request scope for mine and they work fine. I noticed you have tons of bindings in your code. Are they really necessary?

Here's a snippet from my .jsp that has commandLinks in a dataTable. The ID appears as a link that a user can click on to go to a more detailed page.<h:dataTable value="#{eventList.events}" var="event">

<h:column>

<f:facet name="header">

<h:outputText value="ID"/>

</f:facet>

<h:commandLink action="#{eventList.selectEvent}">

<h:outputText value="#{event.eventid}"/>

<f:param name="eventid" value="#{event.eventid}"/>

</h:commandLink>

</h:column>

<h:column>

<f:facet name="header">

<h:outputText value="Name"/>

</f:facet>

<h:outputText value="#{event.name}"/>

</h:column>

</h:dataTable>

Looma at 2007-7-16 0:50:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

jrogerio69,

What implementation are you using? I use Sun's reference implemenation, and have had problems in the past using h:commandLink inside a h:dataTable, accessing action methods in request-scope backing beans. Converting the beans to session beans fixed it (as nboudani suggested)... but I wasn't really happy with the fix, because I would prefer to use request beans, if possible.

Loom, are you using Sun's RI, or some other implementation?

I've been meaning to try MyFaces and see if it properly implements commandLinks within dataTables.

Another gotchya to look for (which probably doesn't apply to your problem, since you mentioned that the commandLink works if it is outside the dataTable): JSF seems to be very strict about requiring it's backing beans to meet the Java Bean contract, that is, if you refer to a backing bean property from your, there MUST be a getter and setter method for that property. When I started using JSF, I thought I could get away with just a "get" method for read-only things I wanted to include in my page, or get away with just an "is" method for boolean attributes I used for the tag attribute "rendered". Then my action methods weren't being invoked and I could not figure out why. Adding setters for all properties I used in the backing bean made the action methods work.

--Scott

Scott_Moorea at 2007-7-16 0:50:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Scott_Moore,I'm using Sun's RI JSF version 1.1.01 and tomcat 5.5.9
Looma at 2007-7-16 0:50:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Thanks nboudani, changing the bean to a session scope worked.
jrogerio69a at 2007-7-16 0:50:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

This solution works but creates issues while using C2A link s from inside a datatable for JSR 168 JSF portlet.

The solution is to add an action to the userbean used inside the datatable, and call that while clicking on commandLinks. This leaves the backing bean in the session scope as required by the datatable, but the userbean is in the request scope.

Hope this helps.

Sinu

sinusekhara at 2007-7-16 0:50:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

Sinu

Can you please elaborate on your statement in the previous post. I am having the same issue with datatable and commandlink.

Here is my scenario:

<h:dataTable border="0" id="userSearchResult" styleClass="userSearchResult" rowClasses="even, odd"

value="#{usersearchBean.users}" headerClass="dataTableHeader" var="user" rows="15" >

<h:column>

<f:facet name="header">

<h:outputText value="User Name" />

</f:facet>

<h:commandLink id="link" action="success" actionListener="# {userBean.showUserDetail}">

<h:outputText value="#{user.name}" />

</h:commandLink>

</h:column>

<h:column>

<f:facet name="header">

<h:outputText value="Functional Title" />

</f:facet>

<h:outputText value="#{user.jobtitle}" />

</h:column>

</h:dataTable>

And usersearchBean is in Request scope, I even changed it to session scope but the actionListener is never called. I using ajax4jsf for my dropdowns in search form. Do you think that can be an issue? Please advice.

ndnguya at 2007-7-16 0:50:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
in my application the commandlink, actionlistener and datatable work together even in a request-scope bean when i use the attributepreserveDataModel=攖rue?br>of the datatable
roy_eldridgea at 2007-7-16 0:50:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...