Hide row in dynamic grid in ZK framework - zk

I am trying to hide/show a row in a grid (filled dynamically from Java code) upon clicking on it's previous row. To simulate a simple MasterDetail component. I get the right index of the clicked row in the java code, however changing visibility of the row doesn't work! Can anyone help me with this or is there a similar way to to this?
Thanks,
Pooya
Here is the code for the ZUL:
<?xml version="1.0" encoding="UTF-8"?>
<zk xmlns="http://www.zkoss.org/2005/zul">
<window id="callbackLogWindow"
apply="CallbackLogWindowComposer"
border="none" height="100%" width="100%"
xmlns:w="http://www.zkoss.org/2005/zk/client">
<grid id="callbackLogGrid" oddRowSclass="non-odd" height="100%">
<columns>
<column label="Logging Name" />
<column label="Status" />
<column label="DateTime" />
<column label="Subject" />
<column label="Replies" />
</columns>
<rows>
<zk forEach="${callbackLogWindow$composer.callbacks}">
<row sclass='${forEachStatus.index % 2 != 0 ? "z-grid-odd" : ""}'
onClick="callbackLogWindow$composer.toggleRow(self.index)">
<custom-attributes callback="${each}"/>
<cell><label value="${callback.loggingName}" /></cell>
<cell><label value="${callback.resolved}" /></cell>
<cell><label value="${callback.callbackTime}" /></cell>
<cell><label value="${callback.subject}" /></cell>
<cell><label value="${callback.resolvedItemCount}" /></cell>
</row>
<row sclass='${forEachStatus.index % 2 != 0 ? "z-grid-odd" : ""}'>
<cell colspan="5">
<include src="callbackItem.zul" callback="${each}"/>
</cell>
</row>
<row>
<custom-attributes callback="${each}"/>
<button onClick="callbackLogWindow$composer.saveCallbackItems(callback)">
Save
</button>
</row>
</zk>
</rows>
</grid>
</window>
</zk>
And the controller:
public class CallbackLogWindowComposer extends SelectorComposer<Window> {
#Inject private CallbackDao callbackDao;
#Wire Grid callbackLogGrid;
private List<Callback> callbacks = new ArrayList<Callback>();
#Override
public void doAfterCompose(Window window) throws Exception {
super.doAfterCompose(window);
}
public List<Callback> getCallbacks() {
callbacks = callbackDao.findAll();
return callbacks;
}
public void toggleRow(int i) {
Component row = callbackLogGrid.getRows().getChildren().get(i+1);
row.setVisible(row.isVisible());
callbackLogGrid.renderAll();
}
public void saveCallbackItems(Callback cb) {
callbackDao.saveInTransaction(cb);
}
}

I am not sure and not test but i can suggest one thing here to you Zk have visible="true/false" attribute you can apply this attribute in each row and bind this with your databean variable For more detail i can suggest let us suppose you have a List<A> list
and list contain all the record which you want to display now add another variable like display in class A and control it by your self .And onClick on any row change update any other item of list .

I have the same problem, and the solution I found was:
row visible=""
<grid model="#bind(vm.total)" vflex="1" emptyMessage="No records exist" width="315px" >
<columns>
<column width="45%"/>
<column width="25%" />
</columns>
<template name="model">
<row visible="#load(each.visible)">
<checkbox label="#load(each.label)" style="font-weight:bold" if="${each.checkbox}"/>
<label value="#load(each.label)" style="font-weight:bold" unless="${each.checkbox}"/>
<doublebox value="#bind(each.value)" sclass="textBoxNumber" locale="us" readonly="true" />
</row>
</template>
</grid>
</groupbox>

Related

ZK framework getting value of a component on zul page

