我无法使用JSF在selectOneMenu中获取值。在变量中返回null
我无法在selectOneMenu中获取值,我尝试在web上搜索其他示例,结果类似,但不起作用 让我解释一下……下面您可以找到我的XHTML页面: 然后学习我的Java课程我无法使用JSF在selectOneMenu中获取值。在变量中返回null,jsf,primefaces,xhtml,Jsf,Primefaces,Xhtml,我无法在selectOneMenu中获取值,我尝试在web上搜索其他示例,结果类似,但不起作用 让我解释一下……下面您可以找到我的XHTML页面: 然后学习我的Java课程 /** * The Class SccReportController. */ @Controller @ManagedBean @Scope("view") public class SccReportController { final static private String DIRECTORY = "c:
/**
* 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
André尝试在ajax事件中添加进程=@this 像这样
<p:ajax event="change" process="@this"
update="@this"></p:ajax>
根据Ayhan Arslan的awnser,我将下面的代码放在SelectOne菜单中
<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 />
你好,谢谢你回答我的问题。您是否可以编辑您的问题以更好地解释为什么这可以解决OP的问题,或者可以链接并引用某种文档?这样在将来,当人们遇到同样的问题时,他们也许能够更好地理解并推断出他们问题的解决方案,即使它与这个不完全匹配。事实上,我很久以前就解决了这个问题,所以我不记得doc或link了。但原因是这个问题可能是错误使用的布局或表单。嗨,艾兰,你的代码现在正在工作。谢谢你的帮助。你试过提交表格吗?您希望reportOption什么时候有值?代表@Seraphstryfe:您是否尝试过提交表单?您希望reportOption什么时候有值?
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 />