tipsy / j2html

Java to HTML generator. Enjoy typesafe HTML generation.
https://j2html.com/
Apache License 2.0
758 stars 136 forks source link

Extends ContainerTag #221

Closed danieltoril closed 1 year ago

danieltoril commented 1 year ago

Hi, I'm trying to extend ContainerTag to make a complex object, but the class not Render:

`public CardView(String id, String title, List<Tag<?>> cBody) { super("div"); this.id = id; this.title = title; this.content = cBody; }

public String getId() {
  return id;
}

public void setId(String id) {
  this.id = id;
}

public List<Tag<?>> getContent() {
  return content;
}

public void setContent(List<Tag<?>> content) {
  this.content = content;
}

public String getTitle() {
  return title;
}

public void setTitle(String title) {
  this.title = title;
}

public int getRows() {
  return rows;
}

public CardView withRows(int rows) {
  this.rows = rows;
  return this;
}

public CardView withHeader(boolean header) {
  this.header = header;
  return this;
}

public boolean isCollapse() {
  return collapse;
}

public CardView withCollapse(boolean collapse) {
  this.collapse = collapse;
  return this;
}

public CardView withMaximize(boolean maximize) {
  this.maximize = maximize;
  return this;
}

@Override
public String renderFormatted() {
  return super.renderFormatted();
}

@Override
public <T extends Appendable> T render(HtmlBuilder<T> builder) throws IOException {
  // @formatter:off
  DivTag card = this.withId(id).withClass("card card-primary");
  if(header) {
  card.with(
    div().withClass("card-header").with(
      h3(title).withClass("card-title"),
      div().withClass("card-tools").with(
        TagCreator.iff(maximize, button(i().withClass(ICON_EXPAND)).withClasses("btn", "btn-tool").withType(BUTTON).attr("data-card-widget", "maximize").withTitle(getMsg(MSG.maximizar))),
        TagCreator.iff(collapse, button(i().withClass(ICON_MINUS)).withClasses("btn", "btn-tool").withType(BUTTON).attr("data-card-widget", "collapse").withTitle(getMsg(MSG.minimizar)))
      )));
  }
  card.with(div().withClasses("card-body",rows>0?"overflow-auto":"").with(content).withCondStyle(rows>0, "height:"+(rows*ROW_HEIGHT)+"px"));
  // @formatter:on
  return card.render(builder);
}

}` Thanks in advance

sembler commented 1 year ago

Since you closed the issue, did you still want any feedback?