0

data binding and IF attribute

asked 2010-06-15 11:44:24 +0800

mguilherme gravatar image mguilherme
132 3

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)

delete flag offensive retag edit

18 Replies

Sort by ยป oldest newest

answered 2010-06-15 12:03:43 +0800

jj gravatar image jj
638 3

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>

link publish delete flag offensive edit

answered 2010-06-15 12:23:38 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

updated 2010-06-15 12:24:00 +0800

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 ;
}

link publish delete flag offensive edit

answered 2010-06-15 13:39:05 +0800

jj gravatar image jj
638 3

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.

link publish delete flag offensive edit

answered 2010-06-16 05:44:25 +0800

mguilherme gravatar image mguilherme
132 3

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

link publish delete flag offensive edit

answered 2010-06-16 09:28:00 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

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.

link publish delete flag offensive edit

answered 2010-06-16 10:00:56 +0800

mguilherme gravatar image mguilherme
132 3

updated 2010-06-16 11:06:07 +0800

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.

link publish delete flag offensive edit

answered 2010-06-16 11:08:22 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

updated 2010-06-16 11:11:54 +0800

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>

link publish delete flag offensive edit

answered 2010-06-16 11:34:49 +0800

mguilherme gravatar image mguilherme
132 3

caclark thanks again for ure answer.

The getValue() is returning NULL :(

java.lang.NullPointerException: Attempt to invoke method isOverdue on null value

link publish delete flag offensive edit

answered 2010-06-16 14:41:13 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

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

link publish delete flag offensive edit

answered 2010-06-17 03:43:13 +0800

mguilherme gravatar image mguilherme
132 3

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>

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-06-15 11:44:24 +0800

Seen: 1,834 times

Last updated: Feb 17 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More