Skip to content

Commit

Permalink
#587 added the new attribute "content-disabled"
Browse files Browse the repository at this point in the history
#546 allow search filters to be above the table
  • Loading branch information
stephanrauh committed Feb 3, 2017
1 parent e698190 commit f49b9aa
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import net.bootsfaces.component.ajax.IAJAXComponent;
import net.bootsfaces.listeners.AddResourcesListener;
import net.bootsfaces.render.IContentDisabled;
import net.bootsfaces.render.IResponsive;
import net.bootsfaces.render.Tooltip;
import net.bootsfaces.utils.BsfUtils;
Expand All @@ -49,7 +50,7 @@
@ResourceDependency(library = "bsf", name = "css/datatables.min.css", target = "head") })
@FacesComponent("net.bootsfaces.component.dataTable.DataTable")
public class DataTable extends DataTableCore
implements IAJAXComponent, ClientBehaviorHolder, net.bootsfaces.render.IHasTooltip, IResponsive {
implements IAJAXComponent, ClientBehaviorHolder, net.bootsfaces.render.IHasTooltip, IResponsive, IContentDisabled {

public static final String COMPONENT_TYPE = "net.bootsfaces.component.dataTable.DataTable";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ protected enum PropertyKeys {
colMd,
colSm,
colXs,
contentDisabled,
customLangUrl,
customOptions,
disabled,
Expand All @@ -42,6 +43,7 @@ protected enum PropertyKeys {
largeScreen,
mediumScreen,
multiColumnSearch,
multiColumnSearchPosition,
offset,
offsetLg,
offsetMd,
Expand Down Expand Up @@ -198,6 +200,22 @@ public void setColXs(String _colXs) {
getStateHelper().put(PropertyKeys.colXs, _colXs);
}

/**
* Enables or disables every child element of this container. By default, child elements are enabled. <P>
* @return Returns the value of the attribute, or false, if it hasn't been set by the JSF file.
*/
public boolean isContentDisabled() {
return (boolean) (Boolean) getStateHelper().eval(PropertyKeys.contentDisabled, false);
}

/**
* Enables or disables every child element of this container. By default, child elements are enabled. <P>
* Usually this method is called internally by the JSF engine.
*/
public void setContentDisabled(boolean _contentDisabled) {
getStateHelper().put(PropertyKeys.contentDisabled, _contentDisabled);
}

/**
* Defines a custom lang file url for languages BootsFaces doesn't support out-of-the-box. <P>
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
Expand Down Expand Up @@ -390,6 +408,22 @@ public void setMultiColumnSearch(boolean _multiColumnSearch) {
getStateHelper().put(PropertyKeys.multiColumnSearch, _multiColumnSearch);
}

/**
* Should the multi-column-search attributes be at the bottom or the top of the table? Legal values: 'top','botton', and 'both'. Default to 'bottom'. <P>
* @return Returns the value of the attribute, or "bottom", if it hasn't been set by the JSF file.
*/
public String getMultiColumnSearchPosition() {
return (String) getStateHelper().eval(PropertyKeys.multiColumnSearchPosition, "bottom");
}

/**
* Should the multi-column-search attributes be at the bottom or the top of the table? Legal values: 'top','botton', and 'both'. Default to 'bottom'. <P>
* Usually this method is called internally by the JSF engine.
*/
public void setMultiColumnSearchPosition(String _multiColumnSearchPosition) {
getStateHelper().put(PropertyKeys.multiColumnSearchPosition, _multiColumnSearchPosition);
}

/**
* Integer value to specify how many columns to offset. <P>
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,27 @@ public void encodeBegin(FacesContext context, UIComponent component) throws IOEx

ResponseWriter rw = context.getResponseWriter();
String clientId = dataTable.getClientId();
boolean idHasBeenRendered=false;

String responsiveStyle = Responsive.getResponsiveStyleClass(dataTable, false);
if (null != responsiveStyle && responsiveStyle.trim().length() > 0) {
rw.startElement("div", dataTable);
rw.writeAttribute("class", responsiveStyle.trim(), null);
rw.writeAttribute("id", clientId, "id");
idHasBeenRendered=true;
}

if (dataTable.isContentDisabled()) {
if (beginDisabledFieldset(dataTable, rw)) {
rw.writeAttribute("id", clientId, "id");
idHasBeenRendered=true;
}
}

rw.startElement("table", dataTable);
rw.writeAttribute("id", clientId, "id");
if (!idHasBeenRendered) {
rw.writeAttribute("id", clientId, "id");
}

String styleClass = "table ";
if (dataTable.isBorder()) {
Expand Down Expand Up @@ -126,10 +138,10 @@ private void generateFooter(FacesContext context, DataTable dataTable, ResponseW
boolean hasFooter = false;
boolean hasSearchbar = false;
if (dataTable.isMultiColumnSearch()) {
// String position = dataTable.getMultiColumnSearchPosition();
// if ("both".equalsIgnoreCase(position) || "bottom".equalsIgnoreCase(position)) {
String position = dataTable.getMultiColumnSearchPosition();
if ("both".equalsIgnoreCase(position) || "bottom".equalsIgnoreCase(position)) {
hasSearchbar = true;
// }
}
}
for (UIComponent column : dataTable.getChildren()) {
if (!column.isRendered()) {
Expand Down Expand Up @@ -175,7 +187,7 @@ private void generateMultiColumnSearchRow(FacesContext context, DataTable dataTa
if (!column.isRendered()) {
continue;
}
rw.startElement("th", dataTable);
rw.startElement("td", dataTable);
Object footerStyle = column.getAttributes().get("footerStyle");
if (footerStyle != null) {
rw.writeAttribute("style", footerStyle, null);
Expand All @@ -196,7 +208,7 @@ private void generateMultiColumnSearchRow(FacesContext context, DataTable dataTa
rw.writeText(column.getAttributes().get("label"), null);
}
}
rw.endElement("th");
rw.endElement("td");
}
rw.endElement("tr");
}
Expand Down Expand Up @@ -278,6 +290,13 @@ private void resetClientIdCacheRecursively(UIComponent c) {

private void generateHeader(FacesContext context, DataTable dataTable, ResponseWriter rw) throws IOException {
rw.startElement("thead", dataTable);
// Putting input fields into the header doesn't work yet
if (dataTable.isMultiColumnSearch()) {
String position = dataTable.getMultiColumnSearchPosition();
if ("both".equalsIgnoreCase(position) || "top".equalsIgnoreCase(position)) {
generateMultiColumnSearchRow(context, dataTable, rw);
}
}
rw.startElement("tr", dataTable);
int index = 0;
List<UIComponent> columns = dataTable.getChildren();
Expand Down Expand Up @@ -460,15 +479,6 @@ private void generateHeader(FacesContext context, DataTable dataTable, ResponseW
index++;
}
rw.endElement("tr");
if (false) {
// Putting input fields into the header doesn't work yet
// if (dataTable.isMultiColumnSearch()) {
// String position = dataTable.getMultiColumnSearchPosition();
// if ("both".equalsIgnoreCase(position) || "top".equalsIgnoreCase(position)) {
// generateMultiColumnSearchRow(context, dataTable, rw);
// }
// }
}

rw.endElement("thead");
}
Expand Down Expand Up @@ -518,6 +528,7 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
}
String lang = determineLanguage(context, dataTable);
rw.endElement("table");
endDisabledFieldset(dataTable, rw);
String responsiveStyle = Responsive.getResponsiveStyleClass(dataTable, false);
if (null != responsiveStyle && responsiveStyle.trim().length() > 0) {
rw.endElement("div");
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/net/bootsfaces/render/CoreRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,20 @@ public static void endDisabledFieldset(IContentDisabled component, ResponseWrite
}
}

public static void beginDisabledFieldset(IContentDisabled component, ResponseWriter rw) throws IOException {
/**
* Renders the code disabling every input field and every button within a container.
* @param component
* @param rw
* @return true if an element has been rendered
* @throws IOException
*/
public static boolean beginDisabledFieldset(IContentDisabled component, ResponseWriter rw) throws IOException {
if (component.isContentDisabled()) {
rw.startElement("fieldset", (UIComponent)component);
rw.writeAttribute("disabled", "disabled", "null");
return true;
}
return false;
}

}
36 changes: 36 additions & 0 deletions src/main/meta/META-INF/bootsfaces-b.taglib.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5161,6 +5161,18 @@
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[Enables or disables every child element of this container. By default, child elements are enabled.]]></description>
<name>content-disabled</name>
<required>false</required>
<type>java.lang.Boolean</type>
</attribute>
<attribute>
<description><![CDATA[Enables or disables every child element of this container. By default, child elements are enabled.]]></description>
<name>contentDisabled</name>
<required>false</required>
<type>java.lang.Boolean</type>
</attribute>
<attribute>
<description><![CDATA[Defines a custom lang file url for languages BootsFaces doesn't support out-of-the-box.]]></description>
<name>custom-lang-url</name>
Expand Down Expand Up @@ -5275,6 +5287,18 @@
<required>false</required>
<type>java.lang.Boolean</type>
</attribute>
<attribute>
<description><![CDATA[Should the multi-column-search attributes be at the bottom or the top of the table? Legal values: 'top','botton', and 'both'. Default to 'bottom'.]]></description>
<name>multi-column-search-position</name>
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[Should the multi-column-search attributes be at the bottom or the top of the table? Legal values: 'top','botton', and 'both'. Default to 'bottom'.]]></description>
<name>multiColumnSearchPosition</name>
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[Integer value to specify how many columns to offset.]]></description>
<name>offset</name>
Expand Down Expand Up @@ -8225,6 +8249,18 @@
<required>false</required>
<type>javax.faces.component.UIComponent</type>
</attribute>
<attribute>
<description><![CDATA[Enables or disables every child element of this container. By default, child elements are enabled.]]></description>
<name>content-disabled</name>
<required>false</required>
<type>java.lang.Boolean</type>
</attribute>
<attribute>
<description><![CDATA[Enables or disables every child element of this container. By default, child elements are enabled.]]></description>
<name>contentDisabled</name>
<required>false</required>
<type>java.lang.Boolean</type>
</attribute>
<attribute>
<description><![CDATA[Direction indication for text that does not inherit directionality. Legal values: ltr (Default. Left-to-right text direction), rtl (Right-to-left text direction) and auto (let the browser figure out the direction of your alphabet, based on the page content).]]></description>
<name>dir</name>
Expand Down
5 changes: 4 additions & 1 deletion xtext/BootsFaces.jsfdsl
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ widget dataTable
info Boolean default "true" "If set, this will enable the information about record count. Defaults to true."
lang String "Configured lang for the dataTable. If no default language is configured, the language configured in the browser is used."
multi-column-search Boolean "If true, &lt;b:inputText /&gt; fields will be generated at the bottom of each column which allow you to perform per-column filtering."
// multi-column-search-position default "bottom" "Doesn't work yet. Should the multi-column-search attributes be at the bottom or the top of the table? Legal values: 'top','botton', and 'both'. Default to 'bottom'."
multi-column-search-position default "bottom" "Should the multi-column-search attributes be at the bottom or the top of the table? Legal values: 'top','botton', and 'both'. Default to 'bottom'."
onclick "The onclick attribute."
oncomplete "JavaScript to be executed when ajax completes with success."
ondblclick "Client side callback to execute when input element is double clicked."
Expand Down Expand Up @@ -528,6 +528,7 @@ widget dataTable
+style
+responsive
+tooltip
+contentDisabled
}

widget dataTableColumn {
Expand Down Expand Up @@ -728,6 +729,7 @@ widget fetchBeanInfos
}

widget form
extends UIForm
has_children {
binding javax.faces.component.UIComponent inherited "The ValueExpression linking this component to a property in a backing bean"
id inherited "Unique identifier of the component in a namingContainer."
Expand Down Expand Up @@ -756,6 +758,7 @@ widget form
target inherited "Name of a frame where the response retrieved after this form submit is to be displayed."
title inherited "Advisory title information about markup elements generated for this component."
+style
+contentDisabled
}

widget flyOutMenu
Expand Down

0 comments on commit f49b9aa

Please sign in to comment.