Author: mwringe
Date: 2011-09-17 10:54:48 -0400 (Sat, 17 Sep 2011)
New Revision: 7460
Added:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/input/
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/input/UICheckBoxInput.java
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/UIForm.java
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/UIFormCheckBoxInput.java
epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIWizardPageSetInfo.java
Log:
JBEPP-1160, JBEPP-1142: Fix issue with checkboxes not working properly. Update to use the
new UICheckBoxInput instead of UIFormCheckBoxInput (see GTNPORTAL-1916 &
GTNPORTAL-1916)
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/UIForm.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/UIForm.java 2011-09-16
22:33:32 UTC (rev 7459)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/UIForm.java 2011-09-17
14:54:48 UTC (rev 7460)
@@ -27,6 +27,7 @@
import org.exoplatform.webui.config.Event;
import org.exoplatform.webui.core.UIComponent;
import org.exoplatform.webui.core.UIContainer;
+import org.exoplatform.webui.form.input.UICheckBoxInput;
import java.io.Writer;
import java.util.List;
@@ -114,6 +115,11 @@
return findComponentById(name);
}
+ public UICheckBoxInput getUICheckBoxInput(String name)
+ {
+ return findComponentById(name);
+ }
+
public UIFormSelectBox getUIFormSelectBox(String name)
{
return findComponentById(name);
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/UIFormCheckBoxInput.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/UIFormCheckBoxInput.java 2011-09-16
22:33:32 UTC (rev 7459)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/UIFormCheckBoxInput.java 2011-09-17
14:54:48 UTC (rev 7460)
@@ -27,9 +27,11 @@
/**
* Represents a checkbox field.
* @param <T> The type of value that is expected
+ * @deprecated use {@link org.exoplatform.webui.form.input.UICheckBoxInput} instead
*/
@SuppressWarnings("hiding")
@Serialized
+@Deprecated
public class UIFormCheckBoxInput<T> extends UIFormInputBase<T>
{
/**
@@ -54,7 +56,7 @@
super(name, bindingExpression, null);
if (value != null)
typeValue_ = (Class<T>)value.getClass();
- setValue(value);
+ value_ = value;
setId(name);
}
Added:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/input/UICheckBoxInput.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/input/UICheckBoxInput.java
(rev 0)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/input/UICheckBoxInput.java 2011-09-17
14:54:48 UTC (rev 7460)
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2011 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.webui.form.input;
+
+import java.io.Writer;
+
+import org.exoplatform.commons.serialization.api.annotations.Serialized;
+import org.exoplatform.webui.application.WebuiRequestContext;
+import org.exoplatform.webui.form.UIForm;
+import org.exoplatform.webui.form.UIFormInput;
+import org.exoplatform.webui.form.UIFormInputBase;
+
+/**
+ * <p>Represent an html checkbox input <br/>
+ * This class is a replacement for {@link org.exoplatform.webui.form.UIFormCheckBoxInput}
<br/>
+ * Still support raising event when user click the checkbox, but now we only accept
boolean value. </p>
+ *
+ * @author <a href="mailto:phuong.vu@exoplatform.com">Vu Viet
Phuong</a>
+ * @version $Id$
+ */
+@Serialized
+public class UICheckBoxInput extends UIFormInputBase<Boolean>
+{
+ /**
+ * Name of {@link org.exoplatform.webui.event.EventListener} that will be fired when
checkbox state is changed
+ */
+ private String onchange_;
+
+ /**
+ * Id of {@link org.exoplatform.webui.core.UIComponent} that is configured with the
fired event
+ * This component must be in the same form with the checkbox
+ * If this field is null, event of the UIForm will be fire instead
+ */
+ private String componentEvent_ = null;
+
+ public UICheckBoxInput()
+ {
+ this(null, null, false);
+ }
+
+ public UICheckBoxInput(String name, String bindingExpression, Boolean value)
+ {
+ super(name, bindingExpression, Boolean.class);
+ setValue(value);
+ }
+
+ public UIFormInput<Boolean> setValue(Boolean value)
+ {
+ if (value == null)
+ {
+ value = false;
+ }
+
+ return super.setValue(value);
+ }
+
+ /**
+ * This method is used to make the action more meaning in the context of a checkbox
+ */
+ public boolean isChecked()
+ {
+ return getValue();
+ }
+
+ /**
+ * This method is used to make the action more meaning in the context of a checkbox
+ */
+ public UICheckBoxInput setChecked(boolean check)
+ {
+ return (UICheckBoxInput)setValue(check);
+ }
+
+ public void setOnChange(String onchange)
+ {
+ onchange_ = onchange;
+ }
+
+ public void setComponentEvent(String com)
+ {
+ componentEvent_ = com;
+ }
+
+ public void setOnChange(String event, String com)
+ {
+ this.onchange_ = event;
+ this.componentEvent_ = com;
+ }
+
+ public String renderOnChangeEvent(UIForm uiForm) throws Exception
+ {
+ if (componentEvent_ == null)
+ return uiForm.event(onchange_, null);
+ return uiForm.event(onchange_, componentEvent_, (String)null);
+ }
+
+ public void decode(Object input, WebuiRequestContext context) throws Exception
+ {
+ if (!isEnable())
+ return;
+
+ if (input == null || "false".equals(input.toString()))
+ {
+ setValue(false);
+ }
+ else
+ {
+ setValue(true);
+ }
+ }
+
+ public void processRender(WebuiRequestContext context) throws Exception
+ {
+ Writer w = context.getWriter();
+ w.write("<input type='checkbox' name='");
+ w.write(name);
+ w.write("'");
+ if (onchange_ != null)
+ {
+ UIForm uiForm = getAncestorOfType(UIForm.class);
+ w.append("
onclick=\"").append(renderOnChangeEvent(uiForm)).append("\"");
+ }
+ if (isChecked())
+ w.write(" checked");
+ if (!enable_)
+ w.write(" disabled");
+ w.write(" class='checkbox'/>");
+ if (this.isMandatory())
+ w.write(" *");
+ }
+
+}
\ No newline at end of file
Property changes on:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/input/UICheckBoxInput.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIWizardPageSetInfo.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIWizardPageSetInfo.java 2011-09-16
22:33:32 UTC (rev 7459)
+++
epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIWizardPageSetInfo.java 2011-09-17
14:54:48 UTC (rev 7460)
@@ -43,11 +43,10 @@
import org.exoplatform.webui.event.Event.Phase;
import org.exoplatform.webui.form.UIForm;
import org.exoplatform.webui.form.UIFormDateTimeInput;
-import org.exoplatform.webui.form.UIFormInput;
import org.exoplatform.webui.form.UIFormInputBase;
import org.exoplatform.webui.form.UIFormSelectBox;
import org.exoplatform.webui.form.UIFormStringInput;
-import org.exoplatform.webui.form.UIFormCheckBoxInput;
+import org.exoplatform.webui.form.input.UICheckBoxInput;
import org.exoplatform.webui.form.validator.DateTimeValidator;
import org.exoplatform.webui.form.validator.IdentifierValidator;
import org.exoplatform.webui.form.validator.MandatoryValidator;
@@ -114,10 +113,10 @@
public UIWizardPageSetInfo() throws Exception
{
- UIFormCheckBoxInput uiDateInputCheck =
- new UIFormCheckBoxInput(SHOW_PUBLICATION_DATE, null, false);
- UIFormCheckBoxInput uiVisibleCheck = new UIFormCheckBoxInput(VISIBLE, null,
false);
- UIFormCheckBoxInput uiSwitchLabelMode = new UIFormCheckBoxInput(SWITCH_MODE, null,
true);
+ UICheckBoxInput uiDateInputCheck =
+ new UICheckBoxInput(SHOW_PUBLICATION_DATE, null, false);
+ UICheckBoxInput uiVisibleCheck = new UICheckBoxInput(VISIBLE, null, false);
+ UICheckBoxInput uiSwitchLabelMode = new UICheckBoxInput(SWITCH_MODE, null, true);
uiDateInputCheck.setOnChange("SwitchPublicationDate");
uiVisibleCheck.setOnChange("SwitchVisible");
uiSwitchLabelMode.setOnChange(SWITCH_MODE_ONCHANGE);
@@ -188,7 +187,7 @@
UserNode node = (UserNode)bean;
- if (((UIFormCheckBoxInput)getUIInput(SWITCH_MODE)).isChecked())
+ if (getUICheckBoxInput(SWITCH_MODE).isChecked())
{
node.setLabel(null);
}
@@ -198,9 +197,9 @@
}
Visibility visibility;
- if (((UIFormCheckBoxInput)getUIInput(VISIBLE)).isChecked())
+ if (getUICheckBoxInput(VISIBLE).isChecked())
{
- UIFormCheckBoxInput showPubDate = getUIInput(SHOW_PUBLICATION_DATE);
+ UICheckBoxInput showPubDate = getUICheckBoxInput(SHOW_PUBLICATION_DATE);
visibility = showPubDate.isChecked() ? Visibility.TEMPORAL :
Visibility.DISPLAYED;
}
else
@@ -229,8 +228,8 @@
public void setShowCheckPublicationDate(boolean show)
{
- ((UIFormCheckBoxInput)getUIInput(VISIBLE)).setChecked(show);
- UIFormCheckBoxInput uiForm = getUIInput(SHOW_PUBLICATION_DATE);
+ getUICheckBoxInput(VISIBLE).setChecked(show);
+ UICheckBoxInput uiForm = getUICheckBoxInput(SHOW_PUBLICATION_DATE);
uiForm.setRendered(show);
setShowPublicationDate(show && uiForm.isChecked());
}
@@ -407,7 +406,7 @@
public void execute(Event<UIWizardPageSetInfo> event) throws Exception
{
UIWizardPageSetInfo uiForm = event.getSource();
- boolean isCheck =
((UIFormCheckBoxInput)uiForm.getUIInput(SHOW_PUBLICATION_DATE)).isChecked();
+ boolean isCheck = uiForm.getUICheckBoxInput(SHOW_PUBLICATION_DATE).isChecked();
uiForm.getUIFormDateTimeInput(START_PUBLICATION_DATE).setRendered(isCheck);
uiForm.getUIFormDateTimeInput(END_PUBLICATION_DATE).setRendered(isCheck);
UIWizard uiWizard = uiForm.getAncestorOfType(UIWizard.class);
@@ -422,7 +421,7 @@
public void execute(Event<UIWizardPageSetInfo> event) throws Exception
{
UIWizardPageSetInfo uiForm = event.getSource();
- boolean isCheck =
((UIFormCheckBoxInput)uiForm.getUIInput(VISIBLE)).isChecked();
+ boolean isCheck = uiForm.getUICheckBoxInput(VISIBLE).isChecked();
uiForm.setShowCheckPublicationDate(isCheck);
event.getRequestContext().addUIComponentToUpdateByAjax(uiForm);
}
@@ -456,7 +455,7 @@
public void execute(Event<UIWizardPageSetInfo> event) throws Exception
{
UIWizardPageSetInfo uiForm = event.getSource();
- boolean isExtendedMode =
((UIFormCheckBoxInput)uiForm.getUIInput(SWITCH_MODE)).isChecked();
+ boolean isExtendedMode = uiForm.getUICheckBoxInput(SWITCH_MODE).isChecked();
uiForm.switchLabelMode(isExtendedMode);
event.getRequestContext().addUIComponentToUpdateByAjax(uiForm);
}