我对这个博客比较陌生,但在提出问题之前已做过一些研究。我是网络应用程序开发的新手。我使用的是JSF 2.2,jdk 1.7,oracle 11g,富脸,GlassFish 4.0和netbeans 7.3.1。我正在尝试从rich:pickList
中选择项目并将其添加到目标列表中。单击提交按钮时,应执行与所选项对应的方法。以下是我到目前为止所做的一瞥:
JSF PAGE:
<table width="240" height="235" align="center">
<tr height="30">
<td width="20" height="30" align="LEFT">
<td width="20" height="30" align="LEFT">
<rich:pickList listHeight="225" listWidth="145" value="# {usermanager.selectedOption}" id="message" required="true" >
<f:selectItems value="#{usermanager.selectedValue}" />
</rich:pickList>
<h:message for="message" style="color:red" ></h:message>
</td>
</tr>
</table>
<br/>
<table width="240" height="30" align="center">
<tr height="30" align="center" >
<td width="60" height="30" align="center" >
<h:commandButton value="Submit" action="#{usermanager.submit()}" >
</h:commandButton>
</td>
<td width="100" align="center">Export to Excel
<h:commandButton image="Excel.png" action="#{usermanager.resultTicker()}" value="" />
</td>
</tr>
</table>
以下是Backing Bean的相关部分:(@Named(value = "usermanager")@SessionScoped)
private static Map<String,Object> loadValue;
static{
loadValue = new LinkedHashMap<String,Object>();
loadValue.put("IR: Cap Vol", "1"); //label, value
loadValue.put("IR: Swaptions Vol", "2");
loadValue.put("IR: Interest Rate", "3");
loadValue.put("FX: Cap Vol", "4");
loadValue.put("FX: Swaptions Vol", "5");
loadValue.put("FX: Interest Rate","6");
loadValue.put("Commodities: Cap Vol", "7");
loadValue.put("Commodities: Swaptions Vol", "8");
loadValue.put("Commodities: Interest Rate", "9");
}
private String[] selectedOption={"IR: Cap Vol","IR: Swaptions Vol","IR: Interest Rate","FX: Cap Vol","FX: Swaptions Vol","FX: Interest Rate","Commodities: Cap Vol","Commodities: Swaptions Vol","Commodities: Interest Rate"};
public String[] getSelectedOption() {
return selectedOption;
}
public void setSelectedOption(String[] selectedOption) {
this.selectedOption = selectedOption;
}
public Map<String,Object> getSelectedValue() throws SQLException, FileNotFoundException, IOException, Exception {
switch(getSelectedOption()[0])
{
case "1":
{
loadIRCapVol();
break;
}
case "2":
{
loadIRSwaptionVol();
break;
}
case "3":
{
loadIRInterestRate();
break;
}
case "4":
{
//method
break;
}
......upto case "9":
}
return loadValue;
}
//This method corresponds to list item "IR:Cap Vol"
public void loadIRCapVol() {
//JDBC connection which is executed and tables are populated in the DB from CSV file. I have used FileReader, BufferedReader and executeUpdate here.
}
//This method corresponds to list item "IR:Swaption Vol"
public void loadIRSwaptionVol() {
//JDBC connection which is executed and tables are populated in the DB from CSV file. I have used FileReader, BufferedReader and executeUpdate here.
}
//This method corresponds to list item "IR:Interest Rate"
public void loadIRInterestRate() throws SQLException,FileNotFoundException, IOException, Exception {
//JDBC connection which is executed and tables are populated in the DB from CSV file. I have used FileReader, BufferedReader and executeUpdate here.
}
......similar methods for the remaining 6 items
public String submit() throws SQLException, FileNotFoundException,IOException, Exception{
return "Explore";
}
摘要是用户从列表中选择项目(“IR:Cap Vol”,“IR:Swaptions Vol等”)并添加到目标列表(右侧列表),并在单击提交按钮时对应的方法到选定的列表项目被执行。
代码已经存在许多缺陷。我已经在Switch-Case中硬编码了getSelectedOption值(这应该是动态的,但由于编程经验有限,还没有想出这样做的方法)。我在此处使用Linked Hash-Map通过查阅此博客添加列表项:http://www.mkyong.com/jsf2/jsf-2-multiple-select-listbox-example/
我怀疑交换机案件将来会起作用,因为我用它来将代码显示为高级管理层的工作原型。
伙计们,如果有人能帮助我,我会感谢这个博客社区。 p>