I have an problem with Firebase!, I've created register and login page and works fine!. but i have an problem. why my button create a new 'child'?
How can i put button 'onClick' on same UID from identify users by button clicks ? What I want to do, I don't know how firebase works 100% can anyone explain for me? i really need to {get} does click buttons for identify every user on database. My page button
MainActivity
public class MainActivity extends AppCompatActivity {
private Button influenciador;
private Button marca;
private DatabaseReference mDatabase;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
influenciador = (Button) findViewById(R.id.BotaoSouInfluenciador);
marca = (Button) findViewById(R.id.BotaoSouMarca);
mDatabase = FirebaseDatabase.getInstance().getReference().child("Usuários");
influenciador.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mDatabase.child("Usuários").push().setValue("Pizza");
openDIContrato();
}
});
marca.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mDatabase.child("Usuários").setValue("Burger");
openMarcaContrato();
}
});
}
public void openDIContrato() {
Intent intent = new Intent(this, DIContrato.class);
startActivity(intent);
}
public void openMarcaContrato() {
Intent intent = new Intent(this, MarcaContrato.class);
startActivity(intent);
}
}
Users class
public class Usuarios {
private String id;
private String email;
private String aniversario;
private String senha;
private String nome;
private String sexo;
public Usuarios() {
}
public void salvar(){
DatabaseReference referenciaFirebase = ConfiguracaoFirebase.getFirebase();
referenciaFirebase.child("Usuários").child(String.valueOf(getId())).setValue(this);
}
#Exclude
public Map<String, Object> toMap(){
HashMap<String, Object> hashMapUsuario = new HashMap<>();
hashMapUsuario.put("id", getId());
hashMapUsuario.put("email", getEmail());
hashMapUsuario.put("aniversario", getAniversario());
hashMapUsuario.put("nome", getnome());
hashMapUsuario.put("sexo", getSexo());
return hashMapUsuario;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
public String getnome() {
return nome;
}
public void setnome(String nome) {
this.nome = nome;
}
public String getAniversario() {
return aniversario;
}
public void setAniversario(String aniversario) {
this.aniversario = aniversario;
}
public String getSexo() {
return sexo;
}
public void setSexo(String sexo) {
this.sexo = sexo;
}
}
You're not using the correct reference to your database. From the image with title "what I want to do", you can do so with this piece of code:
DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Usuários");
ref.child(iD).child("Button").setValue("Pizza");
//id is the string I can see in the databse image dG9ue...
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 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
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. :)