使用 Apache MyFaces JSF 2.0。
XHTML 代码:
<h:form id="searchUser" prependId="false">
<h:selectManyListbox value="#{listManyBean.listUser}" id="userList" size="10">
<f:selectItems value="#{listManyBean.selListUser}"/>
</h:selectManyListbox>
<h:commandButton id="clickGo" value="#{bundle.btn_login}"
type="submit"
action="#{listManyBean.submitList}"/>
<input type="button" value="Add" onclick="addUserToList();" />
</h:form>
添加到列表的脚本:
function addUserToList(){
var UserListBox = document.getElementById('UserList');
var UserNum = document.getElementById('UserNumber').value.toUpperCase();
var UserOption = new Option(UserNum,UserNum);
UserListBox.options[UserListBox.options.length] = UserOption;
}
豆:
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.model.SelectItem;
@ManagedBean
@RequestScoped
public class ListManyBean {
private List<String> listUser;
private List<SelectItem> selListUser;
public List<SelectItem> getSelListUser() {
return selListUser;
}
public List<String> getListUser() {
return listUser;
}
public void setListUser(List<String> listUser) {
this.listUser = listUser;
}
public void submitList() {
System.out.println("User List Value***" + this.listUser);
System.out.println("User ListPan***++"+selListUser);
}
}
无论添加一条或多条记录,我总是得到空值。请让我知道这里出了什么问题。