You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by pr...@apache.org on 2005/11/23 02:20:09 UTC
svn commit: r348335 - in
/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom: ajax/util/
inputAjax/
Author: prophecy
Date: Tue Nov 22 17:20:07 2005
New Revision: 348335
URL: http://svn.apache.org/viewcvs?rev=348335&view=rev
Log:
- can use images for selectBoolean now instead of the default checkbox.
Modified:
myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/ajax/util/AjaxRendererUtils.java
myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlMessageRenderer.java
myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlMessageTag.java
myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlSelectBooleanCheckboxAjax.java
myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlSelectBooleanCheckboxAjaxRenderer.java
Modified: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/ajax/util/AjaxRendererUtils.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/ajax/util/AjaxRendererUtils.java?rev=348335&r1=348334&r2=348335&view=diff
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/ajax/util/AjaxRendererUtils.java (original)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/ajax/util/AjaxRendererUtils.java Tue Nov 22 17:20:07 2005
@@ -183,9 +183,7 @@
// a function that can take the actual element for things like HtmlSelectMany
buff.append("function ").append(jsNameSpace).append("ajaxSubmit2(el, elname){\n")
.append(" var elvalue = el.value;\n")
- .append(" ")
- .append(jsNameSpace)
- .append("ajaxSubmit(elname, elvalue, el);\n")
+ .append(" ").append(jsNameSpace).append("ajaxSubmit(elname, elvalue, el);\n")
.append("}\n");
// and now the actual function that will send the request
Modified: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlMessageRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlMessageRenderer.java?rev=348335&r1=348334&r2=348335&view=diff
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlMessageRenderer.java (original)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlMessageRenderer.java Tue Nov 22 17:20:07 2005
@@ -11,9 +11,15 @@
*/
public class HtmlMessageRenderer extends org.apache.myfaces.renderkit.html.ext.HtmlMessageRenderer
{
+ /**
+ * This overrides the rendering to make sure it will output a span even if there is no message.
+ *
+ * @param facesContext
+ * @param component
+ * @throws IOException
+ */
public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException
{
- System.out.println("ENCODEEND IN New Message Renderer");
//super.encodeEnd(facesContext, component);
// Make sure a span is output
renderMessage(facesContext, component, true);
Modified: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlMessageTag.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlMessageTag.java?rev=348335&r1=348334&r2=348335&view=diff
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlMessageTag.java (original)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlMessageTag.java Tue Nov 22 17:20:07 2005
@@ -53,22 +53,6 @@
protected UIComponent findComponent(FacesContext context) throws JspException
{
- log.debug("FINDCOMPONENT");
- String id = getId();
- //UIComponent comp = getComponentInstance();
- log.debug("ID WAS: " + id);
- if (id == null)
- {
- // default id so client side scripts can use this (ie: ajax), this will obviously break things if someone specifies an id, so please don't specify an id if using Ajax components!
- id = "msgFor_" + getFor();
- log.debug("Setting id on MessageTag: " + id);
- setId(id);
- setForceId("true");
- /*if(comp != null){
- log.debug("SETTING COMP ID");
- comp.setId(id);
- }*/
- }
return super.findComponent(context);
}
}
Modified: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlSelectBooleanCheckboxAjax.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlSelectBooleanCheckboxAjax.java?rev=348335&r1=348334&r2=348335&view=diff
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlSelectBooleanCheckboxAjax.java (original)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlSelectBooleanCheckboxAjax.java Tue Nov 22 17:20:07 2005
@@ -50,8 +50,8 @@
// Handled differently
Map requestParams = context.getExternalContext().getRequestParameterMap();
- String checkedStr = (String) requestParams.get("checked");
- log.debug("checked: " + checkedStr);
+ String checkedStr = (String) requestParams.get("elvalue");
+ log.debug("elvalue: " + checkedStr);
boolean checked = Boolean.valueOf(checkedStr).booleanValue();
if (checked)
{
Modified: myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlSelectBooleanCheckboxAjaxRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlSelectBooleanCheckboxAjaxRenderer.java?rev=348335&r1=348334&r2=348335&view=diff
==============================================================================
--- myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlSelectBooleanCheckboxAjaxRenderer.java (original)
+++ myfaces/sandbox/trunk/src/java/org/apache/myfaces/custom/inputAjax/HtmlSelectBooleanCheckboxAjaxRenderer.java Tue Nov 22 17:20:07 2005
@@ -2,6 +2,7 @@
import org.apache.myfaces.renderkit.html.ext.HtmlCheckboxRenderer;
import org.apache.myfaces.renderkit.html.HtmlRendererUtils;
+import org.apache.myfaces.renderkit.html.HTML;
import org.apache.myfaces.renderkit.RendererUtils;
import org.apache.myfaces.custom.ajax.api.AjaxRenderer;
import org.apache.myfaces.custom.ajax.util.AjaxRendererUtils;
@@ -27,7 +28,7 @@
*/
public class HtmlSelectBooleanCheckboxAjaxRenderer extends HtmlCheckboxRenderer implements AjaxRenderer
{
- private static final Log log = LogFactory.getLog(HtmlSelectBooleanCheckboxAjaxRenderer.class);
+ private static final Log log = LogFactory.getLog(HtmlSelectBooleanCheckboxAjaxRenderer.class);
private static final String JAVASCRIPT_ENCODED = "org.apache.myfaces.custom.inputAjax.HtmlSelectBooleanCheckboxAjax.JAVASCRIPT_ENCODED";
@@ -51,10 +52,36 @@
// write required javascript
ResponseWriter out = context.getResponseWriter();
- String extraParams =("&checked=\" + el.checked + \"");
+ String extraParams = null; //("&checked=\" + el.checked + \"");
AjaxRendererUtils.writeAjaxScript(context, out, selectBooleanCheckbox, extraParams);
- // set request var that says what it's going to do
+ if (!context.getExternalContext().getRequestMap().containsKey(JAVASCRIPT_ENCODED))
+ {
+ // write a special script to swap out images onclick.
+ out.startElement(HTML.SCRIPT_ELEM, null);
+ out.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);
+
+ StringBuffer buff = new StringBuffer();
+ // todo: what if an error occurs? we should swap back to actual value back in server side model in an onComplete function
+ buff.append("function ").append(AjaxRendererUtils.JS_MYFACES_NAMESPACE).append("swapImages(imgEl, hiddenElId, onImg, offImg){\n")
+ .append(" var hiddenEl = document.getElementById(hiddenElId);\n")
+ .append(" var currValue = hiddenEl.value;\n")
+ .append(" if(currValue == 'true') {\n")
+ .append(" hiddenEl.value = 'false';\n")
+ .append(" imgEl.src = offImg;\n")
+ .append(" } else {\n")
+ .append(" hiddenEl.value = 'true';\n")
+ .append(" imgEl.src = onImg;\n")
+ .append(" }\n")
+ //.append(" if(imgEl.src == offImg) imgEl.src = onImg;\n")
+ //.append(" if(imgEl.src == onImg) imgEl.src = offImg;\n")
+ .append("}\n");
+ out.writeText(buff.toString(), null);
+
+ out.endElement(HTML.SCRIPT_ELEM);
+ }
+
+ // set request var to make sure this doesn't get written again
context.getExternalContext().getRequestMap().put(JAVASCRIPT_ENCODED, Boolean.TRUE);
}
@@ -73,23 +100,64 @@
// allow for user defined onclick's as well
String onClick = selectBooleanCheckbox.getOnclick();
- if(onClick == null){
+ if (onClick == null)
+ {
onClick = "";
}
- onClick = component.getId() + "_MyFaces_inputAjax_ajaxSubmit2(this, '" + clientId + "'); " + onClick;
+ onClick = component.getId() + "_MyFaces_inputAjax_ajaxSubmit1('" + clientId + "'); " + onClick;
selectBooleanCheckbox.setOnclick(onClick);
this.encodeJavascript(context, component);
- super.encodeEnd(context, component);
+
+ String onImgUrl = selectBooleanCheckbox.getOnImage();
+ String offImgUrl = selectBooleanCheckbox.getOffImage();
+ ResponseWriter out = context.getResponseWriter();
+ if (selectBooleanCheckbox.getOnImage() != null)
+ {
+
+ Object valOb = selectBooleanCheckbox.getValue();
+ if (valOb != null)
+ {
+ if (valOb instanceof Boolean)
+ {
+ Boolean val = (Boolean) valOb;
+
+ // then render an image instead
+ // and a hidden input to store value
+ out.startElement(HTML.INPUT_ELEM, null);
+ out.writeAttribute(HTML.TYPE_ATTR, "hidden", null);
+ out.writeAttribute(HTML.NAME_ATTR, clientId, null);
+ out.writeAttribute(HTML.ID_ATTR, clientId, null);
+ out.writeAttribute(HTML.VALUE_ATTR, val, null);
+ out.endElement(HTML.INPUT_ELEM);
+
+ String imgUrl = val.booleanValue() ? onImgUrl : offImgUrl;
+ out.startElement(HTML.IMG_ELEM, null);
+ out.writeAttribute(HTML.SRC_ATTR, imgUrl, null);
+ // add the swap image function to onClick as well
+ onClick = AjaxRendererUtils.JS_MYFACES_NAMESPACE + "swapImages(this, '" + clientId + "', '" + onImgUrl + "', '" + offImgUrl + "'); " + onClick;
+ out.writeAttribute(HTML.ONCLICK_ATTR, onClick, null);
+ out.endElement(HTML.IMG_ELEM);
+ }
+ else
+ {
+ log.error("HtmlSelectBooleanAjax.value is not an instance of Boolean: " + valOb);
+ }
+ }
+ }
+ else
+ {
+ super.encodeEnd(context, component);
+ }
}
public void encodeAjax(FacesContext context, UIComponent component) throws IOException
{
log.debug("entering HtmlSelectBooleanCheckboxAjaxRenderer.encodeAjax");
- // check for request type (portlet support)
- HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
+// check for request type (portlet support)
+ /*HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
Map extraReturnAttributes = new HashMap();
- extraReturnAttributes.put("checked", request.getParameter("checked"));
- AjaxRendererUtils.encodeAjax(context, component, extraReturnAttributes);
+ extraReturnAttributes.put("checked", request.getParameter("checked"));*/
+ AjaxRendererUtils.encodeAjax(context, component, null);
}
}