I am creating a PropertySheet and I want to add a Property to the sheet. The problem is, what happens if the value of the property changes, the PropertySheet needs to update to reflect those changes. How would I do this?
import java.util.Map;
import javafx.beans.property.Property;
import org.controlsfx.control.PropertySheet;
public class PropertyItem implements PropertySheet.Item {
private Map<String, Property> map;
private String key;
private String name;
private String description;
PropertyItem(Map<String, Property> map, String key, String name, String description){
this.map = map;
this.key = key;
this.name = name;
this.description = description;
}
#Override
public String getCategory() {
return null;
}
#Override
public String getDescription() {
return description;
}
#Override
public String getName() {
return name;
}
#Override
public Class<?> getType() {
return map.get(key).getValue().getClass();
}
#Override
public Object getValue() {
return map.get(key).getValue();
}
#Override
public void setValue(Object arg0) {
map.get(key).setValue(arg0);
}
}
This is probably too late but anyway...
The property editor uses the following method from PropetySheet.Item interface to listen to value changes.
optional<ObservableValue<? extends Object>> getObservableValue();
You need to implement this method on your PropertyItem class.
Related
I am trying to implement a star rating system using Firebase realtime database and I get the following error:
No setter/field for rating found on class com.andrea.uncut.ui.Model.Post
I know this can happen when variables are not named the same as in the database but in this case they are:
public class Post {
private String postID;
private String postImage;
private float rating;
private String title;
private String description;
private String publisher;
public Post(String postID, String postImage, float rating, String title, String description, String publisher) {
this.postID = postID;
this.postImage = postImage;
this.rating = rating;
this.title = title;
this.description = description;
this.publisher = publisher;
}
public Post() {
}
public String getPostid() {
return postID;
}
public void setPostid(String postID) {
this.postID = postID;
}
public String getPostImage() {
return postImage;
}
public void setPostImage(String postImage) {
this.postImage = postImage;
}
public float getRatingScore() { return rating; }
public void setRatingScore(float rating) {
this.rating = rating;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
}
All the other variables work fine so could it be anything related to the type being float?
getRatingScore and setRatingScore would be used for a property called ratingScore.
Your property is called rating, so it would need to be getRating and setRating.
The private internal properties have nothing to do with how Firebase sees them when setting data on the model class.
Plus, postID should be getPostID and setPostID for consistency.
I implemented an upload image in a fragment. I have a model named Beach.java. However, I'm encountering an error
Cannot resolve constructor 'Beach(java.lang.string,
java.lang.string)' on newBeach = new
Beach(beach_name.getText().toString(), uri.toString());
Here is the code in HomeFragment:
imageFolder.putFile(saveUri)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
mDialog.dismiss();
Toast.makeText(getActivity(), "Uploaded", Toast.LENGTH_SHORT).show();
imageFolder.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
#Override
public void onSuccess(Uri uri) {
newBeach = new Beach(beach_name.getText().toString(), uri.toString());
}
});
}
})
Here is the code in Beach.class:
public class Beach {
private String name, image, description, price, menuID;
public Beach() {
}
public Beach(String name, String image, String description, String price, String menuID) {
this.name = name;
this.image = image;
this.description = description;
this.price = price;
this.menuID = menuID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getMenuID() {
return menuID;
}
public void setMenuID(String menuID) {
this.menuID = menuID;
}
}
Your Beach class defines 2 constructors, one with no parameters :
public Beach()
and one with 5 Strings :
public Beach(String name, String image, String description, String price, String menuID)
And you try to call a constructor with 2 Strings, which is no where to be found :
new Beach(beach_name.getText().toString(), uri.toString());
So you should add the below constructor to you Beach class :
public Beach(String name, String image) {
this.name = name;
this.image = image;
}
You don't have constructor with 2 parameters of String.
You can initialize class Beach with :
new Beach(name, image, description, price, menuID)
or with
new Beach()
If you want create with only 2 string add another constructor:
public Beach(String name, String image){....}
I have a model class:
public class Client {
private long id;
private String name;
#Override
public String toString() {
return this.name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
and I have a Textfield that I want to use auto complete using a list of Client class, using ControlsFX, here is what I did:
AutoCompletionBinding<Client> binding = TextFields.bindAutoCompletion(searchField, SuggestionProvider.create(appState.clients));
Where appStat.Clients is a list of Client class. For some reason I get no suggestions appearing. What am I doing wrong?
Hey guys i have stuck in the hibernate Relation with spring MVC , I have class like Student and this class is having the OneToOne relation with the Parent class ,My Error is When i tried to delete Student Object the parent Object Doesn't allow to delete the Student Object
It is giving an error like
Hibernate: delete from Student where id=?
WARN : org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 1451, SQLState: 23000
ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Cannot delete or update a parent row: a foreign key constraint fails (`digischool`.`parent`, CONSTRAINT `FK_l65r4icaxmteeq1tg96t6n3ol` FOREIGN KEY (`student_id`) REFERENCES `student` (`id`))
"
i have Student Model Class like
#Entity
public class Student implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private long id;
private String name;
private Parent parent;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
#OneToOne(mappedBy="student",fetch=FetchType.EAGER)
public Parent getParent() {
return parent;
}
public void setParent(Parent parent) {
this.parent = parent;
}
}
Parent model class like
#Entity
public class Parent {
private long id;
private String name;
private String phoneNumber;
private String email;
private String relation;
private Student student;
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
#OneToOne(fetch=FetchType.EAGER)
#JoinColumn(name="student_id")
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
public String getRelation() {
return relation;
}
public void setRelation(String relation) {
this.relation = relation;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
In order to delete Student Object i have written DAO like
public boolean deleteStudent(long studentId) {
if(studentId > 0){
Session session = getSessionFactory().getCurrentSession();
Query query = session.createQuery("DELETE FROM Student S WHERE S.id = :studentId");
query.setParameter("studentId", studentId);
int rowChanged = query.executeUpdate();
if(rowChanged > 0){
return true;
}
}
return false;
}
My db is looks like
Please help me out i am new bee to this Spring World
This is because you are forgeting to remove the relationship from the parent entity prior to deleting the student.
the way to do this:
public boolean deleteStudent(long studentId) {
if(studentId > 0){
// get parent object
parent.setStudent(null); // THIS REMOVES THE RELATIONSHIP FROM PARENT CLASS SINCE ITS STORED THERE
// save parent object with emptied student field
Session session = getSessionFactory().getCurrentSession();
Query query = session.createQuery("DELETE FROM Student S WHERE S.id = :studentId");
query.setParameter("studentId", studentId);
int rowChanged = query.executeUpdate();
if(rowChanged > 0){
return true;
}
}
return false;
}
FYI
use the hibernates own functions when you can.
check out this link for some ways to delete a object http://www.codejava.net/frameworks/hibernate/hibernate-basics-3-ways-to-delete-an-entity-from-the-datastore
You can use attribute orphanRemoval = true with annotation #OneToOne with your Parent entity
#OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
public Student getStudent() {
return student;
}
....
hope it help.
I a trying to send object from client to server. Below is the Controller using spring mvc.
#Controller
public class HomeController {
public class User{
public String name;
public String email;
public User() {
super();
}
public User(String name, String email) {
super();
this.name = name;
this.email = email;
}
public String getName() {
return name;
}
public String getEmail() {
return email;
}
public void setName(String name) {
this.name = name;
}
public void setEmail(String email) {
this.email = email;
}
}
#RequestMapping(value="/getUsers", method= RequestMethod.POST)
public #ResponseBody User getUser(User user){
return user;
}}
In client side I am sending object in post like this
http://localhost:2015/spring/getUsers
POST /spring/getUsers HTTP/1.1
Host: localhost:2015
Cache-Control: no-cache
{"name":"vinod", "email":"vinod#gmaol.com" }
But I am getting error at server side like this
HTTP Status 500 - Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.vinod.spring.HomeController$User]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.vinod.spring.HomeController$User.<init>()
Try make the refactoring for your User class to another file, and put a reference of it in your controller using the #Resource annotation. Maybe the exception was throwed because User class is nested.
Example:
User.java
#Component
public class User{
public String name;
public String email;
public User() {
super();
}
public User(String name, String email) {
super();
this.name = name;
this.email = email;
}
public String getName() {
return name;
}
public String getEmail() {
return email;
}
public void setName(String name) {
this.name = name;
}
public void setEmail(String email) {
this.email = email;
}
}
HomeController.java
#Controller
public class HomeController {
#Resource
User user;
#RequestMapping(value="/getUsers", method= RequestMethod.POST)
public #ResponseBody User getUser(User user){
return user;
}
}