I am trying to get the value of a textbox on a zul page by using some kind of getValue method. I should handle this on the zul page, not on a controller. I need to assign a listbox cell (which is the first cell of the list box below) with a value coming from the textbox.
<listcell>
<label value="" />
</listcell>
<listcell>
<toolbarbutton visible="true"
image="/resources/images/icons/1616/page_text.gif" />
</listcell>
<listcell>
<label value="#{file.name}" />
</listcell>
<listcell>
<toolbarbutton forward="onClick=onRemoveMultipleFiles"
visible="true" id="newFileAndCommentRemove" image="/resources/images/icons/1616/delete.png" />
</listcell>
</listitem>
If what you want is that after the textbox is filled then the first cell will fill with its value you can do it like this:
put an id into the label in the cell
put an onChange operation in the textbox so when the textbox change you can put its value into the cell
like this:
<textbox id="textbox" onChange="label.setValue(self.getValue())"/>
<listbox id="newFileAndComment">
<listhead>
<listheader label="1" width="30px" />
</listhead>
<listitem self="#{each=file}">
<listcell>
<label id="label"/>
</listcell>
</listitem>

How to change grid default status in a ZK theme?

I have a page built with ZK. In this page there is a button that start a search. If there are some data them appear in a grid view.
Every data are built in this way:
v Date1 (dd/mm/yyyy)
- item
- item
- item
v Date2 (dd/mm/yyyy)
- item
- item
Lecter V means an arrow but I can't post an image so I use a "v" that have similar image to undestand.
It works correctely but there is a problem.
I would have this situation:
Date1 (dd/mm/yyyy)
Date2 (dd/mm/yyyy)
When I click on a date I want that the arrow became "v" and all data appear.
If in the first case I click on date it became close.
How to change the default view of grid items?
This is my code
<grid id="demoGrid" width="50%" height="400px" style ="float:left"
model="#bind(vm.value)" emptyMessage="No data">
<columns menupopup="auto">
<column sort="auto(Hour)" label="Hour" width="150px"/>
<column sort="auto(Value)" label="Value(bpm)" hflex="1" />
</columns>
<!-- template for group -->
<template name="model:group">
<group label="#load(each)" />
</template>
<!-- template for each element in model -->
<template name="model" >
<row>
<label value="#load(each.hour)" />
<label value="#load(each.value)" />
</row>
</template>
<!-- template for footer -->
<template name="model:groupfoot">
<groupfoot>
<cell colspan="5" style="text-align: right; padding-right: 15px">
<label value="#load(each)" style="font-weight:bold;" />
</cell>
</groupfoot>
</template>
</grid>
I try to use tag details in this subcode:
<template name="model">
<details open="false">
<row>
<label value="#load(each.hour)" />
<label value="#load(each.value)" />
</row>
</details>
</template>
Try the details like this :
<template name="model">
<row>
<detail open="false">
<hlayout>
<label value="#load(each.hour)" />
<label value="#load(each.value)" />
</hlayout>
</detail>
<label value="second column"/>
</row>
</template>
Explication :
Detail can have only 1 root element so that's why we set the the hlayout.
Of course you can change this to div or whatever you want.
The row tag has to be outside the detail tag.
The detail take a column so for this example you need to provide 2 columns.
Edit :
I created a fiddle.

Strange Checkbox behaviour using MVVM in ZK Framework

