Skip to content

Commit

Permalink
#218 fixed wrong CSS classes
Browse files Browse the repository at this point in the history
#219 add more attributes to b:switch
  • Loading branch information
stephanrauh committed Dec 28, 2015
1 parent 0b3dca8 commit e37f371
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 12 deletions.
6 changes: 3 additions & 3 deletions gradleResources/css/bsf.css
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@
/* required fields and displaying errors */
label.bf-required:after { content:" *"; }
label.bf-no-message { }
label.bf-info { }
label.bf-warn { font-color: orange; }
label.bf-info { }
label.bf-warning { color: orange; }
label.bf-error { color: red; }
label.bf-fatal { font-color: red; }
label.bf-fatal { color: red; }

.bf-message { padding-top: 2px !important; padding-bottom:2px !important;margin-top:7px; margin-bottom:0px !important;}
.bf-message-summary { padding-left:10px; font-weight:bold;}
Expand Down
2 changes: 1 addition & 1 deletion mavenResources/META-INF/resources/bsf/css/default/bsf.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ protected void addLabel(ResponseWriter rw, String clientId, SelectBooleanCheckbo
String label = selectBooleanCheckbox.getLabel();
if (label != null) {
rw.startElement("label", selectBooleanCheckbox);
writeAttribute(rw, "class", getErrorAndRequiredClass(selectBooleanCheckbox, clientId));
if (null != selectBooleanCheckbox.getDir()) {
rw.writeAttribute("dir", selectBooleanCheckbox.getDir(), "dir");
}
Expand Down Expand Up @@ -327,6 +328,7 @@ protected void renderInputTag(ResponseWriter rw, FacesContext context, SelectBoo

rw.writeAttribute("class", "checkbox", "class");
rw.startElement("label", selectBooleanCheckbox);
writeAttribute(rw, "class", getErrorAndRequiredClass(selectBooleanCheckbox, clientId));

rw.startElement("input", selectBooleanCheckbox);
}
Expand Down Expand Up @@ -373,11 +375,21 @@ protected void renderInputTagAttributes(ResponseWriter rw, String clientId,
if (selectBooleanCheckbox.isReadonly()) {
rw.writeAttribute("readonly", "readonly", null);
}
addAttributesForSwitch(rw, selectBooleanCheckbox);

// Encode attributes (HTML 4 pass-through + DHTML)
R.encodeHTML4DHTMLAttrs(rw, selectBooleanCheckbox.getAttributes(), A.CHECKBOX_ATTRS);
}

/**
* The b:switch and the b:selectBooleanCheckbox share most of their code. This method allows to add extra attributes for the switch.
* @param rw
* @param selectBooleanCheckbox
* @throws IOException
*/
protected void addAttributesForSwitch(ResponseWriter rw, SelectBooleanCheckbox selectBooleanCheckbox) throws IOException {
}

/**
* Closes the input tag. This method is protected in order to allow
* third-party frameworks to derive from it.
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/net/bootsfaces/component/switchComponent/Switch.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,58 @@ public Switch() {
public String getFamily() {
return COMPONENT_FAMILY;
}
protected enum PropertyKeys {
onText,
offText
;

String toString;

PropertyKeys(String toString) {
this.toString = toString;
}

PropertyKeys() {}

public String toString() {
return ((this.toString != null) ? this.toString : super.toString());
}
}


/**
* Optional label of the active switch. The default value is 'on'. <P>
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
*/
public String getOnText() {
String value = (String)getStateHelper().eval(PropertyKeys.onText);
return value;
}

/**
* Optional label of the active switch. The default value is 'on'. <P>
* Usually this method is called internally by the JSF engine.
*/
public void setOnText(String _onText) {
getStateHelper().put(PropertyKeys.onText, _onText);
}


/**
* Optional label of the inactive switch. The default value is 'off'. <P>
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
*/
public String getOffText() {
String value = (String)getStateHelper().eval(PropertyKeys.offText);
return value;
}

/**
* Optional label of the inactive switch. The default value is 'off'. <P>
* Usually this method is called internally by the JSF engine.
*/
public void setOffText(String _offText) {
getStateHelper().put(PropertyKeys.offText, _offText);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
import javax.faces.context.ResponseWriter;
import javax.faces.render.FacesRenderer;

import net.bootsfaces.component.ajax.AJAXRenderer;
import net.bootsfaces.component.selectBooleanCheckbox.SelectBooleanCheckbox;
import net.bootsfaces.component.selectBooleanCheckbox.SelectBooleanCheckboxRenderer;
import net.bootsfaces.render.Tooltip;


/** This class generates the HTML code of &lt;b:switchWidget /&gt;. */
Expand All @@ -45,4 +44,17 @@ public void encodeBegin(FacesContext context, UIComponent component) throws IOEx
rw.append("$('#input_" + clientId + "').bootstrapSwitch();");
rw.append("</script>");
}

/**
* The b:switch and the b:selectBooleanCheckbox share most of their code. This method allows to add extra attributes for the switch.
* @param rw
* @param selectBooleanCheckbox
* @throws IOException
*/
protected void addAttributesForSwitch(ResponseWriter rw, SelectBooleanCheckbox selectBooleanCheckbox) throws IOException {
Switch switchComponent = (Switch)selectBooleanCheckbox;
writeAttribute(rw, "data-off-text", switchComponent.getOffText());
writeAttribute(rw, "data-on-text", switchComponent.getOnText());
}

}
14 changes: 8 additions & 6 deletions xtext/BootsFaces.jsfdsl
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,8 @@ widget switch
onmouseover inherited "Client side callback to execute when a pointer input element is moved onto input element."
onmouseup inherited "Client side callback to execute when a pointer input element is released over input element."
onselect inherited "Client side callback to execute when text within input element is selected by user."
onText "Optional label of the active switch. The default value is 'on'."
offText "Optional label of the inactive switch. The default value is 'off'."
readonly Boolean inherited "Flag indicating that this input element will prevent changes by the user."
renderLabel Boolean default "true" inherited "Allows you to suppress automatic rendering of labels. Used by AngularFaces, too."
rendered Boolean inherited "Boolean value to specify the rendering of the component, when set to false component will not be rendered."
Expand All @@ -1200,12 +1202,12 @@ widget switch
styleClass inherited "Style class of the input element."
tabindex inherited "Advisory tooltip information."
title inherited "Advisory tooltip information."
tooltip inherited "The text of the tooltip."
tooltipContainer default "body" "Where is the tooltip div generated? That's primarily a technical value that can be used to fix rendering error in special cases. Also see data-container in the documentation of Bootstrap. The default value is body."
tooltipDelay Integer inherited "The tooltip is shown and hidden with a delay. This value is the delay in milliseconds. Defaults to 0 (no delay)."
tooltipDelayHide Integer inherited "The tooltip is hidden with a delay. This value is the delay in milliseconds. Defaults to 0 (no delay)."
tooltipDelayShow Integer inherited "The tooltip is shown with a delay. This value is the delay in milliseconds. Defaults to 0 (no delay)."
tooltipPosition inherited "Where is the tooltip to be displayed? Possible values: \"top\", \"bottom\", \"right\", \"left\", \"auto\", \"auto top\", \"auto bottom\", \"auto right\" and \"auto left\". Default to \"bottom\"."
tooltip inherited "The text of the tooltip."
tooltipContainer default "body" inherited "Where is the tooltip div generated? That's primarily a technical value that can be used to fix rendering error in special cases. Also see data-container in the documentation of Bootstrap. The default value is body."
tooltipDelay Integer inherited "The tooltip is shown and hidden with a delay. This value is the delay in milliseconds. Defaults to 0 (no delay)."
tooltipDelayHide Integer inherited "The tooltip is hidden with a delay. This value is the delay in milliseconds. Defaults to 0 (no delay)."
tooltipDelayShow Integer inherited "The tooltip is shown with a delay. This value is the delay in milliseconds. Defaults to 0 (no delay)."
tooltipPosition inherited "Where is the tooltip to be displayed? Possible values: \"top\", \"bottom\", \"right\", \"left\", \"auto\", \"auto top\", \"auto bottom\", \"auto right\" and \"auto left\". Default to \"bottom\"."
value inherited "EL expression referring to the back-end bean attribute providing the value of the field."
valueChangeListener javax.faces.event.ValueChangeListener inherited "A method binding expression referring to a method for handling a valuchangeevent."
}
Expand Down

0 comments on commit e37f371

Please sign in to comment.