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?
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.
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 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.
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;
}
}
Hi I'm unable to create a new object that is a subclass I think that's what you call it it saying virtual isn't allowed what must I do to correct this here is my code.
public class PagerBuilder {
private virtual class PagerLink
{
public string Title { get; set;}
public int PageNo { get; set; }
public string Class { get;set;}
}
private readonly List<PagerLink> _pagerLinks = new List<PagerLink>();
private readonly string _urlTemplate;
public PagerBuilder(string urlTemplate)
{
_urlTemplate = urlTemplate;
}
public string PagerClass { get;set;}
public void AddPage(string title, int pageNo)
{
AddPage(title, pageNo, string.Empty);
}
public void AddPage(string title, int pageNo, string itemClass)
{
PagerLink link = new PagerLink();
}
}
First, I would move PagerLink outside of the PagerBuilder class and define it separately (in a new file as well).
Second, you don't need virtual to subclass PagerLink (It's not even valid, in fact). If you want it to be abstract, use the abstract keyword instead, but this code won't compile (at PagerLink link = new PagerLink() until you define a concrete implementation of PagerLink. You don't need to use abstract to inherit from PagerLink, though. Just do this:
public class CustomPagerLink: PagerLink
{
//Subclass implementation
}
You want to remove virtual from your class definition.
private class PagerLink
{
public string Title { get; set;}
public int PageNo { get; set; }
public string Class { get;set;}
}