can't you put the Xradio in a cell, append a listener to the cell onclick , change the value of the xradio and append the cell to the row?
chillworld ( 2014-04-20 08:34:08 +0800 )edit-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello.
I have a grid. Some of the cells of that grid contain radio buttons. When I click on the radio button it gets selected, but I want to be able to select the radio button by clicking anywhere in cell that contains the radio button.
I tried using vflex and hflex for forcing the radio button to use all the available space, but it does not work.
Here is how I am building the grid:
Rows rows = grid.getRows(); /**grid defined elsewhere**/
rows.getChildren().clear();
for ( int i=0; i<7; i++ ) {
Row row = new Row();
Value someV = new Value(); /**Some value I defined, it has a text and a radio group as attributes.**/
row.setValue(someV);
Hlayout h = new Hlayout();
h.appendChild(new Label(someV.getText()));
h.appendChild(someV.getGroup());
row.appendChild(h);
for ( int n=0; n<5; n++ ) {
XRadio xRadio = new XRadio("", someV.getgroup()); /**Extension of Radio that manages radio group**/
xRadio.setVflex("1");
xRadio.setHflex("1");
row.appendChild(xRadio);
}
rows.appendChild(row);
}
How can I do this?
Ok, I got it. When a click is made on the cell, the radio button inside that cell is selected. All is done in the client side.
Instead of
cell.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
xRadio.setChecked(true);
System.out.println("Cell event");
}
});
I did
cell.setWidgetListener(Events.ON_CLICK, "this.firstChild.setSelected(true)");
That way, the listener is added in the client and the onClick event is handled completely in the browser.
Hi
Adding the following style
<style>
.full-space {
display: inline-block;
width: 100%;
}
.full-space input {
width: 100%;
}
</style>
then set a sclass to the radio
radio.setSclass("full-space");
Hi @jimmyshiau! I thought your answer worked, but in fact it does not work if the cell is much higher than the radio button. I mean, the clickable area does grow horizontally, but not vertically. If I modify the height, the radio button looks bigger and that is not what I want. Do you have any advice on this?
Thanks!
can't you put the Xradio in a cell, append a listener to the cell onclick , change the value of the xradio and append the cell to the row?
chillworld ( 2014-04-20 08:34:08 +0800 )editAs @chillworld suggested, I added a listener for the cell and it works fine.
Here's the code:
for ( int n=0; n<5; n++ ) {
Cell cell = new Cell();
final XRadio xRadio = new XRadio("", someV.getGroup());/**Extension of Radio that manages radio group**/
cell.appendChild(xRadio);
cell.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
xRadio.setChecked(true);
System.out.println("Cell event");
}
});
cell.setStyle("cursor:pointer;");
row.appendChild(cell);
}
So, as I said, this works fine, but I think it's a lot of useless traffic to the server. I mean, this could be done locally in the client, right? No need to go and tell the server that a cell was clicked. I started looking into widgets, but I still do not understand how this could be done with a widget using Java.
Any ideas?
Thanks!
Oke I'll did some research, it should be possible.
I have found 3 site's where do you need to take a look and try to find it :
http://zkframeworkhint.blogspot.be/2013/07/how-to-call-javascript-function-from.html
http://forum.zkoss.org/question/75753/add-javascript-call-to-component-in-java-code/
http://books.zkoss.org/wiki/ZKClient-sideReference/GeneralControl/EventListening#DeclareaClient-sideListenerin_ZUML
I hope this can be of help to you (Mine javascript was long time ago so I have to do back research if I want to create it for you and I don't have that time ATM)
Greetz chill.
Asked: 2014-04-09 21:42:33 +0800
Seen: 45 times
Last updated: Apr 29 '14