Skip to content

Commit

Permalink
fix: Rendering <tc:columnNode> (#5825) (#5826)
Browse files Browse the repository at this point in the history
* fix: Rendering <tc:columnNode>
issue: TOBAGO-2376

(cherry picked from commit d5bf865)
  • Loading branch information
lofwyr14 authored Dec 17, 2024
1 parent bc79a05 commit cebfef2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@
import org.apache.myfaces.tobago.layout.PaginatorMode;
import org.apache.myfaces.tobago.layout.ShowPosition;
import org.apache.myfaces.tobago.layout.TextAlign;
import org.apache.myfaces.tobago.model.ExpandedState;
import org.apache.myfaces.tobago.model.Selectable;
import org.apache.myfaces.tobago.model.SheetState;
import org.apache.myfaces.tobago.model.SortedColumn;
import org.apache.myfaces.tobago.model.SortedColumnList;
import org.apache.myfaces.tobago.model.TreePath;
import org.apache.myfaces.tobago.renderkit.RendererBase;
import org.apache.myfaces.tobago.renderkit.css.BootstrapClass;
import org.apache.myfaces.tobago.renderkit.css.CssItem;
Expand Down Expand Up @@ -490,7 +488,6 @@ private void encodeTableBody(final FacesContext facesContext, final AbstractUISh

final boolean showHeader = sheet.isShowHeader();
final Markup sheetMarkup = sheet.getMarkup() != null ? sheet.getMarkup() : Markup.NULL;
final ExpandedState expandedState = sheet.isTreeModel() ? sheet.getExpandedState() : null;

final UIComponent before = sheet.getFacet(Facets.BEFORE);
if (before != null) {
Expand Down Expand Up @@ -589,20 +586,16 @@ private void encodeTableBody(final FacesContext facesContext, final AbstractUISh
LOG.debug("list " + sheet.getValue());
}

if (sheet.isTreeModel()) {
final TreePath path = sheet.getPath();
if (sheet.isFolder() && expandedState.isExpanded(path)) {
expandedValue.add(rowIndex);
}
if (sheet.isTreeModel() && sheet.isFolder() && sheet.getExpandedState().isExpanded(sheet.getPath())) {
expandedValue.add(rowIndex);
}

writer.startElement(HtmlElements.TR);
writer.writeAttribute(CustomAttributes.ROW_INDEX, rowIndex);
final boolean selected = selectedRows.contains(rowIndex);
final String parentId = sheet.getRowParentClientId();
if (parentId != null) {
// TODO: replace with
// todo writer.writeIdAttribute(parentId + SUB_SEPARATOR + AbstractUITree.SUFFIX_PARENT);
// TODO: replace with writer.writeIdAttribute(parentId + SUB_SEPARATOR + AbstractUITree.SUFFIX_PARENT);
// todo like in TreeListboxRenderer
writer.writeAttribute(DataAttributes.TREE_PARENT, parentId, false);
}
Expand Down Expand Up @@ -635,8 +628,7 @@ private void encodeTableBody(final FacesContext facesContext, final AbstractUISh
column instanceof AbstractUIColumn ? ((AbstractUIColumn) column).getVerticalAlign() : null),
column.getCustomClass());

if (column instanceof AbstractUIColumnSelector) {
final AbstractUIColumnSelector selector = (AbstractUIColumnSelector) column;
if (column instanceof AbstractUIColumnSelector selector) {
writer.startElement(HtmlElements.INPUT);
writer.writeNameAttribute(sheetId + "_data_row_selector_" + rowIndex);
Selectable currentSelectable = getSelectionMode(selectable, selector);
Expand All @@ -655,19 +647,17 @@ private void encodeTableBody(final FacesContext facesContext, final AbstractUISh
BootstrapClass.FORM_CHECK_INLINE,
TobagoClass.SELECTED);
writer.endElement(HtmlElements.INPUT);
} else /*if (normalColumn instanceof AbstractUIColumnNode)*/ {
if (column.getChildCount() > 0) {
for (int k = 0; k < column.getChildCount(); k++) {
column.getChildren().get(k).encodeAll(facesContext);
} else if (column instanceof AbstractUIColumnNode) {
column.encodeAll(facesContext);
} else {
final int childCount = column.getChildCount();
if (childCount > 0) {
final List<UIComponent> children = column.getChildren();
for (int k = 0; k < childCount; k++) {
children.get(k).encodeAll(facesContext);
}
}
} /*else {
final List<UIComponent> children = sheet.getRenderedChildrenOf(normalColumn);
for (final UIComponent grandKid : children) {
grandKid.encodeAll(facesContext);
}
}*/

}
writer.endElement(HtmlElements.TD);
} else if (column instanceof AbstractUIColumnPanel) {
panel = (AbstractUIColumnPanel) column;
Expand Down Expand Up @@ -722,7 +712,6 @@ private void encodeTableBody(final FacesContext facesContext, final AbstractUISh
writer.endElement(HtmlElements.TD);
if (!autoLayout) {
writer.startElement(HtmlElements.TD);
// writer.write("&nbsp;");
writer.startElement(HtmlElements.DIV);
writer.endElement(HtmlElements.DIV);
writer.endElement(HtmlElements.TD);
Expand All @@ -733,7 +722,6 @@ private void encodeTableBody(final FacesContext facesContext, final AbstractUISh
writer.endElement(HtmlElements.TBODY);
writer.endElement(HtmlElements.TABLE);
writer.endElement(HtmlElements.DIV);
// END RENDER BODY CONTENT
}

private static Selectable getSelectionMode(Selectable selectable, AbstractUIColumnSelector selector) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
...</demo-highlight>
<tc:sheet id="sheet" value="#{sheetTreeController.solarTree}" var="solarObject" showRoot="true" showRootJunction="true">
<tc:columnNode id="nameCol" label="Name">
<tc:treeIndent/>
<tc:treeIndent id="indent"/>
<tc:out id="nameOut" value="#{solarObject.userObject.name}" labelLayout="skip"/>
</tc:columnNode>
<tc:column label="Central Body">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,31 @@
import {elementByIdFn, querySelectorAllFn, querySelectorFn} from "/script/tobago-test.js";
import {JasmineTestTool} from "/tobago/test/tobago-test-tool.js";

it("There must be no horizontal scrollbar", function (done) {
it("Open the 'World' node to see 'Carib' and 'Africa'", function (done) {
const reset = elementByIdFn("page:mainForm:reset")
const treeNodes = querySelectorAllFn("#page\\:mainForm\\:sheet tobago-tree-node");
const toggleWorld = querySelectorFn("#page\\:mainForm\\:sheet\\:6\\:nameCol .tobago-toggle");
const spanWorld = querySelectorFn("#page\\:mainForm\\:sheet\\:6\\:nameCol span.form-control-plaintext");
const spanCarib = querySelectorFn("#page\\:mainForm\\:sheet\\:7\\:nameCol span.form-control-plaintext");
const spanAfrica = querySelectorFn("#page\\:mainForm\\:sheet\\:8\\:nameCol span.form-control-plaintext");
const spanWorld = querySelectorFn("#page\\:mainForm\\:sheet\\:6\\:nameOut span.form-control-plaintext");
const spanCarib = querySelectorFn("#page\\:mainForm\\:sheet\\:7\\:nameOut span.form-control-plaintext");
const spanAfrica = querySelectorFn("#page\\:mainForm\\:sheet\\:8\\:nameOut span.form-control-plaintext");

const test = new JasmineTestTool(done);
if (treeNodes().length !== 12) {
// test.fail("Must be a number of 12 tree nodes!");
console.error("Must be a number of 12 tree nodes!");
}
if (reset() === null) {
// test.fail("reset button not found!");
console.error("reset button not found!");
}
if (toggleWorld() === null) {
// test.fail("toggleWorld not found!");
console.error("toggleWorld not found!");
}
if (spanWorld() === null) {
// test.fail("spanWorld not found!");
console.error("spanWorld not found!");
}
test.setup(() => treeNodes().length === 12
&& spanWorld().textContent === "World"
&& spanCarib().textContent !== "Carib"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<tc:button id="reset" label="Reset" outcome="/content/900-test/3000-sheet/70-tree/Sheet_Tree.xhtml"/>
<tc:sheet id="sheet" value="#{treeController.sample}" var="node" showRoot="true" showRootJunction="true">
<tc:columnNode id="nameCol" label="Name">
<tc:treeIndent/>
<tc:treeIndent id="indent"/>
<tc:out id="nameOut" value="#{node.userObject.name}" labelLayout="skip"/>
</tc:columnNode>
</tc:sheet>
Expand Down

0 comments on commit cebfef2

Please sign in to comment.