?? 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 + -