tags:

views:

155

answers:

1

I use Netbeans 6.8 and try to obtain user interface by using metawidget and JPA. I cannot say

@Action
public void save( ActionEvent event )
{
    mSearchMetawidget.save();
}

This annotation gives "incompatible types" error when I add following import.

import org.metawidget.inspector.impl.actionstyle.Action;

What to do? How can I add an action related to my User entity. I want to do "register" action. Thanks in advance

Response to Richard

I thought @Action was a Metawidget annotation and got a headache due to import errors.I get it now.I also need to add swing libraries. @Action annotation belongs to SwingAppFramework.

In fact, we want to update our database records from User Interfaces that are automatically extracted by Metawidget. We have created entity classes and are trying to modify them to serve the purpose. How can we say to our User Interface classes that when a button is pressed, using the entered data in interface fields, the records are updated?

Thanks.

Response 2 to Richard

I want to use JPA's EntityManager. Should the code that is related to EntityManager be added in button's action Listener? For the following class, its listener is addUser()

I have an entity class, User.java

package datamodeldemo;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
import org.metawidget.inspector.annotation.*;
import org.metawidget.inspector.annotation.UiAction;

import org.metawidget.inspector.commons.jexl.UiJexlAttribute;

@Entity
@Table(name="ShineeUser")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="USER_TYPE",
              discriminatorType= DiscriminatorType.STRING, length=20)

public class User implements Serializable
{

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="USER_ID", nullable = false)
    private Integer user_id;

    @Column(name="USER_NAME", nullable = false)
    private String user_name;

    @Column(name="PASSWORD", nullable = false)
    private String password;

    @Column(name="USER_TYPE")
    private UserType userType;

    @Column( name = "EMAIL")
    private String e_mail;

    @Column( name = "TELEPHONE")
    private String telephone;

    public enum UserType {customer, hotelAdmin, agencyAdmin};

    @UiHidden
    public Integer getId() {
        return user_id;
    }

    public void setId(Integer id) {
        this.user_id = id;
    }

    @UiComesAfter( "user_name" )
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @UiComesAfter( "user_id" )
    public String getUser_name() {
        return user_name;
    }

    public void setUser_name(String user_name) {
        this.user_name = user_name;
    }

    @UiComesAfter( "password" )
    public UserType getUserType() {
        return userType;
    }

    public void setUserType(UserType userType) {
        this.userType = userType;
    }
     @UiComesAfter( "userType" )
    public String getE_mail() {
        return e_mail;
    }

    public void setE_mail(String e_mail) {
        this.e_mail = e_mail;
    }
     @UiComesAfter( "e_mail" )
    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (user_id != null ? user_id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof User)) {
            return false;
        }
        User other = (User) object;
        if ((this.user_id == null && other.user_id != null) ||
            (this.user_id != null && !this.user_id.equals(other.user_id))) {
                return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "datamodeldemo.User[id=" + user_id + "]";
    }

    @UiAction
    @UiJexlAttribute( name = "HIDDEN", expression = "this.user != null" )
    public void addUser()
    {
        //Database update???
    }
}

Thank you.

A: 

Hi Gulcan,

I believe you are making a typo. org.metawidget.inspector.impl.actionstyle.Action is an interface, not an annotation. I believe you meant:

@UiAction

Unless, of course, you meant to use the SwingAppFramework @Action annotation, in which case you need to ensure your imports are not clashing. You should use:

@org.jdesktop.application.Action

Hope that helps.

Richard.

Richard Kennard
Hi,thanks for your reply.I thought @Action was a Metawidget annotation and got a headache due to import errors.I get it now.I also need to add swing libraries.I was actually trying your CarDemo application.I adapted my code according to it,however I get null pointer exception due to action listeners and "org.metawidget.widgetprocessor.iface.WidgetProcessorException: java.lang.reflect.InvocationTargetException".I haven't quite get why.I add action listener but it comes later in the execution, first comes fireActionEvent method which tries to execute null action listeners.Any hint? please.
Gulcan
@Richard Stack Overflow is not designed for posting multiple times within a question. Users are encouraged to post one answer, and to modify it if necessary. Please remove your other posts here, or merge them into this accepted post. Thank you.
Jonathan Sampson