提交 808d3443 编写于 作者: F fheremans

Added double form type support

上级 ddb6398d
......@@ -114,6 +114,7 @@ import org.activiti.engine.impl.event.MessageEventHandler;
import org.activiti.engine.impl.event.SignalEventHandler;
import org.activiti.engine.impl.form.BooleanFormType;
import org.activiti.engine.impl.form.DateFormType;
import org.activiti.engine.impl.form.DoubleFormType;
import org.activiti.engine.impl.form.FormEngine;
import org.activiti.engine.impl.form.FormTypes;
import org.activiti.engine.impl.form.JuelFormEngine;
......@@ -1135,6 +1136,7 @@ public abstract class ProcessEngineConfigurationImpl extends ProcessEngineConfig
formTypes.addFormType(new LongFormType());
formTypes.addFormType(new DateFormType("dd/MM/yyyy"));
formTypes.addFormType(new BooleanFormType());
formTypes.addFormType(new DoubleFormType());
}
if (customFormTypes!=null) {
for (AbstractFormType customFormType: customFormTypes) {
......
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.impl.form;
import org.activiti.engine.form.AbstractFormType;
/**
* @author Tom Baeyens
*/
public class DoubleFormType extends AbstractFormType {
public String getName() {
return "long";
}
public String getMimeType() {
return "plain/text";
}
public Object convertFormValueToModelValue(String propertyValue) {
if (propertyValue==null || "".equals(propertyValue)) {
return null;
}
return new Long(propertyValue);
}
public String convertModelValueToFormValue(Object modelValue) {
if (modelValue==null) {
return null;
}
return modelValue.toString();
}
}
......@@ -23,7 +23,7 @@ import org.activiti.engine.form.AbstractFormType;
public class LongFormType extends AbstractFormType {
public String getName() {
return "long";
return "double";
}
public String getMimeType() {
......@@ -34,7 +34,7 @@ public class LongFormType extends AbstractFormType {
if (propertyValue==null || "".equals(propertyValue)) {
return null;
}
return new Long(propertyValue);
return new Double(propertyValue);
}
public String convertModelValueToFormValue(Object modelValue) {
......
......@@ -168,6 +168,7 @@ public class FormServiceTest extends PluggableActivitiTestCase {
properties.put("speaker", "Mike"); // variable name mapping
properties.put("duration", "45"); // type conversion
properties.put("free", "true"); // type conversion
properties.put("double", "45.5"); // type conversion
String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
String processInstanceId = formService.submitStartFormData(procDefId, properties).getId();
......@@ -177,6 +178,7 @@ public class FormServiceTest extends PluggableActivitiTestCase {
expectedVariables.put("SpeakerName", "Mike");
expectedVariables.put("duration", new Long(45));
expectedVariables.put("free", Boolean.TRUE);
expectedVariables.put("double", 45.5d);
Map<String, Object> variables = runtimeService.getVariables(processInstanceId);
assertEquals(expectedVariables, variables);
......@@ -210,8 +212,12 @@ public class FormServiceTest extends PluggableActivitiTestCase {
FormProperty propertyFree = formProperties.get(4);
assertEquals("free", propertyFree.getId());
assertEquals("true", propertyFree.getValue());
FormProperty propertyDouble = formProperties.get(5);
assertEquals("double", propertyDouble.getId());
assertEquals("45.5", propertyDouble.getValue());
assertEquals(5, formProperties.size());
assertEquals(6, formProperties.size());
try {
formService.submitTaskFormData(taskId, new HashMap<String, String>());
......@@ -238,6 +244,7 @@ public class FormServiceTest extends PluggableActivitiTestCase {
expectedVariables.put("SpeakerName", "Mike");
expectedVariables.put("duration", new Long(45));
expectedVariables.put("free", Boolean.TRUE);
expectedVariables.put("double", 45.5d);
variables = runtimeService.getVariables(processInstanceId);
address = (Address) variables.remove("address");
......
......@@ -12,6 +12,7 @@
<activiti:formProperty id="speaker" variable="SpeakerName"/>
<activiti:formProperty id="duration" type="long"/>
<activiti:formProperty id="free" type="boolean" />
<activiti:formProperty id="double" type="double" />
</extensionElements>
</startEvent>
......@@ -29,6 +30,7 @@
<activiti:formProperty id="speaker" variable="SpeakerName" writable="false" />
<activiti:formProperty id="street" expression="#{address.street}" required="true" />
<activiti:formProperty id="free" type="boolean"/>
<activiti:formProperty id="double" type="double"/>
</extensionElements>
</userTask>
......
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.explorer.ui.form;
import org.activiti.engine.form.FormProperty;
import org.activiti.engine.impl.form.DoubleFormType;
import org.activiti.explorer.Messages;
import org.activiti.explorer.ui.validator.DoubleValidator;
import com.vaadin.ui.Field;
import com.vaadin.ui.TextField;
/**
* @author Frederik Heremans
*/
public class DoubleFormPropertyRenderer extends AbstractFormPropertyRenderer {
public DoubleFormPropertyRenderer() {
super(DoubleFormType.class);
}
@Override
public Field getPropertyField(FormProperty formProperty) {
final TextField textField = new TextField(getPropertyLabel(formProperty));
textField.setRequired(formProperty.isRequired());
textField.setEnabled(formProperty.isWritable());
textField.setRequiredError(getMessage(Messages.FORM_FIELD_REQUIRED, getPropertyLabel(formProperty)));
if (formProperty.getValue() != null) {
textField.setValue(formProperty.getValue());
}
// Add validation of numeric value
textField.addValidator(new DoubleValidator("Value must be a double"));
textField.setImmediate(true);
return textField;
}
protected boolean isLong(String value) {
try {
Double.parseDouble(value);
return true;
} catch (NumberFormatException nfe) {
return false;
}
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.explorer.ui.validator;
import com.vaadin.data.validator.AbstractStringValidator;
/**
* @author Frederik Heremans
*/
public class DoubleValidator extends AbstractStringValidator {
private static final long serialVersionUID = 8306001395582004472L;
public DoubleValidator(String errorMessage) {
super(errorMessage);
}
@Override
protected boolean isValidString(String value) {
try {
Double.parseDouble(value);
return true;
} catch (Exception e) {
return false;
}
}
}
......@@ -34,6 +34,7 @@
<bean class="org.activiti.explorer.ui.form.StringFormPropertyRenderer" />
<bean class="org.activiti.explorer.ui.form.EnumFormPropertyRenderer" />
<bean class="org.activiti.explorer.ui.form.LongFormPropertyRenderer" />
<bean class="org.activiti.explorer.ui.form.DoubleFormPropertyRenderer" />
<bean class="org.activiti.explorer.ui.form.DateFormPropertyRenderer" />
<bean class="org.activiti.explorer.ui.form.UserFormPropertyRenderer" />
<bean class="org.activiti.explorer.ui.form.BooleanFormPropertyRenderer" />
......
......@@ -37,7 +37,7 @@
<configuration>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8081</port>
<port>8080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
......
......@@ -8113,19 +8113,19 @@ Only the attachment name is required to create a new attachment.
<entry>Return only historic task instances that haveno due-date. When <literal>false</literal> is provided as value, this parameter is ignored.</entry>
</row>
<row>
<entry>completedOn</entry>
<entry>taskCompletedOn</entry>
<entry>No</entry>
<entry>Date</entry>
<entry>Return only historic task instances that have been completed on this date.</entry>
</row>
<row>
<entry>completedAfter</entry>
<entry>taskCompletedAfter</entry>
<entry>No</entry>
<entry>Date</entry>
<entry>Return only historic task instances that have been completed after this date.</entry>
</row>
<row>
<entry>completedBefore</entry>
<entry>taskCompletedBefore</entry>
<entry>No</entry>
<entry>Date</entry>
<entry>Return only historic task instances that have been completed before this date.</entry>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册