I am doing program similar on ContactList, but when I try to add information, I can't see my information. But if I do nine clicks, I can see scrolling.
I have my work file, end prtsc fxml file below.
#FXML
private void initialize() throws IOException {
iniData();
id.setCellValueFactory(new PropertyValueFactory<Work, Integer>("id"));
Fname.setCellValueFactory(new PropertyValueFactory<Work, String>("fname"));
Lname.setCellValueFactory(new PropertyValueFactory<Work, String>("lname"));
Phone.setCellValueFactory(new PropertyValueFactory<Work, String>("phone"));
Email.setCellValueFactory(new PropertyValueFactory<Work, String>("email"));
table.setItems(arr);
addName.setPromptText("fname");
addName.setMaxWidth(Fname.getPrefWidth());
addLName.setPromptText("lname");
addLName.setMaxWidth(Lname.getPrefWidth());
addPhone.setPromptText("phone");
addPhone.setMaxWidth(Phone.getPrefWidth());
addEmail.setPromptText("email");
addEmail.setMaxWidth(Email.getPrefWidth());
btn01.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
arr.add(new Work(addName.getText(),
addLName.getText(), addPhone.getText(), addEmail.getText()));
} } ); }
public void iniData() throws IOException {
arr.add(new Work(1, "Alex", "qwerty", "33333","alex#mail.com"));
arr.add(new Work(2, "Bob", "dsfsdfw","0987432", "bob#mail.com"));
arr.add(new Work(3, "Jeck", "dsfdsfwe","345743", "Jeck#mail.com"));
arr.add(new Work(4, "Mike", "iueern","32456", "mike#mail.com"));
arr.add(new Work(5, "colin", "woeirn","12233455", "colin#mail.com"));
}}
My Work java file.
public class Work implements Serializable{
private Integer id;
private String Fname;
private String Lname;
private String Phone;
private String Email;
private String addFname;
private String addLname;
private String addPhone;
private String addEmail;
public Work(Integer id, String fname, String lname, String phone, String email) {
this.id = id;
Fname = fname;
Lname = lname;
Phone = phone;
Email = email;
}
public Work(String addFname, String addLname, String addPhone, String addEmail) {
this.addFname = addFname;
this.addLname = addLname;
this.addPhone = addPhone;
this.addEmail = addEmail;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getFname() {
return Fname;
}
public void setFname(String fname) {
Fname = fname;
}
public String getLname() {
return Lname;
}
public void setLname(String lname) {
Lname = lname;
}
public String getPhone() {
return Phone;
}
public void setPhone(String phone) {
Phone = phone;
}
public String getEmail() {
return Email;
}
public void setEmail(String email) {
Email = email;
}
public String getAddFname() {
return addFname;
}
public void setAddFname(String addFname) {
this.addFname = addFname;
}
public String getAddLname() {
return addLname;
}
public void setAddLname(String addLname) {
this.addLname = addLname;
}
public String getAddPhone() {
return addPhone;
}
public void setAddPhone(String addPhone) {
this.addPhone = addPhone;
}
public String getAddEmail() {
return addEmail;
}
public void setAddEmail(String addEmail) {
this.addEmail = addEmail;
}
}
this is the link to view fxml file
As your not using properties in your Work class you have to set the cell like
FName.setCellValueFactory(new Callback<CellDataFeatures<Work, String>, ObservableValue<String>>() {
public ObservableValue<String> call(CellDataFeatures<Work, String> p) {
return new ReadOnlyObjectWrapper(p.getValue().getFname());
}
});
As an alternate you could use properties but aus they are not serializable you have to override the functions for reading and writing object as discribed here
Related
please i get this errror on logcat when i use restclient to get a list. it works on desktop just after deploymnet to android
java.lang.NoSuchMethodException: ...dto.Meeting.()
its pops up more than the number of record i have in my list
WARNING: Failed to create object of type class .Meeting from the following json object {"id":1,"topic":"leksyde","description":"123e4","location":"7623","longitude":"45","latitude":"10","category":null,"datetime":"9839823"}
primary.setShowTransitionFactory(BounceInRightTransition::new);
RestClient restClient = RestClient.create()
.method("GET")
.host(LISTOFMEETINGS);
// create a custom Converter that is able to parse the response into a list of objects
InputStreamIterableInputConverter<Meeting> converter = new ItemsIterableInputConverter<>(Meeting.class);
// retrieve a list from the DataProvider
GluonObservableList<Meeting> data = DataProvider.retrieveList(restClient.createListDataReader(converter));
data.initializedProperty().addListener((obs, ov, nv) -> {
if (nv) {
for (Meeting meet: data) {
meetingslv.setItems(meet);
}
}
});
meeting.java
public class Meeting {
private IntegerProperty id = new SimpleIntegerProperty();
private StringProperty topic = new SimpleStringProperty();
private StringProperty description = new SimpleStringProperty();
private StringProperty location = new SimpleStringProperty();
private StringProperty longitude = new SimpleStringProperty();
private StringProperty latitude = new SimpleStringProperty();
private StringProperty datetime = new SimpleStringProperty();
private StringProperty category = new SimpleStringProperty();
public Meeting() {
}
public Meeting(int id, String topic, String description, String location, String longitude, String latitude, String datetime, String category) {
this.id = new SimpleIntegerProperty(id);;
this.topic = new SimpleStringProperty(topic);
this.description = new SimpleStringProperty(description);
this.location = new SimpleStringProperty(location) ;
this.longitude = new SimpleStringProperty(longitude);
this.latitude = new SimpleStringProperty(latitude);
this.datetime = new SimpleStringProperty(datetime);
this.category = new SimpleStringProperty(category);
}
public int getId() {
return id.get();
}
public IntegerProperty IdProperty() {
return id;
}
public void setId(int id) {
this.id.set(id);
}
public String getTopic() {
return topic.get();
}
public StringProperty TopicProperty() {
return topic;
}
public void setTopic(String id) {
this.topic.set(id);
}
public String getDescription() {
return description.get();
}
public StringProperty DescriptionProperty() {
return description;
}
public void setDescription(String id) {
this.description.set(id);
}
public String getLocation() {
return location.get();
}
public StringProperty LocationProperty() {
return location;
}
public void setLocation(String id) {
this.location.set(id);
}
public String getLongitude() {
return longitude.get();
}
public StringProperty LongitudeProperty() {
return longitude;
}
public void setLongitude(String id) {
this.longitude.set(id);
}
public String getLatitude() {
return latitude.get();
}
public StringProperty LatitudeProperty() {
return latitude;
}
public void setLatitude(String id) {
this.latitude.set(id);
}
public String getDatetime() {
return datetime.get();
}
public StringProperty DatetimeProperty() {
return datetime;
}
public void setDatetime(String id) {
this.datetime.set(id);
}
public String getCategory() {
return category.get();
}
public StringProperty CategoryProperty() {
return category;
}
public void setCategory(String id) {
this.category.set(id);
}
}
this is the list i am trying to parse to the listview [enter link description here]1
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 am trying to fetch the data from firebase databse. i am using FirebaseDatabase. while fetching the data i am getting above exception. there is no long variable in firebase and local. i am getting proper data.
DatabaseReference firebase = Firebase.getInstance().getReference().child(FirebaseConfig.PRODUCT_MASTER);
Query query = firebase.orderByChild(getString(R.string.COLUMN_RETAILER_ID)).equalTo(retailerId);
query.addChildEventListener(new ChildEventListener() {
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Product_Master productMaster = dataSnapshot.getValue(Product_Master.class);
pdtMasterList.add(productMaster);
}
#Override
public void onChildChanged(DataSnapshot dataSnapshot,
String s) {
}
#Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
#Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
public class Product_Master {
#SerializedName("brand")
private String brand;
#SerializedName("category")
private String category;
#SerializedName("display_name")
private String display_name;
#SerializedName("dealer_price")
private String dealer_price;
#SerializedName("distributor_id")
private String distributor_id;
#SerializedName("EAN")
private String EAN;
#SerializedName("image")
private String image;
#SerializedName("image_folder")
private String image_folder;
#SerializedName("item_description1")
private String item_description1;
#SerializedName("item_description2")
private String item_description2;
#SerializedName("item_id")
private String item_id;
#SerializedName("loose_category")
private String loose_category;
#SerializedName("description")
private String description;
#SerializedName("major_category")
private String major_category;
#SerializedName("moq")
private String moq;
#SerializedName("sub_category")
private String sub_category;
#SerializedName("varaiety")
private String varaiety;
#SerializedName("vat_percent")
private String vat_percent;
#SerializedName("type_product")
private String type_product;
#SerializedName("weight")
private String weight;
#SerializedName("offer_price")
private String offer_price;
#SerializedName("offer_indicator")
private String offer_indicator;
#SerializedName("mov")
private String mov;
#SerializedName("retailer_id")
private String retailer_id;
#SerializedName("retailer_price")
private String retailer_price;
#SerializedName("market_price")
private String market_price;
#SerializedName("price")
private ArrayList<Price> price;
public String getMov() {
return mov;
}
public void setMov(String mov) {
this.mov = mov;
}
public String getRetailer_price() {
return retailer_price;
}
public void setRetailer_price(String retailer_price) {
this.retailer_price = retailer_price;
}
public String getOffer_price() {
return offer_price;
}
public void setOffer_price(String offer_price) {
this.offer_price = offer_price;
}
public String getOffer_indicator() {
return offer_indicator;
}
public void setOffer_indicator(String offer_indicator) {
this.offer_indicator = offer_indicator;
}
public Product_Master() {
}
public String getDealer_price() {
return dealer_price;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getImage_folder() {
return image_folder;
}
public void setImage_folder(String image_folder) {
this.image_folder = image_folder;
}
public void setDealer_price(String dealer_price) {
this.dealer_price = dealer_price;
}
public String getDisplay_name() {
return display_name;
}
public void setDisplay_name(String display_name) {
this.display_name = display_name;
}
public String getDistributor_id() {
return distributor_id;
}
public void setDistributor_id(String distributor_id) {
this.distributor_id = distributor_id;
}
public String getMoq() {
return moq;
}
public void setMoq(String moq) {
this.moq = moq;
}
public String getRetailer_id() {
return retailer_id;
}
public String getMarket_price() {
return market_price;
}
public void setMarket_price(String market_price) {
this.market_price = market_price;
}
public void setRetailer_id(String retailer_id) {
this.retailer_id = retailer_id;
}
public String getItem_id() {
return item_id;
}
public void setItem_id(String item_id) {
this.item_id = item_id;
}
public String getItem_description1() {
return item_description1;
}
public void setItem_description1(String item_description1) {
this.item_description1 = item_description1;
}
public String getItem_description2() {
return item_description2;
}
public void setItem_description2(String item_description2) {
this.item_description2 = item_description2;
}
public String getMajor_category() {
return major_category;
}
public void setMajor_category(String major_category) {
this.major_category = major_category;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getSub_category() {
return sub_category;
}
public void setSub_category(String sub_category) {
this.sub_category = sub_category;
}
public String getVaraiety() {
return varaiety;
}
public void setVaraiety(String varaiety) {
this.varaiety = varaiety;
}
public String getLoose_category() {
return loose_category;
}
public void setLoose_category(String loose_category) {
this.loose_category = loose_category;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getEAN() {
return EAN;
}
public void setEAN(String EAN) {
this.EAN = EAN;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getWeight() {
return weight;
}
public void setWeight(String weight) {
this.weight = weight;
}
public String getVat_percent() {
return vat_percent;
}
public void setVat_percent(String vat_percent) {
this.vat_percent = vat_percent;
}
public String getType_product() {
return type_product;
}
public void setType_product(String type_product) {
this.type_product = type_product;
}
public ArrayList<Price> getPrice() {
return price;
}
public void setPrice(ArrayList<Price> price) {
this.price = price;
}
public static class Price
{
private String weight;
private String offer_price;
private String dealer_price;
public Price(String weight, String offer_price, String dealer_price) {
this.weight = weight;
this.offer_price = offer_price;
this.dealer_price = dealer_price;
}
public String getWeight() {
return weight;
}
public void setWeight(String weight) {
this.weight = weight;
}
public String getOffer_price() {
return offer_price;
}
public void setOffer_price(String offer_price) {
this.offer_price = offer_price;
}
public String getDealer_price() {
return dealer_price;
}
public void setDealer_price(String dealer_price) {
this.dealer_price = dealer_price;
}
}
}
{
"brand" : "GTS Bullet",
"category" : "RICE",
"dealer_price" : "1000",
"description" : "Sona Masuri - A1 Quality - 25Kg",
"display_name" : "SuperZop Traders",
"distributor_id" : "1001",
"ean" : "",
"image" : "sona_masuri_rice_large.jpg",
"image_folder" : "superzop_ordering_product_images",
"item_description1" : "Sona Masuri",
"item_description2" : "A1 Quality",
"item_id" : "100001",
"loose_category" : "RICE",
"major_category" : "GROCERY",
"market_price" : "",
"moq" : "50Kg",
"mov" : "5000",
"offer_indicator" : "",
"offer_price" : "800",
"retailer_id" : 10001,
"sub_category" : "RICE",
"type_product" : "MRP",
"varaiety" : "",
"vat_percent" : "12.50%",
"weight" : "25Kg"
}
i am new for Spring MVC. In my small crm project, i want to display a objectList with nested object. But it show only a object inside objectname like de.fischerlandmaschinen.crm.model.Employee#6018ebcc statt the converted name string.
the below are the codes:
Domain:
#Entity
#Table(name = "CUSTOMER")
public class Customer implements Serializable {
private static final long serialVersionUID = 5015685214532097319L;
private Long id;
private String foreignId;
private String title;
private String firstName;
private String middleName;
#NotEmpty
private String lastName;
#Enumerated(EnumType.STRING)
private Gender gender;
#Past
#Temporal(TemporalType.DATE)
private Date dateOfBirth;
#Valid
private Address address = new Address();
#Valid
private Contact contact = new Contact();
private Company company = null; // new Company();
private String notice;
#Past
#Temporal(TemporalType.DATE)
private Date createdDate;
#Past
#Version
#Temporal(TemporalType.DATE)
private Date lastUpdatedDate;
private String status;
private Employee primaryConsultant = null; //new Employee();
private Employee secondaryConsultant = null; //new Employee();
public Customer(){
createdDate = new Date();
lastUpdatedDate = new Date();
}
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "customer_id")
public Long getId() {
return id;
}
public void setId(Long customerId) {
this.id = customerId;
}
#Column(name = "foreign_id")
public String getForeignId() {
return foreignId;
}
public void setForeignId(String foreignId) {
this.foreignId = foreignId;
}
#OneToOne(cascade = CascadeType.ALL)
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
#OneToOne(cascade = CascadeType.ALL)
public Contact getContact() {
return contact;
}
public void setContact(Contact contact) {
this.contact = contact;
}
#Column(name = "created_date")
public Date getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getMiddleName() {
return middleName;
}
public void setMiddleName(String middleName) {
this.middleName = middleName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Gender getGender() {
return gender;
}
public void setGender(Gender gender) {
this.gender = gender;
}
#Column(name = "date_of_birth")
public Date getDateOfBirth() {
return dateOfBirth;
}
public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
#ManyToOne(fetch=FetchType.LAZY, cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH })
#JoinColumn(name="company", nullable=true)
public Company getCompany() {
return company;
}
public void setCompany(Company company) {
this.company = company;
}
public String getNotice() {
return notice;
}
public void setNotice(String notice) {
this.notice = notice;
}
#Column(name = "last_updated_date")
public Date getLastUpdatedDate() {
return lastUpdatedDate;
}
public void setLastUpdatedDate(Date lastUpdatedDate) {
this.lastUpdatedDate = lastUpdatedDate;
}
// #ManyToOne(fetch=FetchType.LAZY, cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH })
#ManyToOne(fetch=FetchType.EAGER)
#JoinColumn(name="primary_consultant", nullable=true)
public Employee getPrimaryConsultant() {
return primaryConsultant;
}
public void setPrimaryConsultant(Employee primaryConsultant) {
this.primaryConsultant = primaryConsultant;
}
// #ManyToOne(fetch=FetchType.LAZY, cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH })
#ManyToOne(fetch=FetchType.EAGER)
#JoinColumn(name="secondary_consultant", nullable=true)
public Employee getSecondaryConsultant() {
return secondaryConsultant;
}
public void setSecondaryConsultant(Employee secondaryConsultant) {
this.secondaryConsultant = secondaryConsultant;
}
}
and the Employee Domain:
#Entity
#Table(name = "EMPLOYEE")
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private String alias;
private String title;
private String firstName;
private String middleName;
private String lastName;
// getter and setter
}
In my Controller:
#RequestMapping(value = "customer/list")
public ModelAndView list() {
ModelAndView mav = new ModelAndView("customer/list");
List<Customer> customers = customerService.getAllCustomers();
mav.addObject("customerList", customers);
return mav;
}
#InitBinder
protected void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
dateFormat.setLenient(false);
binder.setAutoGrowNestedPaths(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(
dateFormat, true));
binder.registerCustomEditor(Gender.class, new GenderEditor());
binder.registerCustomEditor(Employee.class,
new CustomEmployeePropertyEditor(employeeService));
}
And i have a CustomEmployeePropertyEditor extends PropertyEditorSupport for initBinder:
#Override
public void setAsText(String text) {
logger.info("convert string to employee object");
if (text == null || text.length() == 0) {
setValue(null);
return;
}
Long id = (Long) typeConverter.convertIfNecessary(text, Long.class);
if (id == null) {
setValue(null);
return;
}
setValue(employeeService.getEmployee(id));
}
#Override
public String getAsText() {
logger.info("convert employee object to string");
Object obj = getValue();
if (obj == null) {
return null;
}
return (String) typeConverter.convertIfNecessary(
((Employee) obj).getLastName(), String.class);
}
#Override
public void setAsText(String text) {
logger.info("convert string to employee object");
if (text == null || text.length() == 0) {
setValue(null);
return;
}
Long id = (Long) typeConverter.convertIfNecessary(text, Long.class);
if (id == null) {
setValue(null);
return;
}
setValue(employeeService.getEmployee(id));
}
#Override
public String getAsText() {
logger.info("convert employee object to string");
Object obj = getValue();
if (obj == null) {
return null;
}
return (String) typeConverter.convertIfNecessary(
((Employee) obj).getLastName(), String.class);
}
And die JSP Code:
<c:forEach items="${customerList}" var="customer">
<tr>
<td>${customer.id}</td>
...
<td>${customer.primaryConsultant}</td>
<td>${customer.secondaryConsultant}</td>
...
</tr>
</c:forEach>
But i get the unwanted result in Browser:
de.fischerlandmaschinen.crm.model.Employee#6018ebcc
in the field primaryConsultant and secondaryConsultant fields
What is the wrong. And i look for the document of registerCustomEditor. it saids, that it can for the nested path property too. What means the path property? The path in .jsp page or the property in domain object?
thanks
Ludwig
Override toString() method in Employee class and write what field values you want to display in the browser. That is the easy way and the only way I can think of right now. :)