Author: SergeySmirnov
Date: 2007-11-12 17:10:32 -0500 (Mon, 12 Nov 2007)
New Revision: 3938
Modified:
trunk/sandbox/samples/rex-demo/src/main/webapp/richfaces/button/examples/simple.xhtml
trunk/sandbox/samples/rex-demo/src/main/webapp/richfaces/resizable/usage.xhtml
trunk/sandbox/ui/componentControl/src/main/java/org/richfaces/sandbox/component/UIComponentControl.java
trunk/sandbox/ui/componentControl/src/main/templates/htmlComponentControl.jspx
Log:
server side attachment for componentControl has been added added
Modified:
trunk/sandbox/samples/rex-demo/src/main/webapp/richfaces/button/examples/simple.xhtml
===================================================================
---
trunk/sandbox/samples/rex-demo/src/main/webapp/richfaces/button/examples/simple.xhtml 2007-11-12
20:20:31 UTC (rev 3937)
+++
trunk/sandbox/samples/rex-demo/src/main/webapp/richfaces/button/examples/simple.xhtml 2007-11-12
22:10:32 UTC (rev 3938)
@@ -10,7 +10,12 @@
<f:view contentType="text/html">
+ <h:inputText >
+ <cc:componentControl name="controlMe" event="onclick"
attachTiming="onload" for="mb4"
params="animEl:'d:mb4'" operation="show"/>
+ </h:inputText>
+
+
<h:form id="f">
<rex:button id="a" style="color:red" value="The real button
Name">
@@ -19,29 +24,26 @@
<rich:panel id="mb3" style="width:100px;border:1px solid
red">Start</rich:panel>
- <cc:componentControl event="onclick" attachTo="mb3"
for="mb4" operation="show"/>
-
- <rex:button id="mb4" onclick="aaa()" value="Show Box"
/>
-
-
</h:form>
+ <f:subview id="d">
+ <rex:button id="mb4" onclick="aaa()" value="Show Box"
/>
+ </f:subview>
-
<rich:modalPanel id="dd">
<h:outputText value="hello" />
</rich:modalPanel>
<script>
- jQuery('#f\\:mb4')[0].component = {};
- jQuery('#f\\:mb4')[0].component.show = function(event, params) {
- jQuery('#f\\:mb4').click();
+ jQuery('#d\\:mb4')[0].component = {};
+ jQuery('#d\\:mb4')[0].component.show = function(event, params) {
+ jQuery('#d\\:mb4').click();
}
</script>
- <button onclick="upup()">UpUp</button>
+ <button onclick="controlMe()">UpUp</button>
Modified: trunk/sandbox/samples/rex-demo/src/main/webapp/richfaces/resizable/usage.xhtml
===================================================================
---
trunk/sandbox/samples/rex-demo/src/main/webapp/richfaces/resizable/usage.xhtml 2007-11-12
20:20:31 UTC (rev 3937)
+++
trunk/sandbox/samples/rex-demo/src/main/webapp/richfaces/resizable/usage.xhtml 2007-11-12
22:10:32 UTC (rev 3938)
@@ -14,9 +14,9 @@
<div class="sample-container" >
- <ui:include src="/richfaces/button/examples/simple.xhtml"/>
+ <ui:include src="/richfaces/resizable/examples/simple.xhtml"/>
<ui:include src="/templates/include/sourceview.xhtml">
- <ui:param name="sourcepath"
value="/richfaces/button/examples/simple.xhtml"/>
+ <ui:param name="sourcepath"
value="/richfaces/resizable/examples/simple.xhtml"/>
</ui:include>
</div>
Modified:
trunk/sandbox/ui/componentControl/src/main/java/org/richfaces/sandbox/component/UIComponentControl.java
===================================================================
---
trunk/sandbox/ui/componentControl/src/main/java/org/richfaces/sandbox/component/UIComponentControl.java 2007-11-12
20:20:31 UTC (rev 3937)
+++
trunk/sandbox/ui/componentControl/src/main/java/org/richfaces/sandbox/component/UIComponentControl.java 2007-11-12
22:10:32 UTC (rev 3938)
@@ -4,16 +4,106 @@
package org.richfaces.sandbox.component;
+import org.ajax4jsf.Messages;
+import org.ajax4jsf.component.EventValueBinding;
import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+import javax.faces.component.UIComponent;
+import org.ajax4jsf.component.AjaxSupport;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.ajax4jsf.renderkit.RendererUtils;
+import org.richfaces.component.util.HtmlUtil;
/**
* JSF component class
*
*/
-public abstract class UIComponentControl extends UIComponentBase {
+public abstract class UIComponentControl extends UIComponentBase implements AjaxSupport
{
public static final String COMPONENT_TYPE =
"org.richfaces.sandbox.ComponentControl";
public static final String COMPONENT_FAMILY =
"org.richfaces.sandbox.ComponentControl";
+
+ private static final Log log = LogFactory.getLog(UIComponentControl.class);
+
+ /**
+ * @return JavaScript eventString. Rebuild on every call, since
+ * can be in loop ( as in dataTable ) with different parameters.
+ */
+ public String getEventString()
+ {
+ StringBuffer buildOnEvent = new StringBuffer();
+
+ String targetId="#" + getFor();
+
+ targetId=HtmlUtil.expandIdSelector(targetId, this, FacesContext.getCurrentInstance());
+
+ buildOnEvent.append("Richfaces.componentControl.performOperation(
null,");
+ buildOnEvent.append("'" + targetId + "',");
+ buildOnEvent.append("'" + getOperation() + "',");
+ buildOnEvent.append("{" + getParams() + "});");
+
+ return buildOnEvent.toString();
+
+
+ }
+
+
+ public abstract String getEvent();
+ public abstract void setEvent(String event);
+
+ public abstract String getFor();
+ public abstract void setFor(String value);
+
+ public abstract String getParams();
+ public abstract void setParams(String value);
+
+ public abstract String getOperation();
+ public abstract void setOperation(String value);
+
+ public abstract String getAttachTo();
+ public abstract void setAttachTo(String value);
+
+ protected String replaceClientIds(FacesContext context, UIComponent component, String
selector) {
+ return HtmlUtil.expandIdSelector(selector, component, context);
+ }
+
+
+ /**
+ * After nornal setting <code>parent</code> property in case of
+ * created component set Ajax properties for parent.
+ * @see
javax.faces.component.UIComponentBase#setParent(javax.faces.component.UIComponent)
+ */
+ public void setParent(UIComponent parent)
+ {
+ super.setParent(parent);
+ if (null != parent && parent.getFamily() != null ) {
+ if (log.isDebugEnabled()) {
+ log.debug(Messages.getMessage(Messages.CALLED_SET_PARENT,
parent.getClass().getName()));
+ }
+ // TODO If this comopnent configured, set properties for parent component.
+ // NEW created component have parent, restored view - null in My faces.
+ // and SUN RI not call at restore saved view.
+ // In other case - set in restoreState method.
+ // if (parent.getParent() != null)
+ {
+ if (log.isDebugEnabled()) {
+ log.debug(Messages.getMessage(Messages.DETECT_NEW_COMPONENT));
+ }
+ setParentProperties(parent);
+
+ }
+ }
+ }
+
+
+ public void setParentProperties(UIComponent parent){
+ if (getAttachTo() == "" && getEvent() !="" ) {
+ parent.setValueBinding(getEvent(), new EventValueBinding(this));
+ }
+ }
+
+
}
Modified: trunk/sandbox/ui/componentControl/src/main/templates/htmlComponentControl.jspx
===================================================================
---
trunk/sandbox/ui/componentControl/src/main/templates/htmlComponentControl.jspx 2007-11-12
20:20:31 UTC (rev 3937)
+++
trunk/sandbox/ui/componentControl/src/main/templates/htmlComponentControl.jspx 2007-11-12
22:10:32 UTC (rev 3938)
@@ -24,19 +24,15 @@
<jsp:scriptlet>
<![CDATA[
String event = (String) variables.getVariable("event");
- String forAttr = (String) variables.getVariable("forAttr");
+ String forAttr = "#"+(String) variables.getVariable("forAttr");
String attachTiming = (String) variables.getVariable("attachTiming");
- String attachTo = (String) variables.getVariable("attachTo");
+ String attachTo = "#"+(String) variables.getVariable("attachTo");
String name = (String) variables.getVariable("name");
String operation = (String) variables.getVariable("operation");
checkValidity(clientId, name, attachTiming, forAttr, operation);
- System.out.println("Before search for client id:" + forAttr);
- variables.setVariable("forAttr", replaceClientIds(context, component,
"#" + forAttr));
- System.out.println("After search for client id:" + (String)
variables.getVariable("forAttr"));
- System.out.println("Before search for client id:" + attachTo);
- variables.setVariable("attachTo", replaceClientIds(context, component,
"#" + attachTo));
- System.out.println("After search for client id:" + (String)
variables.getVariable("attachTo"));
+ variables.setVariable("forAttr", replaceClientIds(context, component,
forAttr));
+ variables.setVariable("attachTo", replaceClientIds(context, component,
attachTo));
]]>
</jsp:scriptlet>
@@ -52,7 +48,7 @@
<jsp:scriptlet><![CDATA[ } ]]></jsp:scriptlet>
-<jsp:scriptlet><![CDATA[ if ( "immediate".equals(attachTiming) ) {
]]></jsp:scriptlet>
+<jsp:scriptlet><![CDATA[ if ( "immediate".equals(attachTiming)
&& ! "#".equals(attachTo) ) { ]]></jsp:scriptlet>
<script type="text/javascript">
//<![CDATA[
{
@@ -67,7 +63,7 @@
-<jsp:scriptlet><![CDATA[ if ( "onload".equals(attachTiming) ) {
]]></jsp:scriptlet>
+<jsp:scriptlet><![CDATA[ if ( "onload".equals(attachTiming) &&
! "#".equals(attachTo) ) {]]></jsp:scriptlet>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function() {
@@ -78,11 +74,5 @@
//]]>
</script>
<jsp:scriptlet><![CDATA[ } ]]></jsp:scriptlet>
-
-
- <div id="#{clientId}"
- x:passThruWithExclusions="value,name,type,id"
- >Here we start
- </div>
</f:root>
\ No newline at end of file