📄 abstractformaction.java
字号:
// Copyright 2005-2007 onetsoft.com
//
// 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 com.onetsoft.fastjsp;
import com.onetsoft.fastjsp.util.ComboKey;
import com.onetsoft.fastjsp.util.StringUtils;
import com.onetsoft.fastjsp.valid.FieldValidator;
import com.onetsoft.fastjsp.valid.ValidationDelegateImpl;
import com.onetsoft.fastjsp.valid.ValidationException;
/**
* 应用于表单的action
*
* @author <a href="mailto:hgw@onetsoft.com">hgw</a>
*/
public abstract class AbstractFormAction extends AbstractAction {
/**
* 是否忽略表单验证
* 注:此配置不会影响自定义验证方法{@link this#validate()} 的执行
*
* @return
*/
protected boolean isBypassFormFieldValidation() {
return false;
}
final public void execute() {
if (!(cycle.service.data.get(StringUtils.CANCEL_FORM_TAG) != null || isBypassFormFieldValidation())) {
try {
validateForm();
} catch (ValidationException e) {
throw new ApplicationRuntimeException(e);
}
}
try {
validate();
} catch (ValidationException e) {
throw new ApplicationRuntimeException(e);
}
perform();
}
/**
* 验证表单配置的验证
*
* @throws ValidationException
*/
private void validateForm() throws ValidationException {
AbstractForm form = cycle.service.actionsManager.getFormInstance(new ComboKey(cycle.getPage().getData().getInt(LinkImpl.UCI, 0), null), cycle.service.data.getString("form"));
form.setPage(cycle.getPage());
FieldValidator[] a = form.getFieldValidators();
if (a == null) return;
for (int i = 0; i < a.length; i++) {
if (a[i] != null) {
new ValidationDelegateImpl(cycle, form.getFieldValidators()).validate();
break;
}
}
}
/**
* 执行此action
* 若标单验证失败,此方法将不会执行。
* 也可通过 throw new ApplicationRuntimeException(new ValidationException());方式抛出验证错误。
*
* @throws ApplicationRuntimeException
*/
protected abstract void perform();
/**
* 针对每个 action 操作验证
* 在执行{@link this#perform()}前会执行此方法
*
* @throws ValidationException
*/
protected void validate() throws ValidationException {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -