0

ZK取得某列某listcell的id 錯誤

asked 2011-02-15 07:45:12 +0800

unitcell gravatar image unitcell
28 4

updated 2011-02-15 07:47:04 +0800

Hi all,

操作圖
操作功能:
所有欄位預設readonly is true.
當使用者選某列(row)後, 按下修改按鈕,
我想取得該列(row)的第一欄位,如圖,FirstName的id 並設readonly is false,
當第一個欄位Enter(onOK) 再取得第二欄位LastName的id 並設為 readonly is false, 同時第一欄位設為readonly is true.

目前遇到 當按下修改Button後, 會得到"Fellow component not found: id_frist" 訊息.
不知如何解決?

Thanx.

listbox_binding.zul

<?page title="Data binding 5" contentType="text/html;charset=UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<window id="win" title="Data binding 5" border="normal" use="com.sanq.test.Listbox_binding_win">
  <zscript><![CDATA[
     //prepare the sample List
        import com.sanq.test.Person;
        int count = 3;
        List persons = new ArrayList();
        for(int j= 1; j <= count; ++j) {
            Person personx = new Person();
            personx.setFirstName("Tony"+j);
            personx.setLastName(""+j);     
            persons.add(personx);
        }
     ]]></zscript>
  
    <listbox rows="4" model="@{persons}">
        <listhead>
            <listheader label="First Name" width="100px" />
            <listheader label="Last Name" width="100px" />
            <listheader label="Full Name" width="100px" />
        </listhead>
        <!-- define variable person here-->
        <listitem self="@{each='person'}">
            <listcell>
                <textbox id="id_first" value="@{person.firstName}" readonly="true"/>
            </listcell>
            <listcell>
                <textbox id="id_last" value="@{person.lastName}" readonly="true"/>
            </listcell>
            <listcell id="id_full" label="@{person.fullName}"/>
        </listitem>
    </listbox>
    <separator bar="false"/>
          <hbox>
           <button label="修改F3" onClick="win.onModify()"/>
         </hbox>
</window>

Controller, Listbox_binding_win.java

package com.sanq.test;
 
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;
 
public class Listbox_binding_win extends Window {
 
  public void onModify() {
    Textbox tb = (Textbox) getFellow("id_first");
    //tb.setReadonly(false);
    //tb.setFocus(true);
  }
}

delete flag offensive retag edit

2 Replies

Sort by » oldest newest

answered 2011-03-03 22:40:51 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

<listitem self="@{each='person'}">
            <listcell>
                <textbox id="id_first" value="@{person.firstName}" readonly="true"/>
            </listcell>
            <listcell>
                <textbox id="id_last" value="@{person.lastName}" readonly="true"/>
            </listcell>
            <listcell id="id_full" label="@{person.fullName}"/>
        </listitem>

DataBinder will remove all ids in the "template" listitem; otherwise, there will be "Duplicate" id for each listitem.

You can traverse the component tree to get the component you need.

getSelectedItem().getFirstChild().getFirstChild(); //get id_first textbox
getSelectedItem().getFirstChild().getNextSibling().getFirstChild(); //get id_last textbox

link publish delete flag offensive edit

answered 2011-03-05 08:05:14 +0800

unitcell gravatar image unitcell
28 4

updated 2011-03-05 08:06:31 +0800

Finally, I got it fixed ZK task it work fine, Thank you for your help, Henri.

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: 2011-02-15 07:45:12 +0800

Seen: 1,210 times

Last updated: Mar 05 '11

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