0

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
1

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

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

index.zul :

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

    <listbox id="lb" width="200" height="300"  >
    <listhead>
        <listheader label="ID" sort="auto"/>
        <listheader label="Nama"/>   
        <listheader label="email"/>
        <listheader label="Address"/>
        <listheader label="Phone"/>
        <listheader label="Action"/>
    </listhead>
    <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}"/>
        <listcell>
            <button label="Edit" onClick="@command('edit', mahasiswa=mahasiswa)" />
            <button label="Hapus" onClick="@command('hapus', mahasiswa=mahasiswa)" />
    </listcell>

    </listitem>
    </listbox>

</window>
</zk>

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> {

    @Wire
    private Textbox nametxt;
    @Wire
    private Textbox emailtxt;

    @Command
    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);

            statement.executeUpdate();

            statement.close();
            connection.close();

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

}
delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

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

hawk gravatar image hawk
3250 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

Follow

RSS

Stats

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

Seen: 4 times

Last updated: May 26 '23

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