CommandLink in DataTable

I'm using asession-scoped bean to generate datatable, but still commandLink does not work.

<h:form>

<h:dataTable value="#{ComponentBean.components}" var="item"

styleClass="List" headerClass="ListHeader" footerClass="ListFooter"

rowClasses="EvenRow,OddRow" rendered="#{ComponentBean.found}">

<h:column>

<f:facet name="header">

<h:outputText value="#{msg.No}" />

</f:facet>

<h:outputText value="#{item.id}" />

</h:column>

<h:column>

<f:facet name="header">

<h:outputText value="" />

</f:facet>

<h:commandLink value="#{msg.Select}" action="#{ComponentBean.reserve}">

<f:param name="selectedId" value="#{item.id}" />

</h:commandLink>

</h:column>

</h:dataTable>

</h:form>

ComponentBean.components is not null. (session-scope)

When I click commandLink neigherComponentBean.getComponents() norComponentBean.reserve() are called, instead I'm redirected to main page.

Any help will be greatly appreciated.

Thanks.

[1589 byte] By [GBerberoglua] at [2007-11-26 15:37:32]
# 1
Can you post the faces-config.xml code for this bean?
Seshu_Varanasia at 2007-7-8 21:55:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
<managed-bean><managed-bean-name>ComponentBean</managed-bean-name><managed-bean-class>project.component.ComponentBean</managed-bean-class><managed-bean-scope>session</managed-bean-scope></managed-bean>
GBerberoglua at 2007-7-8 21:55:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

hi,

it seems to me,

you are getting validation error(s)...

your action handler method is not firing because your full phase chain is not completed...

i recommend you try the FacesTrace component that shows all your phases, states, values, errors etc...

you can reach it from here:

http://facestrace.sourceforge.net/

regards...

xaxia at 2007-7-8 21:55:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
I'll try that when I'm back home.. ( May be one day I'll quit coding and give myself to fishing, because of commandLink problems in dataTable.)
GBerberoglua at 2007-7-8 21:55:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Remove the f:param (this causes this all not working, because it is not iterated correctly as you should expect) and add componentbinding to the h:dataTable. In the action method you can retrieve the id (or just the object) by

Long id = ((Component) htmlDataTable.getRowData()).getId();

Check http://balusc.xs4all.nl/srv/dev-jep-dat.html how to use datatables.

Edit

Another thing, you can replacerendered="#{ComponentBean.found}"

byrendered="#{!empty ComponentBean.components}"

In the link I gave you above, you also can download an EAR. This EAR contains a CRUD example. This will give you much more insights how it should work ;)

Message was edited by:

BalusC

BalusCa at 2007-7-8 21:55:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Thanks for the reply..

I know commandLink problems in request-scoped beans, but I'm using session-scoped bean..

I have similar pages works well with session-scoped beans, but only this one causes problem. I'm trying to code in the same way through project, this is why I dont want to use databale binding...

GBerberoglua at 2007-7-8 21:55:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
Your choice. Try to remove this f:param and a big change that you'll see that the action method will be invoked.
BalusCa at 2007-7-8 21:55:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
Yes...You Are Right BalcusCthere is no need to have <f:param here..if you are using DataModel for you DataTableyou can access all the properties of the particular row by getRowData method of DataModel..the way BalcusC has shown you>
pra_n_dea at 2007-7-8 21:55:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

BalusC,

I'have tried to remove f:param, but still ComponentBean.reserve is not invoked.

as I said before, that is not usual commandLink problem, because I'm redirected directly to context-root (http://localhost/app/) instead of page refresh.

edit:

SOLVED:

OMG!! I forgot to end a <h:form> tag before dataTable!!

I understand that when I look commandLink's id..

thanks everyone who replied.

Message was edited by:

GBerberoglu

GBerberoglua at 2007-7-8 21:55:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
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-8 21:55:26 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...