JSF DataModelEvent for Row Selected

Hello,

I have a JSF DataTable with a row selection listener (DataModelEvent). When running the web application the listener returns -1 for the getRowIndex(). I have tried getting the source of the event and getting selected row through that but still get -1. Is there a bug with this listener or am I just missing something? The event is being fired because the code I have in the event handler is running just not getting the selected row of the table. Sorry if this has been answered elsewhere, I searched but did not find an answer.

Here is the code for the data table:

<h:dataTable binding="#{a.dataTable1}" id="dataTable1" rowClasses="list-row-even,list-row-odd" style="width: 800px"

value="#{a.dataTable1Model}" var="currentRow">

<h:column id="column1">

<h:commandLink action="case2">

<h:outputText binding="#{a.outputText1}" id="outputText1" value="#{currentRow['name']}"/>

</h:commandLink>

</h:column>

</h:dataTable>

And the event handler:

privatevoid _init()throws Exception{

dataTable1Model.addDataModelListener(new DataModelListener(){

publicvoid rowSelected(DataModelEvent dme){

dataTable1Model_rowSelected(dme);

}

});

}

publicvoid dataTable1Model_rowSelected(DataModelEvent dme){

getSessionBean1().setReferer("A");

getSessionBean1().setRefererurl("/faces/a.jsp");

getSessionBean1().setCurrent(String.valueOf(dme.getDataModel().getRowIndex()));

}

[2353 byte] By [rogerrhodya] at [2007-11-26 17:09:50]
# 1

I figured out a solution for my problem. I am using the table for dynamic links and for additional information that will be dynamically loaded into the called page.

Do not use the DataModelListener. Instead of output text use a hyperlink object so that the table will now look like:

<h:dataTable binding="#{a.dataTable1}" headerClass="list-header" id="dataTable1" rowClasses="list-row-even,list-row-odd"

value="#{a.dataTable1Model}" var="currentRow" width="800">

<h:column binding="#{a.column1}" id="column1">

<webuijsf:hyperlink actionExpression="#{a.hyperlink1_action}" binding="#{a.hyperlink1}" id="hyperlink1"

style="font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 14px; text-decoration: none" text="#{currentRow['name']}"/>

</h:column>

</h:dataTable>

Then handle any of the additional code that needs to be processed in the link handler:

public String hyperlink1_action() {

getSessionBean1().setReferer("A");

getSessionBean1().setRefererurl("/faces/a.jsp");

Links activated = (Links)linkList.get(getDataTable1Model().getRowIndex());

getSessionBean1().setCurrent(activated.getName());

return "case2";

}

linkList is an ArrayList and Links is an object for my link information. I hope this information is useful to someone trying to build dynamic links.

rogerrhodya at 2007-7-8 23:37:39 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

commandLink will do.. it is like a submit button which you can put parameters inside tags

<h:commandLink value="Sample Value" action="#{myBean.doSomething}">

<f:param value="#{myBeanBean.someProperty}" name="id" />

</h:commandLink>

jgalacambraa at 2007-7-8 23:37:39 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...