0

How do I edit a List<String> within a listbox directly?

asked 2015-11-18 02:23:25 +0800

KlausWr gravatar image KlausWr
37 5

I know how to edit a List<pojo> by using a listbox. But when I try to use a listbox to edit a simple List<string>, I always get an exception

org.zkoss.zk.ui.UiException: java.lang.Long cannot be cast to java.lang.String

class EditableListboxViewModel:

public class EditableListboxViewModel {

    List<String> list = new ArrayList<String>();

    @Init
    public void init() {
        list.add("test");
        list.add("test");
    }

    public List<String> getList() {
        return list;
    }
}

EditableListbox.zul:

<zk>
    <vbox apply="org.zkoss.bind.BindComposer"
        viewModel="@id('vm') @init('experiment.EditableListboxViewModel')">

        <listbox model="@bind(vm.list)">
            <template name="model">
                <listitem>
                    <listcell>
                        <textbox value="@bind(each)" />
                    </listcell>
                </listitem>
            </template>
        </listbox>
    </vbox>
</zk>

I also tried the following (as I thought an immutable string might be the problem):

@Init
public void init() {
    list.add(new String("test"));   
    list.add(new String("test"));   
}
delete flag offensive retag edit

Comments

Klaus, is it possible to create a fiddle with this problem? the problem doesn't come from this part of code normally

chillworld ( 2015-11-18 06:32:32 +0800 )edit

http://temp.zkfiddle.org:8080/t651svt/1k96gre/6/ Does only fail with exception when run in 6.5 - but does not really work in 8. BTW: the original fiddle is here: http://zkfiddle.org/sample/1k96gre/7-How-do-I-edit-a-List-of-String-within-a-listbox-directly

KlausWr ( 2015-11-18 07:22:46 +0800 )edit

I'm actually not able to get it working in any version. The conversion in 6.5 is probably a bug what's resolved, but I can't change the value also directly, no matter what I try

chillworld ( 2015-11-18 08:47:07 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-11-18 10:00:39 +0800

Darksu gravatar image Darksu
1991 1 4

Hello KlausWr,

I found the following fiddle that uses a grid:

http://zkfiddle.org/sample/skqfup/7-Array-binding-bug#source-1

Between us using a pojo probably is the best method from a design perspective.

Best Regards,

Darksu

link publish delete flag offensive edit
Your answer
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
1 follower

RSS

Stats

Asked: 2015-11-18 02:23:25 +0800

Seen: 43 times

Last updated: Nov 18 '15

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