Author: sergeyhalipov
Date: 2007-07-06 13:02:52 -0400 (Fri, 06 Jul 2007)
New Revision: 1529
Modified:
branches/3.0.2/richfaces/modal-panel/src/main/config/component/modalPanel.xml
branches/3.0.2/richfaces/modal-panel/src/main/java/org/richfaces/component/UIModalPanel.java
branches/3.0.2/richfaces/modal-panel/src/main/java/org/richfaces/renderkit/ModalPanelRendererBase.java
branches/3.0.2/richfaces/modal-panel/src/main/resources/org/richfaces/renderkit/html/scripts/modalPanel.js
branches/3.0.2/richfaces/modal-panel/src/main/templates/org/richfaces/htmlModalPanel.jspx
Log:
http://jira.jboss.com/jira/browse/RF-69
Modified: branches/3.0.2/richfaces/modal-panel/src/main/config/component/modalPanel.xml
===================================================================
---
branches/3.0.2/richfaces/modal-panel/src/main/config/component/modalPanel.xml 2007-07-06
16:30:51 UTC (rev 1528)
+++
branches/3.0.2/richfaces/modal-panel/src/main/config/component/modalPanel.xml 2007-07-06
17:02:52 UTC (rev 1529)
@@ -176,7 +176,7 @@
<defaultvalue>false</defaultvalue>
</property>
<property>
- <name>keepState</name>
+ <name>keepVisualState</name>
<classname>boolean</classname>
<description>
</description>
Modified:
branches/3.0.2/richfaces/modal-panel/src/main/java/org/richfaces/component/UIModalPanel.java
===================================================================
---
branches/3.0.2/richfaces/modal-panel/src/main/java/org/richfaces/component/UIModalPanel.java 2007-07-06
16:30:51 UTC (rev 1528)
+++
branches/3.0.2/richfaces/modal-panel/src/main/java/org/richfaces/component/UIModalPanel.java 2007-07-06
17:02:52 UTC (rev 1529)
@@ -21,7 +21,10 @@
package org.richfaces.component;
-import javax.faces.component.UIComponentBase;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import org.ajax4jsf.framework.skin.Skin;
@@ -31,12 +34,14 @@
* JSF component class
*
*/
-public abstract class UIModalPanel extends UIComponentBase {
+public abstract class UIModalPanel extends UIInput {
public static final String COMPONENT_TYPE = "org.richfaces.ModalPanel";
private static final String COMPONENT_FAMILY = "org.richfaces.ModalPanel";
+ private Map visualOptions;
+
/**
* Shadow depth.
*/
@@ -72,8 +77,8 @@
public abstract boolean isShowWhenRendered();
public abstract void setShowWhenRendered(boolean opened);
- public abstract boolean isKeepState();
- public abstract void setKeepState(boolean keepState);
+ public abstract boolean isKeepVisualState();
+ public abstract void setKeepVisualState(boolean keepVisualState);
public boolean getRendersChildren() {
return true;
@@ -111,4 +116,13 @@
return shadowStyle;
}
+
+ public Map getVisualOptions() {
+ if (null == visualOptions)
+ visualOptions = new HashMap();
+ return visualOptions;
+ }
+ public void setVisualOptions(Map visualOptions) {
+ this.visualOptions = visualOptions;
+ }
}
Modified:
branches/3.0.2/richfaces/modal-panel/src/main/java/org/richfaces/renderkit/ModalPanelRendererBase.java
===================================================================
---
branches/3.0.2/richfaces/modal-panel/src/main/java/org/richfaces/renderkit/ModalPanelRendererBase.java 2007-07-06
16:30:51 UTC (rev 1528)
+++
branches/3.0.2/richfaces/modal-panel/src/main/java/org/richfaces/renderkit/ModalPanelRendererBase.java 2007-07-06
17:02:52 UTC (rev 1529)
@@ -22,8 +22,11 @@
package org.richfaces.renderkit;
import java.io.IOException;
+import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
+import javax.faces.component.UIComponent;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
@@ -39,17 +42,44 @@
* created 13.02.2007
*
*/
-public class ModalPanelRendererBase extends AjaxComponentRendererBase {
+public class ModalPanelRendererBase extends InputRendererBase {
//TODO nick - set sizeA to actual min value
private static final int sizeA = 10;
+ private static final String STATE_OPTION_SUFFIX = "StateOption_";
+
protected String[] RESIZERS = new String[] {
"NWU", "N", "NEU", "NEL", "E",
"SEU", "SEL", "S", "SWL",
"SWU", "W", "NWL"
};
+ protected void doDecode(FacesContext context, UIComponent component) {
+ super.doDecode(context, component);
+
+ UIModalPanel panel = (UIModalPanel)component;
+ ExternalContext exCtx = context.getExternalContext();
+ Map rqMap = exCtx.getRequestParameterMap();
+ Object clnId = rqMap.get(panel.getClientId(context) + "OpenedState");
+
+ if (panel.isKeepVisualState()) {
+ if (null != clnId) {
+ panel.setShowWhenRendered(new Boolean((String) clnId).booleanValue());
+
+ Iterator it = rqMap.entrySet().iterator();
+ while ( it.hasNext()) {
+ Map.Entry entry = (Map.Entry)it.next();
+ int suffixPos = entry.getKey().toString().indexOf(STATE_OPTION_SUFFIX);
+ if (-1 != suffixPos) {
+ String key = entry.getKey().toString().substring(suffixPos +
STATE_OPTION_SUFFIX.length());
+ panel.getVisualOptions().put(key, entry.getValue());
+ }
+ }
+ }
+ }
+ }
+
protected Class getComponentClass() {
return UIModalPanel.class;
}
@@ -101,26 +131,20 @@
public String getShowScript(FacesContext context, UIModalPanel panel) {
StringBuffer result = new StringBuffer();
- ExternalContext exCtx = context.getExternalContext();
- Map rqMap = exCtx.getRequestParameterMap();
- Object clnId = rqMap.get(panel.getClientId(context) + "OpenedState");
-
- if (panel.isKeepState()) {
- if (null != clnId) {
- boolean opened = new Boolean((String) clnId).booleanValue();
- panel.setShowWhenRendered(opened);
- if (opened) {
- result.append("Richfaces.showModalPanel('" +
panel.getClientId(context) + "');");
- }
- } else {
- if (panel.isShowWhenRendered()) {
- result.append("Richfaces.showModalPanel('" +
panel.getClientId(context) + "');");
- }
- }
- } else {
- if (null == clnId && panel.isShowWhenRendered()) {
- result.append("Richfaces.showModalPanel('" + panel.getClientId(context)
+ "');");
+ if (panel.isKeepVisualState() && panel.isShowWhenRendered()) {
+ result.append("Richfaces.showModalPanel('" + panel.getClientId(context)
+ "', {");
+
+ Iterator it = panel.getVisualOptions().entrySet().iterator();
+ while (it.hasNext()) {
+ Map.Entry entry = (Map.Entry)it.next();
+
+ result.append(entry.getKey() + ": '" + entry.getValue() +
"'");
+ if (it.hasNext()) {
+ result.append(", ");
+ }
}
+
+ result.append("});");
}
return result.toString();
}
Modified:
branches/3.0.2/richfaces/modal-panel/src/main/resources/org/richfaces/renderkit/html/scripts/modalPanel.js
===================================================================
---
branches/3.0.2/richfaces/modal-panel/src/main/resources/org/richfaces/renderkit/html/scripts/modalPanel.js 2007-07-06
16:30:51 UTC (rev 1528)
+++
branches/3.0.2/richfaces/modal-panel/src/main/resources/org/richfaces/renderkit/html/scripts/modalPanel.js 2007-07-06
17:02:52 UTC (rev 1529)
@@ -358,10 +358,11 @@
}
var forms = this.cdiv.getElementsByTagName("form");
- if (forms) {
- this.formOnload = this.setStateInput.bindAsEventListener(this);
+
+ if (this.options.keepVisualState && forms) {
+ this.formOnsubmit = this.setStateInput.bindAsEventListener(this);
for (var i = 0; i < forms.length; i++) {
- Event.observe(forms[i], "submit", this.formOnload);
+ Event.observe(forms[i], "submit", this.formOnsubmit);
}
}
@@ -388,16 +389,18 @@
Object.extend(options, opts);
}
+ Object.extend(this.options, options);
+
if (options.width) {
if (this.minWidth > options.width) {
options.width = this.minWidth;
}
if (this.iframe) {
- this.iframe.style.width = options.width + 'px';
+ this.iframe.style.width = options.width + (/px/.test(options.width) ? '' :
'px');
}
- this.contentDiv.style.width = options.width + 'px';
- this.shadowDiv.style.width = options.width + 'px';
+ this.contentDiv.style.width = options.width + (/px/.test(options.width) ? '' :
'px');
+ this.shadowDiv.style.width = options.width + (/px/.test(options.width) ? '' :
'px');
}
if (options.height) {
@@ -406,10 +409,10 @@
}
if (this.iframe) {
- this.iframe.style.height = options.height + 'px';
+ this.iframe.style.height = options.height + (/px/.test(options.height) ? '' :
'px');
}
- this.contentDiv.style.height = options.height + 'px';
- this.shadowDiv.style.height = options.height + 'px';
+ this.contentDiv.style.height = options.height + (/px/.test(options.height) ?
'' : 'px');
+ this.shadowDiv.style.height = options.height + (/px/.test(options.height) ? ''
: 'px');
}
if (options.left) {
@@ -530,7 +533,7 @@
hide: function(opts) {
this.restoreFocus();
- this.traverseSelects(true);
+ this.traverseSelects(true);
if (this.div.style.removeExpression) {
this.div.style.removeExpression("width");
@@ -560,6 +563,13 @@
var event = {};
event.parameters = opts || {};
if (this.eventOnHide) this.eventOnHide(event);
+
+ var forms = this.cdiv.getElementsByTagName("form");
+ if (this.options.keepVisualState && forms) {
+ for (var i = 0; i < forms.length; i++) {
+ Event.stopObserving(forms[i], "submit", this.formOnsubmit);
+ }
+ }
this.shown = false;
},
@@ -608,6 +618,7 @@
newPos += diff.deltaX;
this.cdiv.mpLeft = newPos;
+ cssHash.left = newPos + 'px';
} else {
newPos = Richfaces.getComputedStyleSize(this.cdiv, "left");
newPos += diff.deltaX;
@@ -648,6 +659,7 @@
newPos += diff.deltaY;
this.cdiv.mpTop = newPos;
+ cssHash.top = newPos + 'px';
} else {
newPos = Richfaces.getComputedStyleSize(this.cdiv, "top");
newPos += diff.deltaY;
@@ -662,6 +674,9 @@
if (this.iframe) {
Element.setStyle(this.iframe, cssHashWH);
}
+
+ Object.extend(this.options, cssHash);
+ Object.extend(this.options, cssHashWH);
var w = this.context.width();
var h = this.context.height();
@@ -689,14 +704,28 @@
},
setStateInput: function(e) {
- if (e && e.target) {
+ var target = e.target ? e.target : e.srcElement;
+ if (e && target) {
var input = document.createElement("input");
input.type = "hidden";
input.id = this.markerId.id + "OpenedState";
input.name = this.markerId.id + "OpenedState";
input.value = this.shown ? "true" : "false";
+ target.appendChild(input);
- e.target.appendChild(input);
+ var keys = $H(this.options).keys();
+ if (keys) {
+ for (var i = 0; i < keys.length; i++) {
+ input = document.createElement("input");
+ input.type = "hidden";
+ input.id = this.markerId.id + "StateOption_" + keys[i];
+ input.name = this.markerId.id + "StateOption_" + keys[i];
+ input.value = this.options[keys[i]];
+ target.appendChild(input);
+
+ }
+ }
+
return true;
}
}
Modified:
branches/3.0.2/richfaces/modal-panel/src/main/templates/org/richfaces/htmlModalPanel.jspx
===================================================================
---
branches/3.0.2/richfaces/modal-panel/src/main/templates/org/richfaces/htmlModalPanel.jspx 2007-07-06
16:30:51 UTC (rev 1528)
+++
branches/3.0.2/richfaces/modal-panel/src/main/templates/org/richfaces/htmlModalPanel.jspx 2007-07-06
17:02:52 UTC (rev 1529)
@@ -134,7 +134,7 @@
onshow: #{onshow},
onhide: #{onhide},
- keepState: #{component.keepState},
+ keepVisualState: #{component.keepVisualState},
showWhenRendered: #{component.showWhenRendered}
});
</script>