Skip to main content

Id confusion with ajax and datatables

3 replies [Last post]
angelcervera
Offline
Joined: 2003-12-03
Points: 0

I'm confused with use of render attribute of h:ajax inside tables.

I'm using Glassfish 2.1.1 and Mojarra 2.0.1 (FCS b02).

The question is:
I want refresh table which has the h:commandButton which throws event.
¿Why refresh nothing when push "add updating :sumForm:tableId" and "add updating tableId" buttons of this simplify absolutely absurd example ( my real case is more complex ):

This is my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<style>
table {
border: 10px solid;
}
</style>
</h:head>
<h:body>
<div align="center">
<h:form id="sumForm">
<h:panelGroup id="tableWrapperId" >
<h:dataTable value="#{sumtable.table}" var="lst1" id="tableId">
<h:column>
<h:commandButton action="#{sumtable.add}" value="add updating :sumForm:tableId">
<f:ajax execute="@this" render=":sumForm:tableId"/>
</h:commandButton>
<h:commandButton action="#{sumtable.add}" value="add updating tableId">
<f:ajax execute="@this" render="tableId"/>
</h:commandButton>
<h:commandButton action="#{sumtable.add}" value="add updating tableWrapperId">
<f:ajax execute="@this" render=":sumForm:tableWrapperId "/>
</h:commandButton>
<h:commandButton action="#{sumtable.add}" value="add updating subtotals">
<f:ajax execute="@this" render=":sumForm:sumsId"/>
</h:commandButton>
<h:commandButton action="#{sumtable.add}" value="add updating form">
<f:ajax execute="@this" render="@form"/>
</h:commandButton>
#{lst1[0]}
</h:column>
<h:column>
#{lst1[1]}
</h:column>
</h:dataTable>
</h:panelGroup>
<h:dataTable value="#{sumtable.sums}" var="sums" id="sumsId">
<h:column>
#{sums[0]}
</h:column>
<h:column>
#{sums[1]}
</h:column>
</h:dataTable>

</h:form>
</div>
</h:body>
</html>

package com.silyan.pruebas;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
* @author angel
*
*/
@ManagedBean(name="sumtable")
@SessionScoped
public class SumController {

private final static int COLUMNS_LEN = 2;

private List> table = new ArrayList>();

private List sums = new ArrayList();

@PostConstruct
public void init() {
fill();
}

private int base = 0;

public void fill() {

sums.clear();
Integer[] arrSum = new Integer[COLUMNS_LEN];
sums.add(arrSum);

table.clear();

for (int i = 0; i < COLUMNS_LEN; i++) {
arrSum[i] = 0;
}

for (int i = 0; i < 10; i++) {
List integers = new ArrayList();
table.add(integers);
for (int j = 0; j < COLUMNS_LEN; j++) {
integers.add(new Integer(j + base));
arrSum[j] = arrSum[j] + j + base;
}
}
}

public String add() {
base++;
fill();
return null;
}

public List> getTable() {
return table;
}

public void setTable(List> table) {
this.table = table;
}

public List getSums() {
return sums;
}

public void setSums(List sums) {
this.sums = sums;
}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
angelcervera
Offline
Joined: 2003-12-03
Points: 0

bug

Jim Driscoll

Well, I'm traveling, so I can't try your example (which did come across
correctly on the email bridge).

However, in the interest of giving your a pointer which may clear up the
problem, try actionListener instead of action.

It's possible you're running into a bug - I'll try this when I get a minute.

Jim

On 11/30/09 1:47 PM, webtier@javadesktop.org wrote:
> I'm confused with use of render attribute of h:ajax inside tables.
>
> I'm using Glassfish 2.1.1 and Mojarra 2.0.1 (FCS b02).
>
> The question is:
> I want refresh table which has the h:commandButton which throws event.
> ¿Why refresh nothing when push "add updating :sumForm:tableId" and "add updating tableId" buttons of this simplify absolutely absurd example ( my real case is more complex ):
>
> This is my code:
>

> 
>  	xmlns:h="http://java.sun.com/jsf/html"
> 	xmlns:f="http://java.sun.com/jsf/core">
> 
> 
> 
> 
> 	
> > > > > > > > > > > > > > > > > > > > #{lst1[0]} > > > #{lst1[1]} > > > > > > #{sums[0]} > > > #{sums[1]} > > > > >
>
> >

>
>
>
> package com.silyan.pruebas;
>
> import java.util.ArrayList;
> import java.util.List;
>
> import javax.annotation.PostConstruct;
> import javax.faces.bean.ManagedBean;
> import javax.faces.bean.SessionScoped;
>
> /**
> * @author angel
> *
> */
> @ManagedBean(name="sumtable")
> @SessionScoped
> public class SumController {
>
> private final static int COLUMNS_LEN = 2;
>
> private List> table = new ArrayList>();
>
> private List sums = new ArrayList();
>
> @PostConstruct
> public void init() {
> fill();
> }
>
> private int base = 0;
>
> public void fill() {
>
> sums.clear();
> Integer[] arrSum = new Integer[COLUMNS_LEN];
> sums.add(arrSum);
>
> table.clear();
>
> for (int i = 0; i< COLUMNS_LEN; i++) {
> arrSum[i] = 0;
> }
>
> for (int i = 0; i< 10; i++) {
> List integers = new ArrayList();
> table.add(integers);
> for (int j = 0; j< COLUMNS_LEN; j++) {
> integers.add(new Integer(j + base));
> arrSum[j] = arrSum[j] + j + base;
> }
> }
> }
>
> public String add() {
> base++;
> fill();
> return null;
> }
>
> public List> getTable() {
> return table;
> }
>
> public void setTable(List> table) {
> this.table = table;
> }
>
> public List getSums() {
> return sums;
> }
>
> public void setSums(List sums) {
> this.sums = sums;
> }
> }
> [Message sent by forum member 'angelcervera' ]
>
> http://forums.java.net/jive/thread.jspa?messageID=373932
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

angelcervera
Offline
Joined: 2003-12-03
Points: 0

It is impossible format correctly the message in this forum !! SOS!!