Author: phuong_vu
Date: 2011-06-08 05:48:07 -0400 (Wed, 08 Jun 2011)
New Revision: 6612
Added:
portal/branches/branch-GTNPORTAL-1921/webui/core/src/main/java/org/exoplatform/webui/form/input/
portal/branches/branch-GTNPORTAL-1921/webui/core/src/main/java/org/exoplatform/webui/form/input/UIFormCheckBoxInput.java
Modified:
portal/branches/branch-GTNPORTAL-1921/testsuite/webuibasedsamples/src/main/java/org/exoplatform/sample/webui/component/UISampleUIForm.java
portal/branches/branch-GTNPORTAL-1921/testsuite/webuibasedsamples/src/main/webapp/WEB-INF/conf/sample/webui/configuration.xml
portal/branches/branch-GTNPORTAL-1921/webui/core/src/main/java/org/exoplatform/webui/form/UIFormCheckBoxInput.java
Log:
GTNPORTAL-1916 New UIFormCheckBoxInput component with more constraint in API and better
implementation
Modified:
portal/branches/branch-GTNPORTAL-1921/testsuite/webuibasedsamples/src/main/java/org/exoplatform/sample/webui/component/UISampleUIForm.java
===================================================================
---
portal/branches/branch-GTNPORTAL-1921/testsuite/webuibasedsamples/src/main/java/org/exoplatform/sample/webui/component/UISampleUIForm.java 2011-06-08
09:09:21 UTC (rev 6611)
+++
portal/branches/branch-GTNPORTAL-1921/testsuite/webuibasedsamples/src/main/java/org/exoplatform/sample/webui/component/UISampleUIForm.java 2011-06-08
09:48:07 UTC (rev 6612)
@@ -33,7 +33,7 @@
import org.exoplatform.webui.event.Event;
import org.exoplatform.webui.event.EventListener;
import org.exoplatform.webui.form.UIForm;
-import org.exoplatform.webui.form.UIFormCheckBoxInput;
+import org.exoplatform.webui.form.input.UIFormCheckBoxInput;
import org.exoplatform.webui.form.UIFormDateTimeInput;
import org.exoplatform.webui.form.UIFormInput;
import org.exoplatform.webui.form.UIFormInputSet;
@@ -109,7 +109,7 @@
List<SelectItemOption<String>> selectItemOptions =
makeSelectItemOptions();
inputSet.addUIFormInput(new UIFormSelectBox(POSITION, null, selectItemOptions));
- inputSet.addUIFormInput(new UIFormCheckBoxInput<String>(RECEIVE_EMAIL, null,
"test"));
+ inputSet.addUIFormInput(new UIFormCheckBoxInput(RECEIVE_EMAIL, null, false));
List<SelectItemOption<String>> comboBoxItemOptions = new
ArrayList<SelectItemOption<String>>();
comboBoxItemOptions.add(new SelectItemOption<String>(("VI")));
@@ -220,7 +220,7 @@
UISampleUIForm uiForm = event.getSource();
String userName = uiForm.getUIStringInput(USERNAME).getValue();
String password = uiForm.getUIStringInput(PASSWORD).getValue();
- boolean receiveEmail =
uiForm.getUIFormCheckBoxInput(RECEIVE_EMAIL).isChecked();
+ boolean receiveEmail =
uiForm.<UIFormCheckBoxInput>getUIInput(RECEIVE_EMAIL).isChecked();
String favoriteColor = (String)uiForm.getUIInput(FAVORITE_COLOR).getValue();
String position = (String)uiForm.getUIInput(POSITION).getValue();
String gender = (String)uiForm.getUIInput(GENDER).getValue();
Modified:
portal/branches/branch-GTNPORTAL-1921/testsuite/webuibasedsamples/src/main/webapp/WEB-INF/conf/sample/webui/configuration.xml
===================================================================
---
portal/branches/branch-GTNPORTAL-1921/testsuite/webuibasedsamples/src/main/webapp/WEB-INF/conf/sample/webui/configuration.xml 2011-06-08
09:09:21 UTC (rev 6611)
+++
portal/branches/branch-GTNPORTAL-1921/testsuite/webuibasedsamples/src/main/webapp/WEB-INF/conf/sample/webui/configuration.xml 2011-06-08
09:48:07 UTC (rev 6612)
@@ -26,8 +26,7 @@
<application>
<ui-component-root>org.exoplatform.sample.webui.component.UISamplePortlet</ui-component-root>
<state-manager>org.exoplatform.webui.application.portlet.ParentAppStateManager</state-manager>
- <application-lifecycle-listeners>
-
<listener>org.exoplatform.portal.application.PortletStatisticLifecycle</listener>
+ <application-lifecycle-listeners>
</application-lifecycle-listeners>
</application>
</webui-configuration>
Modified:
portal/branches/branch-GTNPORTAL-1921/webui/core/src/main/java/org/exoplatform/webui/form/UIFormCheckBoxInput.java
===================================================================
---
portal/branches/branch-GTNPORTAL-1921/webui/core/src/main/java/org/exoplatform/webui/form/UIFormCheckBoxInput.java 2011-06-08
09:09:21 UTC (rev 6611)
+++
portal/branches/branch-GTNPORTAL-1921/webui/core/src/main/java/org/exoplatform/webui/form/UIFormCheckBoxInput.java 2011-06-08
09:48:07 UTC (rev 6612)
@@ -19,17 +19,19 @@
package org.exoplatform.webui.form;
+import java.io.Writer;
+
+import org.exoplatform.commons.serialization.api.annotations.Serialized;
import org.exoplatform.webui.application.WebuiRequestContext;
-import org.exoplatform.commons.serialization.api.annotations.Serialized;
-import java.io.Writer;
-
/**
* Represents a checkbox field.
* @param <T> The type of value that is expected
+ * @deprecated use {@link org.exoplatform.webui.form.input.UIFormCheckBoxInput} instead
*/
@SuppressWarnings("hiding")
@Serialized
+@Deprecated
public class UIFormCheckBoxInput<T> extends UIFormInputBase<T>
{
/**
Added:
portal/branches/branch-GTNPORTAL-1921/webui/core/src/main/java/org/exoplatform/webui/form/input/UIFormCheckBoxInput.java
===================================================================
---
portal/branches/branch-GTNPORTAL-1921/webui/core/src/main/java/org/exoplatform/webui/form/input/UIFormCheckBoxInput.java
(rev 0)
+++
portal/branches/branch-GTNPORTAL-1921/webui/core/src/main/java/org/exoplatform/webui/form/input/UIFormCheckBoxInput.java 2011-06-08
09:48:07 UTC (rev 6612)
@@ -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;
+
+/**
+ * @author <a href="mailto:phuong.vu@exoplatform.com">Vu Viet
Phuong</a>
+ * @version $Id$
+ *
+ * <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>
+ */
+@Serialized
+public class UIFormCheckBoxInput 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 UIFormCheckBoxInput()
+ {
+ this(null, null, false);
+ }
+
+ public UIFormCheckBoxInput(String name, String bindingExpression, Boolean value)
+ {
+ super(name, bindingExpression, Boolean.class);
+ setValue(value);
+ }
+
+ public UIFormInput 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 UIFormCheckBoxInput setChecked(boolean check)
+ {
+ return (UIFormCheckBoxInput)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