Hello,
Could you please suggest how to update the values of the fields in a form with the ones entered from a popup window? Meanwhile, the model of the main form and popup form is the same.
For example, I would like to change the values of the « product-form » update from the « stock-product-tariff-popup-form. »
My solution is not working. The code snippet to look at:
axelor-stock/views/Product.xml:
ProductController.java:
public void handleSubmissionForm(ActionRequest request, ActionResponse response) {
Product product = request.getContext().asType(Product.class);
if (product != null) {
Product updatedProduct = Beans.get(ProductService.class).handleSubmissionForm(product);
response.setValue("_tariffStatus", updatedProduct.getTariffStatus());
response.setValue("_salePrice", updatedProduct.getSalePrice());
response.setValue("_startDateTime", updatedProduct.getStartDateTime());
response.setValue("_endDateTime", updatedProduct.getEndDateTime());
response.setReload(true);
} else {
response.setError("Product not found");
}
}
ProductService.java:
@Transactional
public Product handleSubmissionForm(Product product) {
Product existingProduct = productRepo.find(product.getId());
//Product existingProduct = productRepo.all().filter("self.id = ?1", product.getId()).fetchOne();
if (existingProduct != null) {
existingProduct.setTariffStatus(product.getTariffStatus());
existingProduct.setSalePrice(product.getSalePrice());
existingProduct.setStartDateTime(product.getStartDateTime());
existingProduct.setEndDateTime(product.getEndDateTime());
productRepo.save(existingProduct);
return existingProduct;
} else {
throw new RuntimeException("Product not found");
}
}