Skip to content

Instantly share code, notes, and snippets.

@lofidewanto
Last active October 28, 2020 20:45
Show Gist options
  • Save lofidewanto/aa10420110c0e92619542fca64bc4272 to your computer and use it in GitHub Desktop.
Save lofidewanto/aa10420110c0e92619542fca64bc4272 to your computer and use it in GitHub Desktop.
IndexedDB with Patterns - Composite UI
package com.github.lofi.client;
import static org.jboss.elemento.Elements.br;
...
import java.util.logging.Logger;
...
@Singleton
public class ProductComposite {
private static Logger logger = Logger.getLogger(ProductComposite.class.getName());
private ProductService productService;
private Element panelElement;
@Inject
public ProductComposite(ProductService productService) {
this.productService = productService;
}
public void renderView() {
panelElement = DomGlobal.document.getElementById("panel");
HtmlContentBuilder<HTMLLabelElement> label = label().textContent("Try this to add data... ")
.add(button().textContent("Click to add data!").on(click,
event -> onProductCreated())).add(br());
panelElement.appendChild(label.element());
}
void onProductCreated() {
Product createdProduct = productService.createProduct();
Integer calculatedPriceWithAmount = createdProduct.getCalculatedPriceWithAmount();
if (calculatedPriceWithAmount >= 350) {
logger.info("getCalculatedPriceWithAmount >= 350: " + calculatedPriceWithAmount);
InputBuilder<HTMLInputElement> input = renderInputElements();
input.element().value = calculatedPriceWithAmount.toString();
} else {
logger.info("getCalculatedPriceWithAmount: " + calculatedPriceWithAmount);
}
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment