Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 基于selectOneMenu值更新JSF数据表_Java_Jsf - Fatal编程技术网

Java 基于selectOneMenu值更新JSF数据表

Java 基于selectOneMenu值更新JSF数据表,java,jsf,Java,Jsf,我试图创建一个JSF页面,用户在其中选择两个selectOneMenu组件中的值。然后,这些选择中的值将传递给SQL查询,以更新页面上显示的表 我已经将每个选择项绑定到支持bean中的适当变量,但是在更改selectOneMenu中选择的值之后,支持bean中的绑定属性没有更改,并且执行查询但不返回任何结果。(另一方面,当页面最初显示时,getter似乎也被调用了两次) 我不能将任何其他第三方组件(如RichFaces等)用于此实现 任何对此的洞察都将不胜感激 代码如下: notes.jsp &

我试图创建一个JSF页面,用户在其中选择两个selectOneMenu组件中的值。然后,这些选择中的值将传递给SQL查询,以更新页面上显示的表

我已经将每个选择项绑定到支持bean中的适当变量,但是在更改selectOneMenu中选择的值之后,支持bean中的绑定属性没有更改,并且执行查询但不返回任何结果。(另一方面,当页面最初显示时,getter似乎也被调用了两次)

我不能将任何其他第三方组件(如RichFaces等)用于此实现

任何对此的洞察都将不胜感激

代码如下:

notes.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
      <title></title>
 </head>
<body>

<f:view>

<h:form id="notelistform">
    <f:subview id="loginbar">
        <jsp:include page="/jsp/loginbar.jsp" />
    </f:subview>

    <h:outputText value="Worktype:" />
    <h:selectOneMenu value="#{pc_noteListBacker.worktype}"
        title="worktype" id="worktypeList" onchange="submit()">
        <f:selectItems value="#{pc_noteListBacker.selectWorktypes}" />
        <f:valueChangeListener
            type="<package>.web.backer.note.NoteListBacker" />

    </h:selectOneMenu>

    <h:outputText value="Product:" />
    <h:selectOneMenu value="#{pc_noteListBacker.product}" title="product"
        id="productList" onchange="submit()">
        <f:selectItems value="#{pc_noteListBacker.selectProducts}" />
        <f:valueChangeListener
            type="<package>.web.backer.note.NoteListBacker" />
    </h:selectOneMenu>


    <h:dataTable id="notelisttable" value="#{pc_noteListBacker.noteList}"
        var="item" bgcolor="#F1F1F1" border="10" cellpadding="5"
        cellspacing="3" first="0" width="80%" dir="LTR" frame="hsides"
        rules="all" summary="Status and notes note table display."
        binding="#{pc_noteListBacker.noteListTable}">


        <h:column>
            <f:facet name="header">
                <h:outputText value="Note ID" />
            </f:facet>
            <h:outputText value="#{item.noteId}"></h:outputText>
        </h:column>


        <h:column>
            <f:facet name="header">
                <h:outputText value="Note Category" />
            </f:facet>
            <h:outputText value="#{item.noteCategory}"></h:outputText>
            <f:facet name="footer">
                <h:commandButton value="Add" action="#{pc_noteListBacker.insert}">
                </h:commandButton>
            </f:facet>
        </h:column>

        <h:column>
            <f:facet name="header">
                <h:outputText value="Note Subcategory" />
            </f:facet>
            <h:outputText value="#{item.noteSubCategory}"></h:outputText>
        </h:column>


        <h:column>
            <f:facet name="header">
                <h:outputText value="Note" />
            </f:facet>
            <h:outputText value="#{item.note}"></h:outputText>
        </h:column>



        <h:column>
            <h:commandButton value="Edit" action="#{pc_noteListBacker.edit}">
            </h:commandButton>
        </h:column>
        <h:column>
            <h:commandButton value="Delete" action="#{pc_noteListBacker.delete}"></h:commandButton>
        </h:column>
    </h:dataTable>

</h:form>

NoteListBacker.java

 package <package>.web.backer.note;

 import java.util.List;
 import java.util.ArrayList;

 import javax.faces.component.UIComponent;
 import javax.faces.component.UIComponentBase;
 import javax.faces.component.UIData;
 import javax.faces.context.FacesContext;
 import javax.faces.event.AbortProcessingException;
 import javax.faces.event.ValueChangeEvent;
 import javax.faces.event.ValueChangeListener;
 import javax.faces.model.ListDataModel;
 import javax.faces.model.SelectItem;
 import javax.swing.JOptionPane;


 public class NoteListBacker implements ValueChangeListener {

private UIData noteListTable;

private Note note;

private NoteCategory noteCategory;

private NoteSubCategory noteSubCategory;

private NoteDao nDao;

private SybaseSqlDao sybaseDao;

private List<Note> noteList;

private List<SelectItem> selectWorktypes;

private List<SelectItem> selectProducts;

private String worktype;

private List<String> worktypeList;

private String product;

private List<Product> productList;

private int noteId;

public NoteListBacker() {

    nDao = new NoteDao();
    sybaseDao = new SybaseSqlDao();
    selectWorktypes = new ArrayList<SelectItem>();
    selectProducts = new ArrayList<SelectItem>();
    noteList = new ArrayList<Note>();
    note = new Note();
    worktypeList = new ArrayList<String>();
    productList = new ArrayList<Product>();
}

public String insert() {
    return "success";
}

public String save() {
    return "notes";
}

public String edit() {
    return "success";
}

public String update() {
    return "notes";
}

public String delete() {
    Note delNote = (Note) noteListTable.getRowData();
    nDao.deleteNote(delNote);
    return "notes";
}

public String cancel() {
    return "notes";
}

public Note getNote() {
    return note;
}

public void setNote(Note note) {
    this.note = note;
}

public NoteDao getNDao() {
    return nDao;
}

public UIData getNoteListTable() {
    return noteListTable;
}

public void setNoteListTable(UIData noteListTable) {
    this.noteListTable = noteListTable;
}

public List<Note> getNoteList() {


    noteList = nDao.selectNotes(worktype, product); //
    return noteList;
}

public void setNoteList(List<Note> noteList) {
    this.noteList = noteList;
}

public void setNDao(NoteDao dao) {
    nDao = dao;
}

public String getProduct() {
    return product;
}

public void setProduct(String product) {
    this.product = product;
}

public String getWorktype() {
    return worktype;
}

public void setWorktype(String worktype) {
    this.worktype = worktype;
}

public NoteCategory getNoteCategory() {
    return noteCategory;
}

public void setNoteCategory(NoteCategory noteCategory) {
    this.noteCategory = noteCategory;
}

public NoteSubCategory getNoteSubCategory() {
    return noteSubCategory;
}

public void setNoteSubCategory(NoteSubCategory noteSubCategory) {
    this.noteSubCategory = noteSubCategory;
}

public int getNoteId() {
    return noteId;
}

public void setNoteId(int noteId) {
    this.noteId = noteId;
}

public SybaseSqlDao getSybaseDao() {
    return sybaseDao;
}

public void setSybaseDao(SybaseSqlDao sybaseDao) {
    this.sybaseDao = sybaseDao;
}

public List<SelectItem> getSelectWorktypes() {
    selectWorktypes.clear();

    worktypeList = this.getWorktypeList();

    for (String strt : worktypeList) {

        SelectItem si = new SelectItem();
        si.setValue(strt);
        si.setLabel(strt);
        si.setDescription(strt);
        selectWorktypes.add(si);
    }

    return selectWorktypes;
}

public void setSelectWorktypes(List<SelectItem> selectWorktypes) {

    this.selectWorktypes = selectWorktypes;
}

public List<String> getWorktypeList() {

    worktypeList = sybaseDao.selectWorktypes();
    return worktypeList;
}

public void setWorktypeList(List<String> worktypeList) {
    this.worktypeList = worktypeList;
}

public List<Product> getProductList() {

    productList = sybaseDao.selectProducts();
    return productList;
}

public void setProductList(List<Product> productList) {
    this.productList = productList;
}

public List<SelectItem> getSelectProducts() {
    selectProducts.clear();

    productList = this.getProductList();

    for (Product prod : productList) {

        SelectItem si = new SelectItem();
        si.setValue(prod);
        si.setLabel(prod.toString());
        si.setDescription(prod.toString());
        selectProducts.add(si);
    }

    return selectProducts;
}

public void setSelectProducts(List<SelectItem> selectProducts) {
    this.selectProducts = selectProducts;
}

public void processValueChange(ValueChangeEvent arg0) {

    if (arg0.getComponent().getId().equalsIgnoreCase("productList")) {
        this.setProduct(arg0.getNewValue().toString());

    }
    if (arg0.getComponent().getId().equalsIgnoreCase("worktypeList")) {
        this.setWorktype(arg0.getNewValue().toString());
    }

}

 }
package.web.backer.note;
导入java.util.List;
导入java.util.ArrayList;
导入javax.faces.component.UIComponent;
导入javax.faces.component.UIComponentBase;
导入javax.faces.component.UIData;
导入javax.faces.context.FacesContext;
导入javax.faces.event.AbortProcessingException;
导入javax.faces.event.ValueChangeEvent;
导入javax.faces.event.ValueChangeListener;
导入javax.faces.model.ListDataModel;
导入javax.faces.model.SelectItem;
导入javax.swing.JOptionPane;
公共类NoteListBacker实现ValueChangeListener{
私有UIData noteListTable;
私人票据;
私人票据类别;
私人票据子类别票据子类别;
私人债券;
私有SybaseSqlDao-sybaseDao;
私人名单;
私有列表选择工作类型;
私人产品清单;
私有字符串工作类型;
私有列表工作类型列表;
私有字符串产品;
私有列表产品列表;
私有int-noteId;
公共NoteListBacker(){
nDao=新的NoteDao();
sybaseDao=新的SybaseSqlDao();
selectWorktypes=new ArrayList();
selectProducts=newarraylist();
noteList=新的ArrayList();
注释=新注释();
worktypeList=新的ArrayList();
productList=新的ArrayList();
}
公共字符串插入(){
返回“成功”;
}
公共字符串保存(){
返回“注释”;
}
公共字符串编辑(){
返回“成功”;
}
公共字符串更新(){
返回“注释”;
}
公共字符串删除(){
Note delNote=(Note)noteListTable.getRowData();
nDao.删除注释(删除注释);
返回“注释”;
}
公共字符串取消(){
返回“注释”;
}
公共注释getNote(){
退货单;
}
公共无效设置注释(注释){
this.note=注释;
}
公共注释dao getNDao(){
返回nDao;
}
公共UIData getNoteListTable(){
返回noteListTable;
}
公共void setNoteListTable(UIData noteListTable){
this.noteListTable=noteListTable;
}
公共列表getNoteList(){
noteList=nDao。选择Notes(工作类型、产品)//
返回注释列表;
}
公共无效集合注释列表(列表注释列表){
this.noteList=noteList;
}
公共无效setNDao(NoteDao-dao){
nDao=dao;
}
公共字符串getProduct(){
退货产品;
}
公共产品(字符串产品){
本产品=产品;
}
公共字符串getWorktype(){
返回工作类型;
}
公共void setWorktype(字符串工作类型){
this.worktype=工作类型;
}
公共NoteCategory getNoteCategory(){
返回票据类别;
}
公共void setNoteCategory(NoteCategory NoteCategory){
this.notecegory=notecegory;
}
public NoteSubCategory getNoteSubCategory(){
返回注释子类别;
}
public void setNoteSubCategory(NoteSubCategory NoteSubCategory){
this.noteSubCategory=noteSubCategory;
}
public int getNoteId(){
返回noteId;
}
公共void setNoteId(int noteId){
this.noteId=noteId;
}
公共SybaseSqlDao getSybaseDao(){
返回sybaseDao;
}
public void setSybaseDao(SybaseSqlDao sybaseDao){
this.sybaseDao=sybaseDao;
}
公共列表getSelectWorktypes(){
选择worktypes.clear();
worktypeList=this.getWorktypeList();
for(字符串strt:worktypeList){
SelectItem si=新建SelectItem();
si.设定值(strt);
si.setLabel(strt);
si.setDescription(strt);
选择工作类型。添加(si);
}
返回选择的工作类型;
}
public void setSelectWorktypes(列出selectWorktypes){
this.selectWorktypes=selectWorktypes;
}
公共列表getWorktypeList(){
worktypeList=sybaseDao.selectWorktypes();
返回工作类型列表;
}
public void setWorktypeList(List worktypeList){
this.worktypeList=工作类型列表;
}
公共列表getProductList(){
productList=sybaseDao.selectProducts();
返回产品列表;
}
公共无效集合产品列表(列表产品列表){
this.productList=productList;
}
公共列表getSelectProducts(){
选择products.clear();
productList=this.getProductList();
对于(产品产品:productList){
SelectItem si=新建SelectItem();
si.设定值(产品);
si.setLabel(prod.toString());
si.setDescription(prod.toString());
选择产品。添加(si);
}
退货产品;
}
公共无效设置选择产品(列出选择产品){
this.selectProducts=selectProducts;
}
public void进程ValueChange(ValueChangeEvent arg0){
if(arg0.getComponent().getId().equalsIgnoreCase(“产品列表”)){
this.setProduct(arg0.getNewValue().toString());
}
if(arg0.getComponent().getId().equalsIgnoreCase(“工作类型列表”)){
这是塞特沃基
 <?xml version="1.0"?>

 <!DOCTYPE faces-config PUBLIC
   "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
   "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">

 <faces-config>

<lifecycle>
    <phase-listener>
        <package>.utils.NoCachePhaseListener
    </phase-listener>
</lifecycle>

<managed-bean>
    <managed-bean-name>pc_userBacker</managed-bean-name>
    <managed-bean-class>
        <package>.web.backer.UserBacker
    </managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
</managed-bean>

<managed-bean>
    <managed-bean-name>pc_noteCategoryListBacker</managed-bean-name>
    <managed-bean-class>
        <package>.web.backer.note.NoteCategoryListBacker
    </managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>

<managed-bean>
    <managed-bean-name>
        pc_noteSubCategoryListBacker
    </managed-bean-name>
    <managed-bean-class>
        <package>.web.backer.note.NoteSubCategoryListBacker
    </managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>

<managed-bean>
    <managed-bean-name>pc_noteListBacker</managed-bean-name>
    <managed-bean-class>
        <package>.web.backer.note.NoteListBacker
    </managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
</managed-bean>

<managed-bean>
    <managed-bean-name>pc_statusListBacker</managed-bean-name>
    <managed-bean-class>
        <package>.web.backer.status.StatusListBacker
    </managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>

<managed-bean>
    <managed-bean-name>pc_statusReasonBacker</managed-bean-name>
    <managed-bean-class>
        <package>.web.backer.status.StatusReasonBacker
    </managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>


<!-- Notes -->
<navigation-rule>
    <from-view-id>/jsp/notes/notes.jsp</from-view-id>
    <navigation-case>
        <from-action>#{pc_noteListBacker.edit}</from-action>
        <from-outcome>success</from-outcome>
        <to-view-id>/jsp/notes/noteedit.jsp</to-view-id>
    </navigation-case>
    <navigation-case>
        <from-action>#{pc_noteListBacker.insert}</from-action>
        <from-outcome>success</from-outcome>
        <to-view-id>/jsp/notes/notenew.jsp</to-view-id>
    </navigation-case>


</navigation-rule>


<!-- Note Categories -->
<navigation-rule>
    <from-view-id>/jsp/notes/notecategories.jsp</from-view-id>
    <navigation-case>
        <from-action>#{pc_noteCategoryListBacker.edit}</from-action>
        <from-outcome>success</from-outcome>
        <to-view-id>/jsp/notes/notecategoryedit.jsp</to-view-id>
    </navigation-case>
    <navigation-case>
        <from-action>
            #{pc_noteCategoryListBacker.insert}
        </from-action>
        <from-outcome>success</from-outcome>
        <to-view-id>/jsp/notes/notecategorynew.jsp</to-view-id>
    </navigation-case>


</navigation-rule>

<!-- Note Subcategories -->
<navigation-rule>
    <from-view-id>/jsp/notes/notesubcategories.jsp</from-view-id>
    <navigation-case>
        <from-action>
            #{pc_noteSubCategoryListBacker.edit}
        </from-action>
        <from-outcome>success</from-outcome>
        <to-view-id>/jsp/notes/notesubcategoryedit.jsp</to-view-id>
    </navigation-case>
    <navigation-case>
        <from-action>
            #{pc_noteSubCategoryListBacker.insert}
        </from-action>
        <from-outcome>success</from-outcome>
        <to-view-id>/jsp/notes/notesubcategorynew.jsp</to-view-id>
    </navigation-case>
</navigation-rule>

<!-- Statuses -->
<navigation-rule>
    <from-view-id>/jsp/statuses/statuses.jsp</from-view-id>
    <navigation-case>
        <from-action>#{pc_statusListBacker.edit}</from-action>
        <from-outcome>success</from-outcome>
        <to-view-id>/jsp/statuses/statusedit.jsp</to-view-id>
    </navigation-case>
    <navigation-case>
        <from-action>#{pc_statusListBacker.insert}</from-action>
        <from-outcome>success</from-outcome>
        <to-view-id>/jsp/statuses/statusnew.jsp</to-view-id>
    </navigation-case>
</navigation-rule>

<!-- Status Reasons -->
<navigation-rule>
    <from-view-id>/jsp/statuses/statusreasons.jsp</from-view-id>
    <navigation-case>
        <from-action>#{pc_statusReasonBacker.edit}</from-action>
        <from-outcome>success</from-outcome>
        <to-view-id>/jsp/statuses/statusreasonedit.jsp</to-view-id>
    </navigation-case>
    <navigation-case>
        <from-action>#{pc_statusReasonBacker.insert}</from-action>
        <from-outcome>success</from-outcome>
        <to-view-id>/jsp/statuses/statusreasonnew.jsp</to-view-id>
    </navigation-case>
</navigation-rule>

<!-- static and general actions-->
<!-- what page the action is coming from doesn't matter here -->
<navigation-rule>

    <navigation-case>
        <from-outcome>login</from-outcome>
        <to-view-id>/login.jsp</to-view-id>
    </navigation-case>

    <navigation-case>
        <from-outcome>menu</from-outcome>
        <to-view-id>/menu.jsp</to-view-id>
    </navigation-case>

    <!-- Notes -->
    <navigation-case>
        <from-outcome>notes</from-outcome>
        <to-view-id>/jsp/notes/notes.jsp</to-view-id>
    </navigation-case>


    <!-- Note Categories -->
    <navigation-case>
        <from-outcome>notecategories</from-outcome>
        <to-view-id>/jsp/notes/notecategories.jsp</to-view-id>
    </navigation-case>

    <!-- Note Subcategories -->
    <navigation-case>
        <from-outcome>notesubcategories</from-outcome>
        <to-view-id>/jsp/notes/notesubcategories.jsp</to-view-id>
    </navigation-case>

    <!-- Statuses -->
    <navigation-case>
        <from-outcome>statuses</from-outcome>
        <to-view-id>/jsp/statuses/statuses.jsp</to-view-id>
    </navigation-case>



    <!-- Status Reasons -->
    <navigation-case>
        <from-outcome>statusreasons</from-outcome>
        <to-view-id>/jsp/statuses/statusreasons.jsp</to-view-id>
    </navigation-case>


</navigation-rule>
 </faces-config>
public void processValueChange(ValueChangeEvent arg0) {
        if (arg0.getComponent().getId().equalsIgnoreCase("productList")) {
                this.setProduct(arg0.getNewValue().toString());

        }
        if (arg0.getComponent().getId().equalsIgnoreCase("worktypeList")) {
                this.setWorktype(arg0.getNewValue().toString());
        }
}
FacesContext.getCurrentInstance().getApplication().getNavigationHandler().handleNavigation(
                FacesContext.getCurrentInstance(), null, "stay_here");
<!-- Notes -->
<navigation-rule>
        <from-view-id>/jsp/notes/notes.jsp</from-view-id>
        <navigation-case>
                <from-action>#{pc_noteListBacker.edit}</from-action>
                <from-outcome>success</from-outcome>
                <to-view-id>/jsp/notes/noteedit.jsp</to-view-id>
        </navigation-case>
        <navigation-case>
                <from-action>#{pc_noteListBacker.insert}</from-action>
                <from-outcome>success</from-outcome>
                <to-view-id>/jsp/notes/notenew.jsp</to-view-id>
        </navigation-case>
        <navigation-case>
                <from-outcome>stay_here</from-outcome>
                <to-view-id>/jsp/notes/notes.jsp</to-view-id>
        </navigation-case>

</navigation-rule>