org.zkoss.zk.ui.metainfo.PropertyNotFoundException: Method setViewModel not found for class data.controller

asked 2023-05-26 01:03:59 +0800

ibnwildan07 gravatar image ibnwildan07

updated 2023-05-26 12:20:53 +0800

hawk gravatar image hawk
3205 1 5
http://hawkphoenix.blogsp... ZK Team

index.zul :

<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<style src="/styles.css" />
<window apply="org.zkoss.bind.BindComposer" id="win" use="data.controller" viewModel="viewmodel">
    <grid width="270px">
        <label value="Name:"/>
        <textbox id="nametxt" width="100px" sclass="my-input" />
        <label value="Email:" />
        <textbox id="emailtxt" width="100px" sclass="my-input" />
        <button label="Submit" sclass="my-button" onClick="@command('tambahdata')"/>

    <listbox id="lb" width="200" height="300"  >
        <listheader label="ID" sort="auto"/>
        <listheader label="Nama"/>   
        <listheader label="email"/>
        <listheader label="Address"/>
        <listheader label="Phone"/>
        <listheader label="Action"/>
    <listitem forEach="${win.customers}" value="${each}">
        <listcell label="${each.id}"/>    
        <listcell label="${each.nama}"/>
        <listcell label="${each.email}"/>
        <listcell label="${each.address}"/>
        <listcell label="${each.phone}"/>
            <button label="Edit" onClick="@command('edit', mahasiswa=mahasiswa)" />
            <button label="Hapus" onClick="@command('hapus', mahasiswa=mahasiswa)" />



viewmodel.java :

//package data;
package foo;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zul.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.zkoss.bind.annotation.Command;
import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Textbox;
import static sun.jvm.hotspot.HelloWorld.e;

public class viewmodel extends SelectorComposer<Window> {

    private Textbox nametxt;
    private Textbox emailtxt;

    public void tambahdata() throws SQLException {

        String name = nametxt.getValue();
        String email = emailtxt.getValue();

        try {
            Connection connection = DriverManager.getConnection("jdbc:derby://localhost:1527/app");
            PreparedStatement statement = connection.prepareStatement("INSERT INTO YourTable (name, email) VALUES (?, ?)");

            statement.setString(1, name);
            statement.setString(2, email);



            Messagebox.show("Data inserted successfully!");
        catch (SQLException e) {
            Messagebox.show("Error occurred while inserting data.");

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2023-05-26 12:23:13 +0800

hawk gravatar image hawk
3205 1 5
http://hawkphoenix.blogsp... ZK Team

updated 2023-05-26 12:28:51 +0800

After reading your code, I found you mix MVC and MVVM patterns together and contains some wrong usages. I suggest you reading Get ZK Up and Running with MVC which can help you understand basic concepts.

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




Asked: 2023-05-26 01:03:59 +0800

Seen: 3 times

Last updated: May 26

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