I've found strange behaviour of zk checkbox in MVVM. I made a MVVM form that shows list of items and detailed view of selected item. I placed checkbox on detailed view and bind it to boolean property of my POJO. And when I select an item with true value of this property checkbox is displayed checked, but next when I select an item with false value of property and then select an item with true value again checkbox is displayed unchecked.
I can illustrate this issue using ZK's MVVM tutorial http://books.zkoss.org/wiki/ZK_Getting_Started/Get_ZK_Up_and_Running_with_MVVM (source code http://sourceforge.net/projects/zkbook/files/GettingStarted/getzkup-20131127.zip/download )
Add to Car class boolean property:
private Boolean cool = false;
public Car(Integer id, String model, String make, String description, String preview, Integer price, boolean cool){
this.id = id;
this.model = model;
this.make = make;
this.preview = preview;
this.description = description;
this.price = price;
this.cool = cool;
}
public Boolean getCool() {
return cool;
}
public void setCool(Boolean cool) {
this.cool = cool;
}
Change CarServiceImpl.java to initialize boolean property for our demo:
carList.add(
new Car(id++,
"Camry",
"Toyota",
"The Toyota Camry is a midsize car ... ",
"/img/car3.png",
24170, true));
carList.add(
new Car(id++,
"Century",
"Toyota",
"The Toyota Century is ... " ,
"/img/car4.png",
28730, true));
Change searchMvvm.zul (add lines labeled as INSERTED):
<window title="Search" width="600px" border="normal" apply="org.zkoss.bind.BindComposer"
viewModel="#id('vm') #init('tutorial.SearchViewModel')">
<hbox align="center">
Keyword:
<textbox value="#bind(vm.keyword)" />
<button label="Search" image="/img/search.png" onClick="#command('search')" />
</hbox>
<listbox height="160px" model="#bind(vm.carList)" emptyMessage="No car found in the result"
selectedItem="#bind(vm.selectedCar)">
<listhead>
<listheader label="Model" />
<listheader label="Make" />
<listheader label="Price" width="20%"/>
<listheader label="Cool" /> <!-- INSERTED -->
</listhead>
<template name="model">
<listitem>
<listcell label="#bind(each.model)"></listcell>
<listcell label="#bind(each.make)"></listcell>
<listcell>$<label value="#bind(each.price)" /></listcell>
<listcell><checkbox checked="#bind(each.cool)" /></listcell> <!-- INSERTED -->
</listitem>
</template>
</listbox>
<hbox style="margin-top:20px">
<image width="250px" src="#bind(vm.selectedCar.preview)" />
<vbox>
<label value="#bind(vm.selectedCar.model)" />
<label value="#bind(vm.selectedCar.make)" />
<label value="#bind(vm.selectedCar.price)" />
<label value="#bind(vm.selectedCar.description)" />
<checkbox checked="#bind(vm.selectedCar.cool)" label="Cool" /> <!-- INSERTED -->
</vbox>
</hbox>
After that start Tomcat and enter localhost:8080/tutorial/searchMvvm.zul in your browser. When you click on Toyota Camry item everything is ok, but when you click on Nissan Cifiro and then on Toyota Camry again checkbox in detaled view will be displayed unchecked. But checkbox in listbox works fine.
Do you know any workaround to solve this problem?
I have the same problem, but it was fixed when I change getCool() with isCool() (on ZK V7)
I'm using ZK7 and I had the same problem.
I got a :
Property 'standard' not readable on type
on the Boolean standard, which has getter isStandard and setter setStandard
The solution is:
When using Boolean (the object) then you have to use get-Prefix
When using boolean (the primitive) then you can use is-Prefix
That's it !
You should use
checkbox.setCheck(Boolean.valueOf(true));

dynamically creating ids of macro components using arguments

