I am in the process of modifying a JavaFX program that allows me to use Splash app and integrate unit of measure. It is a product management software with a list view that showcases what you created, deleted, and modified. Somehow, despite having outfitted every code without error, creating a product for the list just ends up as null and the Combobox used for the units has nonexistent values. Anyone interested in helping me crack this code?
#Product Management Problem
62 messages ยท Page 1 of 1 (latest)
โ This post has been reserved for your question.
Hey @magic zenith! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Hi, can you provide some code?
Is it alright if i send the zip?
A bit of a warning, this program here needs a filepath to Java and Maven folders from your File Explorer
not only that, an SQL Configurator needs to be set up in order to use your own password in its yml file
Unless you don't wanna run it, I could just send the file immediately?
Sorry for the late response. I have work... Just send here a code of CreateProductController.
Hold on
package com.gabriel.prodmsv;
import com.gabriel.prodmsv.ServiceImpl.ProductService;
import com.gabriel.prodmsv.model.Product;
import com.gabriel.prodmsv.model.Uom;
import com.gabriel.prodmsv.ServiceImpl.UomService;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import javafx.stage.Window;
import lombok.Setter;
import java.net.URL;
import java.util.ResourceBundle;
@Setter ```java
public class CreateProductController implements Initializable {
@Setter
ProdManController prodManController;
@FXML
public TextField tfName;
@FXML
public TextField tfDesc;
@FXML
private ComboBox<Uom> cbUom;
public Button btnSubmit;
public Button btnNext;
@Setter
Stage stage;
@Setter
Scene parentScene;
@Setter
ProductService productService;
@Setter
UomService uomService;
@Override
public void initialize(URL url, ResourceBundle resourceBundle){
System.out.println("CreateProductController: initialize");
try{
Uom[] uoms = UomService.getService().getUoms();
cbUom.getItems().clear();;
cbUom.getItems().addAll(uoms);
tfName.setText("");
tfDesc.setText("");
} catch(Exception e){
System.out.println(e.getMessage());
}
}
public void clearControlTexts(){
tfName.setText("");
tfDesc.setText("");
cbUom.getSelectionModel().clearSelection();
} ```
This message has been formatted automatically. You can disable this using /preferences.
public void onNext(ActionEvent actionEvent) {
System.out.println("CreateProductController:onBack ");
Node node = ((Node) (actionEvent.getSource()));
Window window = node.getScene().getWindow();
window.hide();
stage.setScene(parentScene);
stage.show();
}
public void onSubmit(ActionEvent actionEvent) throws Exception{
Product product = new Product();
product.setName(tfName.getText());
product.setDescription(tfDesc.getText());
Uom uom = cbUom.getSelectionModel().getSelectedItem();
product.setUomId(uom.getId());
product.setUomName(uom.getName());
try{
// Ensure productService is not null
if(productService == null){
productService = ProductService.getService();
}
prodManController.refresh();
onBack(actionEvent);
} catch(Exception ex){
System.out.println("CreateProductController:onSubmit Error: " + ex.getMessage());
}
}
public void onBack(ActionEvent actionEvent) {
System.out.println("CreateProductController:onBack ");
Node node = ((Node) (actionEvent.getSource()));
Window window = node.getScene().getWindow();
window.hide();
stage.setScene(parentScene);
stage.show();
}
} ```
This message has been formatted automatically. You can disable this using /preferences.
So far, most of the codes have a usage
I checked back on the directory leading to the codes for the Unit of measure
So, based on the stacktrace and provided code it seems that the issue is that you have not selected any item from your combobox.
Pretty much
but the items from the combobox should appear inside with the use of this
package com.gabriel.prodmsapp.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import javax.persistence.*;
import java.util.Date;
@Data
@Entity
@Table(name = "uom_data") ```java
public class UomData {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
int id;
String name;
@UpdateTimestamp
@Temporal(TemporalType.TIMESTAMP)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
private Date lastUpdated;
@CreationTimestamp
@Temporal(TemporalType.TIMESTAMP)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
private Date created;
} ```
This message has been formatted automatically. You can disable this using /preferences.
But this are two different issues. First issue is how to populate combobox with items and second how to retrieve them.
When you open the cmb can you see some items or not?
Fair point
Not exactly..
well, than first you have to check whether you are loading your items correctly
check if there are some items returned from call "UomService.getService().getUoms()"
Nadda ๐
well, than you have to figure out why
Well...as far as I'm looking at the codes right now
It only notified now that some of the prompts have no usages.
show me how you retrieve Uoms...
can't i just send the file?
it'd be convenient if we both see through it
with your permission, of course
just post it here. It should be few pieces of lines of code
public Uom create(Uom uom) {
String url = endpointUrl;
HttpHeaders headers = new HttpHeaders();
HttpEntity<Uom> request = new HttpEntity<>(uom, headers);
final ResponseEntity<Uom> response =
getRestTemplate().exchange(url, HttpMethod.PUT, request, Uom.class);
return response.getBody();
}
public Uom update(Uom uom) {
logger.info("update: " + uom.toString());
String url = endpointUrl;
HttpHeaders headers = new HttpHeaders();
HttpEntity<Uom> request = new HttpEntity<>(uom, headers);
final ResponseEntity<Uom> response =
getRestTemplate().exchange(url, HttpMethod.POST, request, Uom.class);
return response.getBody();
}
public void delete(Integer id) {
logger.info("delete: " + Integer.toString(id));
String url = endpointUrl + "/" + Integer.toString(id);
HttpHeaders headers = new HttpHeaders();
HttpEntity<Uom> request = new HttpEntity<>(null, headers);
final ResponseEntity<Uom> response =
getRestTemplate().exchange(url, HttpMethod.DELETE, request, Uom.class);
} ```
This message has been formatted automatically. You can disable this using /preferences.
okay, this is create, update and delete. What about get?
public static UomService getService(){
if(service == null){
service=new UomService();
}
return service;
}
public RestTemplate getRestTemplate() {
if (restTemplate == null) {
restTemplate = new RestTemplate();
List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));
messageConverters.add(converter);
restTemplate.setMessageConverters(messageConverters);
}
return restTemplate;
}
public Uom getUom(Integer id) {
String url = endpointUrl + "/" + Integer.toString(id);
logger.info("getUom: " + url);
HttpHeaders headers = new HttpHeaders();
HttpEntity request = new HttpEntity<>(null, headers);
final ResponseEntity<Uom> response =
getRestTemplate().exchange(url, HttpMethod.GET, request, Uom.class);
return response.getBody();
}
public Uom[] getUoms() {
String url = endpointUrl;
logger.info("getUoms: " + url);
HttpHeaders headers = new HttpHeaders();
HttpEntity request = new HttpEntity<>(null, headers);
final ResponseEntity<Uom[]> response =
getRestTemplate().exchange(url, HttpMethod.GET, request, Uom[].class);
Uom[] uoms = response.getBody();
return uoms;
} ```
This message has been formatted automatically. You can disable this using /preferences.
that's fine ๐ So are you sure your request is correct?
The getters have some usages for the most part
Connected on CreateProduct and UpdateProduct Controllers....
This is a code I have been asked for help to modify but so far this is beyond me when it's Splash view...
From my POV it seems that in method "getUoms()" the "response.getBody()" return empty array. You have to find out why.
I see...
I should probably continue this tomorrow...
May I be able to chat with you again when I need to?
That is if you're still up for it.
yeah sure. Just ping me in this channel ๐
๐ค Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use/help ping.
Warning: abusing this will result in moderative actions taken against you.
@severe badger Hey, I'm back
cool ๐
Sorry for the late reply but uh...
Got no luck in figuring out what to do
Although I'm trying to do something that may activate the ComboBox
@severe badger You still there or is this a bad time?
I'm still working on the code
๐ค Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use/help ping.
Warning: abusing this will result in moderative actions taken against you.
@severe badger Hey buddy, I'm actually back
Hi, can you ping me in two hours? Then I should have some time for you. And sorry for yesterday. I had some urgent stuff at work...
But until that you have to find out how to make a proper http request so it will return you some data. Without that we cannot move on...
No worries
Here's the thing, I think the whole thing's null because I cannot initialize the U.o.m on the comboBox. The text fields work, the other fields open as intended but it cannot create without the U.O.M.
I think this is a good time to give you the zip file so you can have a visualization of the whole thing
With your permission, of course
I don't wanna overload your routine atm
Give me the prove that the HTTP request you are makng to obtain UOMs is returning some data. Only than we will have something to talk about.
Look, it's been an hour
I'm still trying to obtain them
You're not gonna help me?
well, I saw your code and it looks good. So solve the issue with HTTP and you are good to go