-
1. Re: ExtendedDataTable: getting a selection without using session scope
ilya_shaikovsky Jun 15, 2010 7:13 AM (in response to baraabasata1)please post more complete code for both page and bean.
-
2. Re: ExtendedDataTable: getting a selection without using session scope
baraabasata1 Jun 15, 2010 11:28 AM (in response to ilya_shaikovsky)Thanks for your reply, Ilya. I'm including code below, which I have isolated down to the smallest example. This has a form and a table. The form adds simple items to the list backing the table.
I actually get a different behavior from this reduced example, which is that the table does not get rerendered upon clicking the command button. I've tried both reRender="myForm" and reRender="myTable", but the table continues to only show the two items that were added upon construction. Any ideas for this non-rerendering behavior? If this example will work, then my selection issue may be resolved with it.
{code}
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@ taglib prefix="rich" uri="http://richfaces.org/rich" %>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@ taglib prefix="a4j" uri="http://richfaces.org/a4j" %>
<html>
<head>
<title>Hello</title>
</head>
<body>
<f:view>
<a4j:keepAlive beanName="myTableDataModel" />
<a4j:form id="inputForm">
<h:inputText id="inputText" value="#{myTableDataModel.input}" />
<a4j:commandButton id="submitButton" value="Add"
actionListener="#{myTableDataModel.addItem}" reRender=":myTable" />
</a4j:form>
<h:form id="myForm">
<rich:extendedDataTable
id="myTable"
value="#{myTableDataModel.rows}"
var="row"
rows="5"
height="200"
selection="#{myTableDataModel.selection}">
<a4j:support event="onselectionchange" actionListener="#{myTableDataModel.onSelectionChange}"
reRender="selectedItemName" />
<rich:column>
<h:outputText value="#{row.name}" />
</rich:column>
</rich:extendedDataTable>
</h:form>
<h:outputText id="selectedItemName" value="#{myTableDataModel.selectedItem.name}" />
</f:view>
</body>
</html>
import org.richfaces.model.selection.Selection;
import org.richfaces.model.selection.SimpleSelection;
import javax.faces.event.ActionEvent;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class MyTableDataModel implements Serializable {
public static class Item implements Serializable {
private String name;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public Item(String name) { this.name = name; }
}
private String input;
private List<Item> items;
private Item selectedItem;
private Selection selection = new SimpleSelection();
public MyTableDataModel() {
items = new ArrayList<Item>();
items.add(new Item("One"));
items.add(new Item("Two"));
}
public void addItem(ActionEvent event) {
items.add(new Item(input));
}
public String getInput() {
return input;
}
public void setInput(String input) {
this.input = input;
}
public List<Item> getRows() {
return items;
}
public Item getSelectedItem() {
return selectedItem;
}
public Selection getSelection() {
return selection;
}
public void setSelection(Selection selection) {
this.selection = selection;
if (selection.size() > 0) {
Integer selectedIndex = (Integer)selection.getKeys().next();
selectedItem = items.get(selectedIndex);
}
System.out.println("Selection size is: " + selection.size());
System.out.println("Row count is: " + items.size());
}
public void onSelectionChange(ActionEvent event) {
System.out.println("Selection size is: " + selection.size());
System.out.println("Row count is: " + items.size());
}
}{code}
-
3. Re: ExtendedDataTable: getting a selection without using session scope
baraabasata1 Jun 15, 2010 11:36 AM (in response to baraabasata1)To clarify, I think my original issue was that both the form and the table were contained in the same <a4j:form>, which seems to have affected selection behavior.
Here, they are placed into two separate forms. The reRender is the only piece remaining to solve in this example, I think.
-
4. Re: ExtendedDataTable: getting a selection without using session scope
baraabasata1 Jun 15, 2010 12:28 PM (in response to baraabasata1)More detail: if I use a DataTable instead of ExtendedDataTable, the table is rerendered perfectly. The unique piece seems to be the use of ExtendedDataTable inside a Form.
With an ExtendedDataTable inside a Form, using reRender="myTable" has no effect. Using reRender="myForm" results in a neverending "loading" spinner/indicator.
I'm assuming the Form is necessary for the use of <a4j:support> here.
-
5. Re: ExtendedDataTable: getting a selection without using session scope
ilya_shaikovsky Jun 16, 2010 3:08 AM (in response to baraabasata1)in your original snippet the problem was in
:myTable
Such usage means that the component will be searched form outside of any forms. should be just myTable Your current problem of neverending loadind - seems just old issue of table - which version you using? Try the 3.3.3 final if using older.
-
6. Re: ExtendedDataTable: getting a selection without using session scope
baraabasata1 Jun 16, 2010 9:27 AM (in response to ilya_shaikovsky)Thanks for your reply, Ilya. I'm using 3.3.3 Final. I've played with setting reRender in different ways: "myTable", ":myTable", and "myForm". With reRender="myTable" and reRender=":myTable", the table does not change at all. With reRender="myForm", I get the neverending loading indicator.
If I remove the <h:form> that's wrapping the table and then use reRender="myTable", the table gets refreshed perfectly. It's when the ExtendedDataTable is inside a Form that I'm experiencing this.
-
7. Re: ExtendedDataTable: getting a selection without using session scope
alexhe Oct 7, 2010 5:31 PM (in response to baraabasata1)I am running into the same issue. Is this bug has been reported?
-
8. Re: ExtendedDataTable: getting a selection without using session scope
ilya_shaikovsky Oct 8, 2010 6:23 AM (in response to alexhe)No I can't reproduce that at test pages where EDT being reRender'ed. it's successful for me.