我在selectOneMenu中获得价值有问题,我尝试在网络上搜索其他示例,它类似但不起作用。
让我解释一下......你可以在下面找到我的XHTML页面:
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
template="/template/template.xhtml">
<ui:define name="content">
<script>
function setUploadFilesCount() {
var i = 0;
var numberOfFiles = $('.ui-fileupload-preview').size();
var input = document.getElementById('fileupload-multi-fix-input');
input.value = numberOfFiles;
input.onchange();
}
</script>
<ui:include src="/sections/crud/scc/sccReport.xhtml"/>
<br />
<br />
<br />
<h:form enctype="multipart/form-data">
<p:growl id="messages" showDetail="true" />
<p:accordionPanel activeIndex="null">
<p:tab title="Allowed Report Types:">
<h:panelGrid columns="1" cellpadding="20">
<h:outputText
value="blablablablablablabla" />
<h:outputText
value="blablablablablablabla" />
<h:outputText
value="blablablablablablabla" />
</h:panelGrid>
</p:tab>
</p:accordionPanel>
<br />
<br />
<h4>1) Select the Report:</h4>
<h:selectOneMenu id="reportOption" value="#{sccReportController.reportOption}" required="true" label="Report Option">
<f:selectItem itemLabel="Select one" itemValue="" noSelectionOption="true" />
<f:selectItem itemLabel="Report 1" itemValue="report1" />
<f:selectItem itemLabel="Report 2" itemValue="report2" />
<f:selectItem itemLabel="Report 3" itemValue="report3" />
</h:selectOneMenu>
<br />
<br />
<h4>2) Select and upload all log files that will be processed:</h4>
<p:fileUpload
fileUploadListener="#{sccReportController.handleFileUpload}"
mode="advanced"
dragDropSupport="false"
multiple="true"
update="messages"
fileLimit="1000"
allowTypes="/(\.|\/)(csv|txt)$/"
onstart="setUploadFilesCount()" />
</h:form>
<h:form prependId="false" style="display:none;">
<h:inputText id="fileupload-multi-fix-input" value="#{sccReportController.numberOfUploadFiles}">
<f:ajax event="change" execute="@form" />
</h:inputText>
</h:form>
</ui:define>
并关注我的Java类
/**
* The Class SccReportController.
*/
@Controller
@ManagedBean
@Scope("view")
public class SccReportController {
final static private String DIRECTORY = "c:\\temp\\";
final static private String DIRECTORY_TEMPORARY = "c:\\temp\\temporary_folder";
private String reportOption;
private int uploadCount = 0;
private int numberOfUploadFiles;
private StreamedContent file;
private ArrayList<File> files = new ArrayList<File> ();
public String getReportOption() {
return reportOption;
}
public void setReportOption(String reportOption) {
this.reportOption = reportOption;
}
public int getNumberOfUploadFiles() {
return numberOfUploadFiles;
}
public void setNumberOfUploadFiles(int numberOfUploadFiles) {
this.numberOfUploadFiles = numberOfUploadFiles;
}
public StreamedContent getFile() {
return file;
}
public void handleFileUpload(FileUploadEvent event) throws IOException {
InputStream input = event.getFile().getInputstream();
OutputStream output = new FileOutputStream(new File(DIRECTORY_TEMPORARY, event.getFile().getFileName()));
try {
IOUtils.copy(input, output);
} finally {
IOUtils.closeQuietly(input);
IOUtils.closeQuietly(output);
}
uploadCount++;
if(uploadCount == numberOfUploadFiles){
File fFolder = new File(DIRECTORY_TEMPORARY);
for(File file: fFolder.listFiles()){
files.add(file);
}
}
}
}
当我调试此代码时,我在String reportOption中没有收到任何值。 reportOption返回null。
你能帮我理解我的代码中的问题吗?
感谢。
ATT;
安德烈
答案 0 :(得分:2)
尝试添加&#34; process = @ this&#34;在ajax事件中 像这样
<p:ajax event="change" process="@this"
update="@this"></p:ajax>
答案 1 :(得分:0)
根据Ayhan Arslan的awnser,我把下面的代码放在selectOneMenu中
<p:ajax event="change" process="@this" update="@this"></p:ajax>
所以,它现在正在工作,我将selectOneMenu代码更改为:
h4>1) Select the Report:</h4>
<h:selectOneMenu id="reportOption" value="#{sccReportController.reportOption}" required="true" label="Report Option">
<f:selectItem itemLabel="Select one" itemValue="" noSelectionOption="true" />
<f:selectItem itemLabel="MGW SCC Report" itemValue="MGWSCC" />
<f:selectItem itemLabel="MSC SCC Report" itemValue="MSCSCC" />
<f:selectItem itemLabel="MSC SCC + VLR Active User + HLR Provisioned Subscribers Report" itemValue="MSCVLR" />
<p:ajax event="change" process="@this" update="@this"> // I added this code line according with Ayhan Arslan anwser</p:ajax>
</h:selectOneMenu>
<br />
<br />