Skip to content

Commit

Permalink
Introducing NESTED_GRID_CLASS in DynaForm
Browse files Browse the repository at this point in the history
* It used to make HTML invalid as two same client ids were generated
* NESTED_GRID_CLASS makes it possible to distinguish which one of the table is nested or not
  • Loading branch information
Rapster committed Nov 26, 2017
1 parent 199181a commit 9ca684f
Showing 1 changed file with 19 additions and 13 deletions.
Expand Up @@ -32,9 +32,9 @@
import org.primefaces.extensions.model.dynaform.DynaFormModel;
import org.primefaces.extensions.model.dynaform.DynaFormModelElement;
import org.primefaces.extensions.model.dynaform.DynaFormRow;
import org.primefaces.extensions.util.Constants;
import org.primefaces.renderkit.CoreRenderer;
import org.primefaces.util.CompositeUtils;
import org.primefaces.util.Constants;

/**
* Renderer for {@link DynaForm} component.
Expand All @@ -54,6 +54,7 @@ public class DynaFormRenderer extends CoreRenderer {
private static final String FACET_BUTTON_BAR = "buttonBar";

private static final String GRID_CLASS = "pe-dynaform-grid";
private static final String NESTED_GRID_CLASS = "pe-dynaform-nested-grid";
private static final String CELL_CLASS = "pe-dynaform-cell";
private static final String CELL_FIRST_CLASS = "pe-dynaform-cell-first";
private static final String CELL_LAST_CLASS = "pe-dynaform-cell-last";
Expand All @@ -78,18 +79,23 @@ public void encodeEnd(final FacesContext fc, final UIComponent component) throws

// get model
DynaFormModel dynaFormModel = (DynaFormModel) dynaForm.getValue();
encodeMarkup(fc, dynaForm, dynaFormModel, true);
encodeMarkup(fc, dynaForm, dynaFormModel, false);
encodeScript(fc, dynaForm, dynaFormModel);
}

protected void encodeMarkup(FacesContext fc, DynaForm dynaForm, DynaFormModel dynaFormModel, boolean encodeFacet) throws IOException {
protected void encodeMarkup(FacesContext fc, DynaForm dynaForm, DynaFormModel dynaFormModel, boolean nestedGrid) throws IOException {
ResponseWriter writer = fc.getResponseWriter();
String clientId = dynaForm.getClientId(fc);

String styleClass = (dynaForm.getStyleClass() == null ? GRID_CLASS : GRID_CLASS + " " + dynaForm.getStyleClass());

writer.startElement("table", dynaForm);
writer.writeAttribute("id", clientId, "id");

if (!nestedGrid) {
String clientId = dynaForm.getClientId(fc);
writer.writeAttribute("id", clientId, "id");
}

String styleClass = nestedGrid ? NESTED_GRID_CLASS : GRID_CLASS;
styleClass += dynaForm.getStyleClass() == null ? Constants.EMPTY_STRING : " " + dynaForm.getStyleClass();

writer.writeAttribute("cellspacing", "0", "cellspacing");
writer.writeAttribute("class", styleClass, "styleClass");
if (dynaForm.getStyle() != null) {
Expand All @@ -104,31 +110,31 @@ protected void encodeMarkup(FacesContext fc, DynaForm dynaForm, DynaFormModel dy
int totalColspan = getTotalColspan(dynaFormModel);
String bbPosition = dynaForm.getButtonBarPosition();

if (encodeFacet && "top".equals(bbPosition) || "both".equals(bbPosition)) {
if (!nestedGrid && "top".equals(bbPosition) || "both".equals(bbPosition)) {
encodeFacet(fc, dynaForm, FACET_BUTTON_BAR, totalColspan, FACET_BUTTON_BAR_TOP_CLASS, BUTTON_BAR_ROLE, false, true);
}

if (encodeFacet) {
if (!nestedGrid) {
encodeFacet(fc, dynaForm, FACET_HEADER_REGULAR, totalColspan, FACET_HEADER_CLASS, GRID_CELL_ROLE, false, true);
}

// encode regular grid
encodeBody(fc, dynaForm, dynaFormModel.getRegularRows(), false, true);

if (encodeFacet) {
if (!nestedGrid) {
encodeFacet(fc, dynaForm, FACET_FOOTER_REGULAR, totalColspan, FACET_FOOTER_CLASS, GRID_CELL_ROLE, false, true);
encodeFacet(fc, dynaForm, FACET_HEADER_EXTENDED, totalColspan, FACET_HEADER_CLASS, GRID_CELL_ROLE, true,
dynaForm.isOpenExtended());
}
// encode extended grid
encodeBody(fc, dynaForm, dynaFormModel.getExtendedRows(), true, dynaForm.isOpenExtended());

if (encodeFacet) {
if (!nestedGrid) {
encodeFacet(fc, dynaForm, FACET_FOOTER_EXTENDED, totalColspan, FACET_FOOTER_CLASS, GRID_CELL_ROLE, true,
dynaForm.isOpenExtended());
}

if (encodeFacet && "bottom".equals(bbPosition) || "both".equals(bbPosition)) {
if (!nestedGrid && "bottom".equals(bbPosition) || "both".equals(bbPosition)) {
encodeFacet(fc, dynaForm, FACET_BUTTON_BAR, totalColspan, FACET_BUTTON_BAR_BOTTOM_CLASS, BUTTON_BAR_ROLE, false, true);
}

Expand Down Expand Up @@ -291,7 +297,7 @@ else if (element instanceof DynaFormModelElement) {
writer.writeAttribute("class", styleClass, null);
writer.writeAttribute("role", GRID_CELL_ROLE, null);

encodeMarkup(fc, dynaForm, nestedModel.getModel(), false);
encodeMarkup(fc, dynaForm, nestedModel.getModel(), true);
}

writer.endElement("td");
Expand Down

0 comments on commit 9ca684f

Please sign in to comment.