-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Can someone tell me why this isn't working:
<row if="@{controller.taskBean.state.value == 1}"> <label value="Data de Inicio" /> <datebox value="@{controller.taskBean.startDate}" format="dd/MM/yyy" readonly="true" buttonVisible="false" cols="20" /> </row>
I just want this row visible when value is 1 (int)
This may work. Just change the @ to $ for if condition
<row if="${controller.taskBean.state.value == 1}"> <label value="Data de Inicio" /> <datebox value="@{controller.taskBean.startDate}" format="dd/MM/yyy" readonly="true" buttonVisible="false" cols="20" /> </row>
No, it won't work. The if is evaluated at rendering time which is much earlier than databinding is available. Changing it from @ to $ changes it from databinding to EL. You have to hook doBeforeCompose(...) to make sure taskBean has a value otherwise that will fail, too.
You can try using the visible attribute of the row and use a convenience method in your controller:
<row visible="@{controller.isItTheCorrectState}"> <label value="Data de Inicio" /> <datebox value="@{controller.taskBean.startDate}" format="dd/MM/yyy" readonly="true" buttonVisible="false" cols="20" /> </row>
public boolean isItTheCorrectState() { return taskBean.state.value == 1 ; }
caclark,
it is true that taskBean.state has to exist before the rendering, otherwise u'll have nullpointer exception, but moving the if to the rendering phase will serve the purpose of showing the row when the initial state value is 1. The databinding in datebox would still work, I believe. I think that I had tried this a while back and it was working (v 3.6.x).
Your example will make the row behavior more dynamic, that is, when the state changes during subsequent action on the same page, the row will appear or disappear. I am not sure if that was the original requirement.
Hello there, many thanks for this, it's working now :D
public boolean hasTaskStarted() { return taskBean.getState().getValue() == 1 || taskBean.getState().getValue() == 2; }
I've a similar problem that in the past was working, I've a binded listbox wich I want to change the color to red in particular cases.
<listitem self="@{each=task}" forward="onClick=tasksTabWindow.onClickTask"> <zscript> <![CDATA[ if(task.isOverdue()) self.setStyle("color: red"); ]]> </zscript>
But now it is not working anymore, I can't access isOverdue() method of the bean
Is it giving an error in the log or silently failing? I'd try a S.o.p and write out task and task.isOverdue() to see what it shows. I would have thought with it being inside zscript that task would be visible.
It's failing because I'm trying to call a method from bean and not an attribute:
org.zkoss.zk.ui.UiException: Sourced file: inline evaluation of: `` if(task.isOverdue()) self.setStyle("color: red"); . . . '' : Attempt to resolve method: isOverdue() on undefined variable or class name: task : at Line: 15 : in file: inline evaluation of: `` if(task.isOverdue()) self.setStyle("color: red"); . . . '' : task .isOverdue ( )
Another problem is that I can't pass arguments to methods with something like this: style="@{controller.isOverdue('1')}", assuming I'm rewriting the isOverdue method on the controller.
Yeah, task is definitely not visible. I thought it would be because of the self="@ { each=task } ". Just poking in the dark, but you might try:
<listitem self="@{each=task}" forward="onClick=tasksTabWindow.onClickTask" value="@{task}"> <zscript> <![CDATA[ if(self.getValue().isOverdue()) self.setStyle("color: red"); ]]> </zscript> </listitem>
caclark thanks again for ure answer.
The getValue() is returning NULL :(
java.lang.NullPointerException: Attempt to invoke method isOverdue on null value
Did you put the value attribute on the listitem as in my example?
<listitem self="@{each=task}" forward="onClick=tasksTabWindow.onClickTask" value="@{task}"> <============= add value attribute
It doesn't make any difference, allways NULL:
<listbox mold="paging" model="@{controller.tasksBean}" width="99.5%" height="100%" id="tasksList" pageSize="15"> <listhead> <listheader label="Titulo" /> <listheader label="Supervisor" /> <listheader label="Limite" image="img/date.png"/> <listheader label="Estado" width="80px"/> </listhead> <listitem self="@{each=task}" forward="onClick=tasksTabWindow.onClickTask" value="@{task}" > <zscript> <![CDATA[ System.out.println(self.getValue()); ]]> </zscript> <listcell label="@{task.taskDefinition.title}" /> <listcell label="@{task.supervisor}" /> <listcell label="@{task.dueDate, converter='org.zkoss.zkplus.databind.DateFormatConverter' self='@{format(dd/MM/yyyy)'}" /> <listcell label="@{task.state.title}" /> </listitem> </listbox>
Asked: 2010-06-15 11:44:24 +0800
Seen: 1,834 times
Last updated: Feb 17 '12