표현식을 사용하여 목록에 적어도 하나의 객체가 있는지 (비어 있지 않음) 또는 확인란이 true로 선택되었는지 확인하려고합니다. 아무 것도 시도하지 않은 것 같습니다. 내 검증 XML 파일에Struts 2에서 조건을 사용하여리스트의 유효성을 검사하는 방법은 무엇입니까?
나는 해봤 다음 ...
이 목록이 비어 있지 않은 경우에도 오류가 발생, 항상 false를 반환 :
<validator type="fieldexpression">
<param name="fieldname">uploads</param>
<param name="expression">chkAtch eq true or <![CDATA[uploads.length > 0]]></param>
<message key="validation.atch.present" />
</validator>
이 결과 동일한 상술 같이
<param name="expression">chkAtch eq true or uploads not in {null, ""}</param>
,174 :이 않는
<param name="expression">chkAtch eq true or uploads.length > 0</param>
는
이 항상 true를 반환하지만, 모든 필드 오류가있는 경우 오류 메시지가 표시됩니다
<validator type="expression">
<param name="expression">chkAtch eq true or uploads.length > 0</param>
<message key="validation.atch.present" />
</validator>
확실 할 수있는 방법에 어떤 아이디어 중 하나 확인란 (TRUE) 또는 업로드를 체크 목록에 적어도 하나의 객체가 채워져 있습니까?
감사합니다,
편집 :
내 JSP :
<s:file label="File 1" id="file1" name="uploads[0].upload" /> <s:checkbox name="uploads[0].refFile" />
<s:file label="File 2" id="file2" name="uploads[1].upload" /> <s:checkbox name="uploads[1].refFile" />
<!-- omitted - labels and cosmetics -->
<s:checkbox name="chkAtch">
<!-- label -->
</s:checkbox>
편집 2 : 액션 클래스의
관련 조각 :
private Boolean chkAtch;
private List<LinguisticFile> uploads;
public String confirmInput() throws Exception {
if (hasFieldErrors()) {
LOG.debug("[confirmInput] has field errors");
return createInput();
}
// Irrelevant code omitted
ArrayList<AtchObj> atchObj = new ArrayList<AtchObj>();
if (uploads != null) {
for (int i = 0; i < uploads.size(); i++) {
if (uploads.get(i).getUpload() == null)
continue;
AtchObj atchmnt = new AtchObj(uploads.get(i)
.getUploadFileName(),//
uploads.get(i).getUploadContentType(),//
uploads.get(i).getUpload(),//
uploads.get(i).getRefFile()//
);
atchObj.add(atchmnt);
}
}
//Irrelevant code omitted
return "success";
}
// Getters and Setters
public static class LinguisticFile {
private File upload;
private String uploadFileName;
private String uploadContentType;
private Boolean refFile;
public File getUpload() {
return upload;
}
public void setUpload(File file) {
this.upload = file;
}
public String getUploadFileName() {
return uploadFileName;
}
public void setUploadFileName(String fileFileName) {
this.uploadFileName = fileFileName;
}
public String getUploadContentType() {
return uploadContentType;
}
public void setUploadContentType(String fileContentType) {
this.uploadContentType = fileContentType;
}
public Boolean getRefFile() {
return refFile;
}
public void setRefFile(Boolean refFile) {
this.refFile = refFile;
}
}
또 다른 빠른 편집 :
다른 XML 표현식 검사기를 포함하여이 프로젝트에서 다른 모든 기능을 사용할 수 있습니다. 표현식 내에서이 목록을 제대로 참조 할 수없는 것처럼 보입니다.
의 차이는 하나는 필드의 표현이고, 다른 하나는 표현 – Othya