Revision history [back]

click to hide/show revision 1
initial version

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

ibnwildan07 gravatar image ibnwildan07

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

index.zul :

<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.");
    }
}

}

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

index.zul :

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

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

sun.jvm.hotspot.HelloWorld.e; public class viewmodel extends SelectorComposer<window> {

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.");
     }
    }

}

}

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

index.zul :

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

</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.");
        }
    }

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