-
FEATURED COMPONENTS
First time here? Check out the FAQ!
This is my renderer class for a grid, in that I want to access the dinamycs fields on each row.
I can create a method to access them using a "case" by determining the row number but this seems to be a mistake.
// Descripción del registro de pantalla de los detalles de ordenes
public class DetOrdRender implements RowRenderer{
public void render(Row row, java.lang.Object data) {
String iId = "CodDeb"+String.valueOf(nl); <--- Dinamyc Id for each row
String tId = "DesCau"+String.valueOf(nl); <--- Dinamyc Id for each row
String bId = "BtnDeb"+String.valueOf(nl);
final Button b = new Button("Debitar");
b.setId(bId);
final Textbox t = new Textbox();
t.setId(tId); <--- set the dinamyc name of the Textbox field
t.setWidth("370px");
t.setReadonly(true);
t.setStyle("background:#E1E1E1");
final Intbox ib = new Intbox();
ib.setId(iId); <--- set the dinamyc name of the Intbox field
ib.setCols(4);
ib.setReadonly(true);
ib.setStyle("background:#E1E1E1");
b.addEventListener(Events.ON_CLICK,
new EventListener() {
public void onEvent(Event evt) { <--- event that need to access the fields of the row
whatever.........
}});
nl++;
DetOrd _data = (DetOrd)data;
Prestacion pre = new Prestacion();
con012 c012 = new con012();
pre = c012.getPrestacion(_data.getCodAna(), _data.getTipMue());
new Label(String.valueOf(_data.getCodAna())).setParent(row);
new Label(_data.getTipMue()).setParent(row);
new Label(pre.getDtoAna()).setParent(row);
new Label(String.valueOf(_data.getCanPre())).setParent(row);
b.setParent(row);
ib.setParent(row);
t.setParent(row);
}
}
Thanks.
Not sure I've understood what you mean.
Is the following example what you need?
<window title="My First Window" border="normal" width="200px"> <grid id="mygrid"> <columns> <column label="KEY"/> <column label="VALUE"/> <column label="BUTTON"/> </columns> </grid> <zscript> // Inizializing sample data List data = new ArrayList(); data.add("KEY1,DATA1"); data.add("KEY2,DATA2"); data.add("KEY3,DATA3"); data.add("KEY4,DATA4"); mygrid.setModel(new ListModelList(data)); mygrid.setRowRenderer( new RowRenderer() { void render(Row row, java.lang.Object data) { String[] vsData = ((String) data).split(","); new Label(vsData[0]).setParent(row); new Label(vsData[1]).setParent(row); Button btn = new Button(); btn.setLabel("ClickHere"); btn.setParent(row); btn.setAttribute("DATA", data); btn.addEventListener(Events.ON_CLICK, new EventListener() { public void onEvent(Event evt) { Button btn = (Button) evt.getTarget(); alert(btn.getAttribute("DATA")); } }); } } ); </zscript> </window>
Dear ziccardi.
In your example the data fields have a fixed id. I have not problem with this and the render works ok.
The PROBLEM is that I give to the fields "variable" ids and I want to access them when the button is clicked to change settings and edit them.
the fields "t" have ids like "DesCau0", "DesCau1" ..... etc
the fields "ib" have ids like "CodDeb0", "CodDeb1" ........ etc.
when the button is clicked, on row 0, i need to change "CodDeb0" to setReadonly(false) and then focus() it to edit. The problem is that I don't know how access them by the id because the id is a String variable
If I write the zul with CodDeb0.setReadonly(false) and then CodDeb0.focus() its work, but this mean write a case statement, one by each posible row. I suspect that exists a way to access these fields dinamically too and I have not understand it.
Thanks
>In your example the data fields have a fixed id. I have not problem with this and the render works ok.
In my example the ids are not fixed. I don't even care about the ids, 'couse I let ZK generate them.
I simply associate the rendered object to the attribute "VALUE" of the button (you can add how many attributes as you want. Each button has its own set of attributes).
Than, in the event listener, I ask for the button that generated the event and I get the attribute value back..
In your example, I would do something like this:
In the renderer
b.setAttribute("T_COMPONENT", t);
b.setAttribute("IB_COMPONENT", ib);
In your event listener:
new EventListener() { public void onEvent(Event evt) { Button btn = (Button) evt.getTarget(); Textbox t = (Textbox)btn.getAttribute("T_COMPONENT")); Intbox ib = (Intbox)btn.getAttribute("IB_COMPONENT")); ib.setReadonly(false); // ... } }
Asked: 2008-11-13 09:12:53 +0800
Seen: 541 times
Last updated: Nov 13 '08