Author: Alex.Kolonitsky
Date: 2009-07-14 07:22:51 -0400 (Tue, 14 Jul 2009)
New Revision: 14918
Modified:
branches/community/3.3.X/ui/simpleTogglePanel/src/main/java/org/richfaces/renderkit/html/SimpleTogglePanelRenderer.java
branches/community/3.3.X/ui/simpleTogglePanel/src/main/templates/simpleTogglePanel.jspx
branches/community/3.3.X/ui/simpleTogglePanel/src/test/java/org/richfaces/component/SimpleTogglePanelComponentTest.java
Log:
SimpleTogglePanel generates empty display/height/width style attribute
https://jira.jboss.org/jira/browse/RF-7518
Modified:
branches/community/3.3.X/ui/simpleTogglePanel/src/main/java/org/richfaces/renderkit/html/SimpleTogglePanelRenderer.java
===================================================================
---
branches/community/3.3.X/ui/simpleTogglePanel/src/main/java/org/richfaces/renderkit/html/SimpleTogglePanelRenderer.java 2009-07-14
10:25:07 UTC (rev 14917)
+++
branches/community/3.3.X/ui/simpleTogglePanel/src/main/java/org/richfaces/renderkit/html/SimpleTogglePanelRenderer.java 2009-07-14
11:22:51 UTC (rev 14918)
@@ -30,6 +30,7 @@
import javax.faces.component.UIComponent;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
import org.ajax4jsf.component.AjaxSupport;
import org.ajax4jsf.context.AjaxContext;
@@ -187,6 +188,76 @@
}
}
+ public void encodeDivStart(ResponseWriter writer,
+ FacesContext context, UISimpleTogglePanel component) throws IOException {
+ String clientId = component.getClientId(context);
+ writer.startElement("div", component);
+ getUtils().writeAttribute(writer, "class", "rich-stglpanel "
+ convertToString(component.getAttributes().get("styleClass")) );
+ getUtils().writeAttribute(writer, "id", clientId );
+
+ String style =
convertToString(component.getAttributes().get("style"));
+ String width =
convertToString(component.getAttributes().get("width"));
+ if (!isEmpty(width)) {
+ width = "width: " + convertToString(width);
+ style = width + (isEmpty(style) ? ";" : "; " + style +
";");
+ }
+ if (!isEmpty(style)) {
+ getUtils().writeAttribute(writer, "style", style);
+ }
+
+ getUtils().encodeAttributesFromArray(context,component,new String[] {
+ "align",
+ "dir",
+ "lang",
+ "onclick",
+ "ondblclick",
+ "onkeydown",
+ "onkeypress",
+ "onkeyup",
+ "onmousedown",
+ "onmousemove",
+ "onmouseout",
+ "onmouseover",
+ "onmouseup",
+ "title",
+ "xml:lang" });
+ }
+
+ public void encodeBodyDivStart(ResponseWriter writer,
+ FacesContext context, UISimpleTogglePanel component) throws IOException {
+ String clientId = component.getClientId(context);
+ writer.startElement("div", component);
+ getUtils().writeAttribute(writer, "class", "rich-stglpanel-body
" + convertToString(component.getAttributes().get("bodyClass")) );
+ getUtils().writeAttribute(writer, "id", convertToString(clientId) +
"_body" );
+
+ String display =
convertToString(component.getAttributes().get("display"));
+ if (!isEmpty(display)) {
+ display = "display: " + convertToString(display) + "; ";
+ }
+
+ String height =
convertToString(component.getAttributes().get("height"));
+ if (!isEmpty(height)) {
+ height = "height: " +
convertToString(component.getAttributes().get("height")) + ";";
+ }
+
+ String style = display + height;
+ if (!isEmpty(style)) {
+ getUtils().writeAttribute(writer, "style", style);
+ }
+ }
+
+ private boolean isEmpty(String str) {
+ return str == null || str.length() == 0;
+ }
+
+ private String convertToString(Object obj ) {
+ return ( obj == null ? "" : obj.toString() );
+ }
+
+ public void encodeDivEnd(ResponseWriter writer) throws IOException {
+ writer.endElement("div");
+ }
+
public String getSwitchOnStatus(FacesContext context, UIComponent component) {
UISimpleTogglePanel simpleTogglePanel = (UISimpleTogglePanel) component;
return simpleTogglePanel.isOpened() ? EMPTY : NONE;
Modified:
branches/community/3.3.X/ui/simpleTogglePanel/src/main/templates/simpleTogglePanel.jspx
===================================================================
---
branches/community/3.3.X/ui/simpleTogglePanel/src/main/templates/simpleTogglePanel.jspx 2009-07-14
10:25:07 UTC (rev 14917)
+++
branches/community/3.3.X/ui/simpleTogglePanel/src/main/templates/simpleTogglePanel.jspx 2009-07-14
11:22:51 UTC (rev 14918)
@@ -20,10 +20,9 @@
scripts/simpleTogglePanel.js
</h:scripts>
- <div id="#{clientId}"
x:passThruWithExclusions="id,value,style,styleClass,class"
- class="rich-stglpanel #{component.attributes['styleClass']}"
- style="width: #{component.attributes['width']};
#{component.attributes['style']};">
-
+ <jsp:scriptlet>
+ encodeDivStart(writer, context, component);
+ </jsp:scriptlet>
<script type="text/javascript">
SimpleTogglePanelManager.add(new SimpleTogglePanel("#{clientId}",
"#{component.attributes['opened']}",{
@@ -38,7 +37,7 @@
<div id="#{clientId}_header"
class="rich-stglpanel-header
#{component.attributes['headerClass']}"
onclick="#{this:getOnClick(context,component)}">
-
+
<div class="rich-stglpanel-marker">
<div id="#{clientId}_switch_on" style="display:
#{this:getSwitchOnStatus(context, component)};"
class="rich-stglpnl-marker">
<jsp:scriptlet><![CDATA[
@@ -92,15 +91,14 @@
</jsp:scriptlet>
<f:call name="utils.encodeEndFormIfNessesary"/>
- <div id="#{clientId}_body"
- class="rich-stglpanel-body
#{component.attributes['bodyClass']}"
- style="display : #{this:getdivdisplay(context, component)};
- height: #{component.attributes['height']};">
-
+ <jsp:scriptlet>
+ encodeBodyDivStart(writer, context, component);
+ </jsp:scriptlet>
<vcp:body>
<f:call name="renderChildren" />
</vcp:body>
- </div>
- </div>
-
+ <jsp:scriptlet>
+ encodeDivEnd(writer);
+ encodeDivEnd(writer);
+ </jsp:scriptlet>
</f:root>
Modified:
branches/community/3.3.X/ui/simpleTogglePanel/src/test/java/org/richfaces/component/SimpleTogglePanelComponentTest.java
===================================================================
---
branches/community/3.3.X/ui/simpleTogglePanel/src/test/java/org/richfaces/component/SimpleTogglePanelComponentTest.java 2009-07-14
10:25:07 UTC (rev 14917)
+++
branches/community/3.3.X/ui/simpleTogglePanel/src/test/java/org/richfaces/component/SimpleTogglePanelComponentTest.java 2009-07-14
11:22:51 UTC (rev 14918)
@@ -93,7 +93,7 @@
stp1.setId("simpleTogglePanel1");
stp1.setOpened(true);
stp1.setSwitchType(UISimpleTogglePanel.SERVER_SWITCH_TYPE);
-
+
openMarker1 = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE);
openMarker1.setId("openMarker");
openMarker1.setValue("open");
@@ -163,10 +163,10 @@
HtmlElement div1 = page.getHtmlElementById(stp1.getClientId(facesContext));
assertNotNull(div1);
assertEquals("div", div1.getNodeName());
+
assertTrue(div1.getAttributeValue("class").contains("rich-stglpanel"));
+ assertEquals("", div1.getAttributeValue("style"));
+
- String classAttr1 = div1.getAttributeValue("class");
- assertTrue(classAttr1.contains("rich-stglpanel"));
-
HtmlDivision div2 =
(HtmlDivision)page.getHtmlElementById(stp1.getClientId(facesContext) +
"_header");
assertNotNull(div2);
assertEquals("div", div2.getNodeName());
@@ -185,7 +185,8 @@
HtmlElement div4 = page.getHtmlElementById(stp1.getClientId(facesContext) +
"_body");
assertNotNull(div4);
assertEquals("div", div4.getNodeName());
-
+ assertEquals("", div4.getAttributeValue("style"));
+
try {
page.getHtmlElementById(openMarker1.getClientId(facesContext));
assertTrue(false);