我正在使用动作侦听器事件来点击按钮上传文档。但是当我点击按钮时,它没有进入actionlistener
方法。但是一旦我刷新页面,事件就开始工作了。
我也尝试使用phaseId
调用该事件,但它无效。
如果我能以任何其他方式做到这一点,请告诉我。
我的xhtml
:
<ace:fileEntry id="fileEntryForDocUpld" disabled="#{triggerRequestFormBean.disableDocUpload}"
absolutePath="#{triggerRequestFormBean.uploadDirectory}"
maxFileCount="10"
maxFileCountMessage="Limited to 10 files uploaded concurrantly."
fileEntryListener="#{triggerRequestFormBean.uploadDocumentListener}"
required="false" useOriginalFilename="true"
useSessionSubdir="true" immediate="true" >
</ace:fileEntry>
<h:commandButton id="upldDoc"
disabled="#{triggerRequestFormBean.disableDocUpload}"
actionListener="#{triggerRequestFormBean.docUploadListener}"
partialSubmit ="true"
value="Load" styleClass="buttonStyle"
title="Load" >
</h:commandButton>
**java class -**
public void uploadDocumentListener(final FileEntryEvent event) {
if (logger.isInfoEnabled()) {
logger.info(LOG_METHOD_ENTER);
}
if (event.getPhaseId() == PhaseId.ANY_PHASE) {
event.setPhaseId(PhaseId.INVOKE_APPLICATION);
event.queue();
}
getBaseBean().getErrorMessagesList().clear();
try {
setFile(FileUploadUtility.fileEntryUploadListener(event));
if (getFile() != null) {
String fileNameWithExtension = getFile().getName();
int endIndex = fileNameWithExtension.lastIndexOf(ConstantKeys.DOT);
String uploadedDocFormat = fileNameWithExtension.substring(
endIndex + 1, fileNameWithExtension.length()).toLowerCase();
String docFormats = factory.getMessage(ConfigKeys.EDM_SUPPORTING_FILE_FORMAT);
List<String> supportedFormatList = Arrays.asList(docFormats.split("\\s*,\\s*"));
if(!supportedFormatList.contains(uploadedDocFormat)){
getBaseBean().getErrorMessagesList().add(
messageFactory.getMessage(ERROR_SELECT_VALID_FILE_FORMAT));
} else {
setDocLocation(getFile().getName());
setPercentDoc(100);
final TriggerRequestDocumentDataBean docBean = new TriggerRequestDocumentDataBean();
docBean.setTrgrRqstDocNm(appendTimestampToFile(getFile()
.getName()));
//Throw Error incase if the document name is greater than 60 after appending timestamp
if(docBean.getTrgrRqstDocNm()!=null && docBean.getTrgrRqstDocNm().length()>60){
getBaseBean().getErrorMessagesList().add(
messageFactory.getMessage(ERROR_PLEASE_SELECT_FILE_NAME_BELOW_60CHAR));
return;
}
docBean.setTrgrRqstAttach(FileUploadUtility
.readFileAsBytes(getFile()));
final CommonBO commonBO = (CommonBO) FacesUtils
.findBean(COMMON_BO);
final Date currentDt = commonBO.getSysdate();
docBean.setCreatedByEmpNbr(getLoginUserIdAsLong());
docBean.setCreatedDt(currentDt);
docBean.setLastUpdtByEmpNbr(getLoginUserIdAsLong());
final Employee employee = commonBO
.populateEmployeeDetails(getLoginUserIdAsString());
if (employee != null) {
final StringBuilder sbEmpName = new StringBuilder(employee
.getFirstNm()).append(SPACE).append(
employee.getLastNm());
docBean.setLastUpdtBy(sbEmpName.toString());
}
docBean.setLastUpdtDt(currentDt);
docBean.setNewRecord(true);
if (CommonUtil.isListNotEmpty(getTrfDocList())) {
getTrfDocList().add(0, docBean);
} else {
getTrfDocList().add(docBean);
}
}
}
} catch (final Exception e) {
logger.error(e.getMessage(), e);
} finally {
}
if (logger.isInfoEnabled()) {
logger.info(LOG_METHOD_EXIT);
}
}
/**
* This method will be invoke on click of File Upload button from UI
*/
public String docUploadListener(ActionEvent event) {
if (event.getPhaseId() == PhaseId.ANY_PHASE) {
event.setPhaseId(PhaseId.INVOKE_APPLICATION);
event.queue();
}
if (logger.isInfoEnabled()) {
logger.info(LOG_METHOD_ENTER);
}
try {
if (getFile() == null) {
getBaseBean().getErrorMessagesList().add(
messageFactory.getMessage(ERROR_PLEASE_UPLD_DOC));
}
} catch (final Exception e) {
logger.error(e.getMessage(), e);
} finally {
}
if (logger.isInfoEnabled()) {
logger.info(LOG_METHOD_EXIT);
}
/*JavascriptContext.addJavascriptCall(FacesContext
.getCurrentInstance(), "window.location.reload();");*/
return null;
}