Update dataTable after rowEdit

UI Components for JSF
Post Reply
Dimnox
Posts: 2
Joined: 29 Nov 2014, 00:56

29 Nov 2014, 01:28

Hello All,

I ran into a problem with a datatable update. Simply I don't know how should I update the table after rowEdit event is finished to keep the order. I read many topics on the net, but I haven't found the solution yet.

In theory this should work: update=":form:fruits".
But it doesn't re-sort the entries of table. So I tried to update the whole form: update=":form".
In this case all entries are gone except the edited one with no design.

ImageImage

Primefaces version: 5.1.

A very simple code to reproduce the problem.

Fruit.java:

Code: Select all

public class Fruit {

	private Integer id;
	private String name;

	public Fruit(Integer id, String name) {
		super();
		this.id = id;
		this.name = name;
	}

	@Override
	public boolean equals(Object o) {
		if (!(o instanceof Fruit)) {
			return false;
		}
		return id == ((Fruit) o).getId();
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
Fruits.java:

Code: Select all

@ManagedBean(name = "fruits")
@ViewScoped
public class Fruits implements Serializable {

	private static final long serialVersionUID = 1L;

	private ArrayList<Fruit> list = new ArrayList<Fruit>();

	{
		list.add(new Fruit(1, "pineapple"));
		list.add(new Fruit(2, "orange"));
		list.add(new Fruit(3, "banana"));
		list.add(new Fruit(4, "lemon"));
		list.add(new Fruit(5, "apple"));
	}

	public void onRowEdit(RowEditEvent event) {
		Fruit fruit = (Fruit) event.getObject();
		list.set(list.indexOf(fruit), fruit);
	}

	public ArrayList<Fruit> getList() {
		return list;
	}

	public void setList(ArrayList<Fruit> list) {
		this.list = list;
	}
}
fruits.xhtml:

Code: Select all

<h:head />

<h:body>
	<h:form id="form">
		<p:dataTable id="fruits" value="#{fruits.list}" var="fruit"
			editable="true" sortBy="#{fruit.name}">
			<p:ajax event="rowEdit" listener="#{fruits.onRowEdit}" update=":form" />
			<p:column sortBy="#{fruit.name}">
				<p:cellEditor>
					<f:facet name="output">
						<h:outputText value="#{fruit.name}"></h:outputText>
					</f:facet>
					<f:facet name="input">
						<p:inputText value="#{fruit.name}"></p:inputText>
					</f:facet>
				</p:cellEditor>
			</p:column>
			<p:column>
				<p:rowEditor />
			</p:column>
		</p:dataTable>
	</h:form>
</h:body>
</html>
Thank you so much for any ideas in advance.

pjt1
Posts: 17
Joined: 11 Oct 2012, 01:12

30 Jan 2015, 21:26

Similar issue regarding update and broken table to my issue.....listed some workarounds here:
http://forum.primefaces.org/viewtopic.php?f=3&t=40999

Regarding the sort I don't think there is any simple way to accomplish a sort if your dataTable is backed by a simple list.
You would have to create a custom dataModel with sort methods, you could accomplish it:
http://www.primefaces.org/showcase/ui/d ... lazy.xhtml
Primefaces 6.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 30 guests