私はStruts2-Bootstrap-Pluginバージョン2.0.4をクライアント検証に使用しています。私は私の検証関数としてbootstrapValidationを使用しています。私はstrutsアクションにjsonValidationWorkflowStackを追加しました。ほとんどの場合、これは予期したとおりに機能し、フォームデータをサーバーに送信し、サーバーの検証を実際に完全なポストを実行することなく実行します。ただし、ファイルに対しては機能しません。ページにs:ファイルがある場合、それは無視されるようです。検証メソッドが実行されると、常にnullになります。プラグインのクライアント検証をバイパスすると、ファイルは正しく送信され、検証されます。ファイルが機能しないのは何ですか?ありがとう。Struts2 Bootstrap Pluginクライアント検証ファイル
マイStruts.xml
<action name="testValidateSave" class="webapp.action.TestValidationAction" method="save" >
<interceptor-ref name="jsonValidationWorkflowStack"/>
<result name="success">/WEB-INF/pages/testValidate.jsp</result>
<result name="error">/WEB-INF/pages/testValidate.jsp</result>
<result name="input">/WEB-INF/pages/testValidate.jsp</result>
</action>
私のJSPページ
<s:form id="testValidationForm" theme="bootstrap" method="post" labelCssClass="col-sm-2 text-semibold" elementCssClass="col-sm-10"
cssClass="form-horizontal" action="testValidateSave" enctype="multipart/form-data">
<div class="panel panel-flat">
<div class="panel-heading">
<h5 class="panel-title text-bold">Testing Client Validation</h5>
<div class="heading-elements">
<sj:submit button="true"
name = "Save"
type="button"
id="saveButton"
formIds="testValidationForm"
targets="bodySection"
iframe="true"
dataType="html"
validate="true"
validateFunction="bootstrapValidation"
cssClass="btn bg-cobalt-400 mr-5 pull-right"
buttonIcon="icon-floppy-disk"
label="Save"
value="Save"
/>
</div>
</div>
<div id="bodySection" class="panel-body">
<s:textfield
id="testText"
name="testText"
label="Test Text"
/>
<s:file
id="testDoc"
label="Test Doc"
name="testDoc"/>
</div>
</div>
</s:form>
そして、私のアクションクラス:
public class TestValidationAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private String testText;
private File testDoc;
private String testDocContentType;
private String testDocFileName;
/*****************************************************************
* Action Methods
*****************************************************************/
@SkipValidation
public String execute() {
return SUCCESS;
}
public String save() {
return SUCCESS;
}
public void validate() {
super.validate();
System.out.println(" testText = " + this.testText);
System.out.println(" testDoc = " + this.testDoc);
if (this.testText == null || this.testText.isEmpty()) {
addFieldError("testText", "Required");
}
if (this.testDoc == null) {
addFieldError("testDoc", "Required");
}
}
/*****************************************************************
* Getters and Setters
*****************************************************************/
public String getTestText() {
return this.testText;
}
public void setTestText(String testText) {
this.testText = testText;
}
public File getTestDoc() {
return this.testDoc;
}
public void setTestDoc(File testDoc) {
this.testDoc= testDoc;
}
public String getTestDocFileName() {
return this.testDocFileName;
}
public void setTestDocFileName(String testDocFileName) {
this.testDocFileName= testDocFileName;
}
public String getTestDocContentType() {
return this.testDocContentType;
}
public void setTestDocContentType(String testDocContentType) {
this.testDocContentType= testDocContentType;
}
}