I am trying to create two grids which perform exactly the same function without having to duplicate the code of the code for the grid twice. So, I decided to use a macro component. But, I am not sure how to create the ids of the components in the macro component dynamically. The code does the following:
The first grid(west region) has two rows with two textboxes. If I add "hello" to the first textbox in this grid then the value of the second textbox is also set to "hello".
The second grid(center region) has two rows with two textboxes. If I add "world" to the first textbox in this grid then the value of the second textbox is also set to "world"
The values of both textboxes in the first grid are now same i.e. "hello"
The values of both textboxes in the second grid are now same i.e. "world"
I created a zul file in which I use a macro component like so:
<?component name="mygrid1" macro-uri="grid1.zul" inline="true"?>
<zk>
<vbox hflex="1">
<borderlayout height="500px" width="500px">
<west size="50%">
<mygrid1 id="grid1" index="1" />
</west>
<center>
<mygrid1 id="grid2" index="2" />
</center>
</borderlayout>
</vbox>
</zk>
<zscript>
fillInDuplicateBox(String value, Textbox duplicateBox) {
if (!"".contentEquals(duplicateBox.value))
return;
duplicateBox.value = value;
}
</zscript>
</window>
Macro component is shown below:
<zk>
<vbox hflex="1">
<grid width="300px">
<rows>
<row> Box 1: <textbox id="${concat("newBox", arg.index)}" onChange="fillInDuplicateBox(${concat("newBox, arg.index)}.value, ${concat("duplicateBox", arg.index)})" hflex="1" /></row>
<row> Box 2: <textbox id="${concat("duplicateBox", arg.index)}" hflex="1" /></row>
</rows>
</grid>
</vbox>
</zk>
I also tried the following code to create the macro component
<zk>
<vbox hflex="1">
<grid width="300px">
<rows>
<row> Box 1: <textbox id="newBox${arg.index}" onChange="fillInDuplicateBox(newBox${arg.index}.value, duplicateBox${arg.index})" hflex="1" /></row>
<row> Box 2: <textbox id="duplicateBox${arg.index}" hflex="1" /></row>
</rows>
</grid>
</vbox>
</zk>
None of this works. I am not sure how to dynamically create the ids of the components in the macro component. The textbox ids of the first grid must be "newBox1", "duplicateBox1" and the textbox ids of the second grid must be "newBox2", "duplicateBox2"
Please point out if there is a better way of achieving this task.
Thanks,
Sony
I am not sure if it is possible to dynamically create ids like that, but I am pretty certain it would be better to avoid it. There are better ways to do this by avoiding the id problem altogether and to use data binding or event handling instead. Your example indicates the main purpose for each grid is to copy the value of one Textbox to a different Textbox - I imagine there is something bigger you are trying to achieve so let us know if this answer leads you to what you need or not.
I have simplified and expanded your sample to give two examples, the first uses the onChanging to immediately copy as you type. The second pair of boxes uses databinding.
<?component name="mygrid1" macro-uri="/grid1.zul" ?>
<zk>
<window>
<vbox hflex="1">
<mygrid1 id="grid1" myGridTitle="First" />
<mygrid1 id="grid2" myGridTitle="Another" />
</vbox>
</window>
</zk>
Here is the macro component in grid1.zul:
<zk>
<zscript><![CDATA[
String myBoundString = "initial value";
]]></zscript>
<vbox hflex="1">
<grid>
<rows>
<row>
<hbox><label value="${arg.myGridTitle}" /> Source</hbox>
<textbox id="originalText" hflex="1" onChanging="duplicateText.value = event.value" />
</row>
<row>
<hbox><label value="${arg.myGridTitle}" /> Source copies here:</hbox>
<textbox id="duplicateText" hflex="1" />
</row>
<row>
Bound to myBoundString:
<textbox id="boundText1" value="#{myBoundString}" hflex="1" />
</row>
<row>
Bound to boundText1:
<textbox id="boundText2" value="#{boundText1.value, load-when=boundText1.onChange}" hflex="1" />
</row>
</rows>
</grid>
</vbox>
</zk>
In the databinding example, you have to change "intial value" and then tab away before the binder updates boundText2. Also notice that the TextBoxes do have ids (boundText1 and boundText2) but that has no impact on achieving the expected functionality in multiple instances of the macro component.

Aspx grid view FileUpload

Bllow is my AspxGridview syntax
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" KeyFieldName="Menu_ID"
OnCellEditorInitialize="ASPxGridView1_CellEditorInitialize" OnCustomUnboundColumnData="ASPxGridView1_CustomUnboundColumnData">
<Columns>
<dx:GridViewCommandColumn VisibleIndex="0">
<EditButton Visible="True">
</EditButton>
<NewButton Visible="True">
</NewButton>
<DeleteButton Visible="True">
</DeleteButton>
<CustomButtons>
<dx:GridViewCommandColumnCustomButton Text="Create a Copy" ID="Copy" />
</CustomButtons>
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn Caption="Module_ID" FieldName="Module_ID" UnboundType="Integer"
VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataButtonEditColumn Caption="Target_URL" FieldName="Target_URL" UnboundType="String"
VisibleIndex="2">
<PropertiesButtonEdit>
<Buttons>
<dx:EditButton Text=".." Width="5px">
</dx:EditButton>
</Buttons>
</PropertiesButtonEdit>
</dx:GridViewDataButtonEditColumn>
<dx:GridViewDataTextColumn Caption="Menu_ID" FieldName="Menu_ID" UnboundType="Integer"
VisibleIndex="3">
</dx:GridViewDataTextColumn>
</Columns>
</dx:ASPxGridView>
AspxGridview edit/insert mode Click on Target_URL column button i want to FileUpload .
Please take a look at the following example posted in our site:
http://www.devexpress.com/Support/Center/CodeCentral/ViewExample.aspx?exampleId=E95