Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.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
Jsf 2 无法在richfaces的弹出面板中获取数据_Jsf 2_Richfaces_Hibernate3 - Fatal编程技术网

Jsf 2 无法在richfaces的弹出面板中获取数据

Jsf 2 无法在richfaces的弹出面板中获取数据,jsf-2,richfaces,hibernate3,Jsf 2,Richfaces,Hibernate3,当我点击编辑链接时,我无法在丰富的弹出面板中获得所需的数据。谁能帮我解决这个问题 当我试图编辑行详细信息时,我第一次无法在各自的字段中获取所需的数据,但令人惊讶的是,当我刷新页面并执行相同的过程时,我在各自的字段中获取了数据 我想在第一次点击编辑链接时获得所需的数据 那么,谁能帮我解决这个问题呢 我的xhtml页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/

当我点击编辑链接时,我无法在丰富的弹出面板中获得所需的数据。谁能帮我解决这个问题

当我试图编辑行详细信息时,我第一次无法在各自的字段中获取所需的数据,但令人惊讶的是,当我刷新页面并执行相同的过程时,我在各自的字段中获取了数据

我想在第一次点击编辑链接时获得所需的数据

那么,谁能帮我解决这个问题呢

我的xhtml页面

   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:t="http://myfaces.apache.org/tomahawk">
<h:head>

</h:head>
<h:body>
    <h:form id="dboperatorform">
        <t:saveState value="#{dBOperator.empList}"></t:saveState>
        <t:saveState value="#{dBOperator.edit}"></t:saveState>
        <t:saveState value="#{dBOperator.rowNum}"></t:saveState>
        <t:saveState value="#{dBOperator.employee}"></t:saveState>
        <rich:panel style="width:1345px">
            <f:facet name="header">
                <h:outputText value="Search Panel" />
            </f:facet>
            <h:panelGrid id="searchPanel" columns="6">
                <h:column>
                    <h:outputLabel value="First Name:" />
                </h:column>
                <h:column>
                    <h:inputText value="#{dBOperator.first_Name}" />
                </h:column>
                <h:column>
                    <h:outputLabel value="Last Name:" />
                </h:column>
                <h:column>
                    <h:inputText value="#{dBOperator.last_name}" />
                </h:column>
                <h:column>
                    <a4j:commandButton value="Search" action="#{dBOperator.search}"
                        render="richtable">

                    </a4j:commandButton>
                </h:column>
                <h:column>

                </h:column>
            </h:panelGrid>
        </rich:panel>
        <br />
        <a4j:commandButton value="Add" action="#{dBOperator.editdetails}"
            execute="@this" style="width:30px;height:30px;"
            oncomplete="#{rich:component('popup1')}.show();"
            render="richtable popup1">
            <f:setPropertyActionListener target="#{dBOperator.edit}"
                value="false"></f:setPropertyActionListener>
        </a4j:commandButton>
        <p></p>
        <rich:dataTable value="#{dBOperator.employees}" var="emp"
            id="richtable" cellpadding="0" cellspacing="0" style="width:1349px"
            reRender="richtable" iterationStatusVar="it"
            noDataLabel="No Records Found!" rows="5">
            <rich:column>
                <f:facet name="header">#</f:facet>
                <h:outputText value="#{it.index}" />
            </rich:column>
            <rich:column>
                <f:facet name="header">
                    <a4j:commandLink value="First Name"
                        action="#{dBOperator.sortByFirstName}" render="richtable"></a4j:commandLink>
                </f:facet>
                <h:outputText value="#{emp.first_Name}" />
            </rich:column>
            <rich:column>
                <f:facet name="header">Last Name</f:facet>
                <h:outputText value="#{emp.last_name}" />
            </rich:column>
            <rich:column>
                <f:facet name="header">Edit</f:facet>
                <a4j:commandButton image="images/edit.png"
                    action="#{dBOperator.editdetails}" execute="@this"
                    style="width:30px;height:30px;"
                    oncomplete="#{rich:component('popup1')}.show();"
                    render="richtable popup1">
                    <f:setPropertyActionListener target="#{dBOperator.rowNum}"
                        value="#{it.index}"></f:setPropertyActionListener>
                    <f:setPropertyActionListener target="#{dBOperator.edit}"
                        value="true"></f:setPropertyActionListener>
                </a4j:commandButton>
            </rich:column>
            <f:facet name="footer">
                <rich:dataScroller for="richtable" align="right"
                    status="ajaxProcessIcon" renderIfSinglePage="false" fastStep="5"
                    fastControls="auto" />
            </f:facet>
        </rich:dataTable>

        <rich:popupPanel id="popup1" minHeight="300"
            minWidth="300">
            <t:saveState value="#{dBOperator.edit}"></t:saveState>
            <t:saveState value="#{dBOperator.rowNum}"></t:saveState>
            <f:facet name="header">
                <h:outputText value="Simple popup panel" />
            </f:facet>
            <f:facet name="controls">
                <h:outputLink
                    onclick="#{rich:component('popup1')}.hide(); return false;"
                    reRender="richtable">X</h:outputLink>
            </f:facet>
            <rich:toolbar itemSeparator="line" width="100%" id="qawq">
                <rich:toolbarGroup location="left">
                    <h:outputText
                        value="#{dBOperator.edit?'Employee Edit':'Employee Add'}" />
                </rich:toolbarGroup>
            </rich:toolbar>
            <h:panelGrid id="CancelGrid" columns="2" width="100%">
                <rich:column width="30%" style="border:none;">
                    <h:outputText value="First Name" style="font-weight: bold;" />
                    <font class="star" color="red">*</font>
                </rich:column>
                <rich:column width="70%" style="border:none;">
                    <h:inputText value="#{dBOperator.employee.first_Name}"
                        style="width:100%" id="abbr" />
                </rich:column>
                <rich:column width="30%" style="border:none;">
                    <h:outputText value="Last Name" style="font-weight: bold;" />
                    <font class="star" color="red">*</font>
                </rich:column>
                <rich:column width="70%" style="border:none;">
                    <h:inputText value="#{dBOperator.employee.last_name}"
                        style="width:100%" id="abbr1" />
                </rich:column>
            </h:panelGrid>
            <a4j:commandButton value="#{dBOperator.edit?'Edit':'Save'}"
                action="#{dBOperator.savedetails}"
                oncomplete="#{rich:component('popup1')}.hide();"
                onclick="validateFields();"></a4j:commandButton>
        </rich:popupPanel>
        <script type="text/javascript">
                    function validateFields() {
                        alert('came inside validateFields');
                        var fn=document.getElementById('dboperatorform:abbr');
                        alert('fn '+fn.value);
                        var ln=document.getElementById('dboperatorform:abbr1');
                        alert('ln '+ln.value);
                    }

                </script>
    </h:form>
</h:body>
</html>


# 姓 编辑 X * * 函数validateFields(){ 警报(“进入validateFields”); var fn=document.getElementById('dboperatorform:abbr'); 警报(“fn”+fn.值); var ln=document.getElementById('dboperatorform:abbr1'); 警报('ln'+ln.值); }
我的Bean类代码

   package com.richfaces.db;

import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.management.MBeanServer;
import javax.swing.SortOrder;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import com.comparator.NameComparator;
import com.comparator.NameCompartor1;
import com.richfaces.Employee;

public class DBOperator {
    String id;
    String first_Name;
    String last_name;
    String fName;
    String lName;
    Employee employee;
    int rowNum;
    boolean edit;
    Boolean search=Boolean.FALSE;
    Boolean status = Boolean.FALSE;
    List<Employee> list = new ArrayList<Employee>();
    List<Employee> empList = new ArrayList<Employee>();

    public boolean isEdit() {
        return edit;
    }

    public void setEdit(boolean edit) {
        this.edit = edit;
    }

    public Employee getEmployee() {
        return employee;
    }

    public void setEmployee(Employee employee) {
        this.employee = employee;
    }

    public int getRowNum() {
        return rowNum;
    }

    public void setRowNum(int rowNum) {
        this.rowNum = rowNum;
    }

    public String getFirst_Name() {
        return first_Name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setFirst_Name(String first_Name) {
        this.first_Name = first_Name;
    }

    public String getLast_name() {
        return last_name;
    }

    public void setLast_name(String last_name) {
        this.last_name = last_name;
    }

    public List<Employee> getEmployees() {
        System.out.println("hghhghhhhh");
        String sql2="";
        Query query = null;
        String sql1 = "from Employee as emp where id is not null ";
        Configuration cfg = new Configuration();
        cfg.configure();
        SessionFactory sf = cfg.buildSessionFactory();
        Session sess = sf.openSession();
        sess.beginTransaction();
        if(status==false && search==false) {
            System.out.println("Normal Query +++++++++++++++++++++++ " + sql1);
            String appendedQuery = createCriteriaQuery(sql1);
            System.out.println("Appended Query ++++++++++++++++++++++++ "
                    + appendedQuery);
            query = sess.createQuery(appendedQuery);
        }else if(status==true && search==true) {
            System.out.println("came inside when search and status is true");
            String appendedQuery = createCriteriaQuery(sql1);
            System.out.println("Appended Query ++++++++++++++++++++++++ "
                    + appendedQuery);
            query = sess.createQuery(appendedQuery);
        }else if(status==false && search==true) {
            System.out.println("came inside when search  is true and status is false");
            String appendedQuery = createCriteriaQuery(sql1);
            System.out.println("Appended Query ++++++++++++++++++++++++ "
                    + appendedQuery);
            query = sess.createQuery(appendedQuery);
        }else if(status==true && search==false) {
            System.out.println("came inside when search  is false and status is true");
            String appendedQuery = createCriteriaQuery(sql1);
            System.out.println("Appended Query ++++++++++++++++++++++++ "
                    + appendedQuery);
            query = sess.createQuery(appendedQuery);
        }
        list = query.list();
        /*if (status) {
            Collections.sort(list, new NameComparator());
        } else {
            Collections.sort(list, new NameCompartor1());
        }*/
        System.out.println(list.size());
        this.empList = list;
        return list;
    }

    public String createCriteriaQuery(String query) {
        StringBuffer sb = new StringBuffer(query);
        if (getFirst_Name() != null && !(getFirst_Name().equals(""))) {
            sb.append(" and emp.first_Name='" + first_Name + "'");
        }
        if (getLast_name() != null && !(getLast_name().equals(""))) {
            sb.append(" and emp.last_name='" + last_name + "'");
        }
        if(this.status) {
            sb.append(" order by emp.first_Name desc");
        }else {
            sb.append(" order by emp.first_Name");
        }
        System.out.println(sb.toString());
        return sb.toString();
    }

    public void editdetails() {
        if (edit) {
            System.out.println("rownum is " + rowNum);
            System.out.println(empList.size());
            employee = (Employee) empList.get((rowNum));
            System.out.println(employee.getFirst_Name() + "\t"
                    + employee.getLast_name() + "\t" + employee.getId());
            System.out.println("end of edit details method");
        } else {
            employee = new Employee();
        }

    }

    public List<Employee> getEmpList() {
        return empList;
    }

    public void setEmpList(List<Employee> empList) {
        this.empList = empList;
    }

    public void savedetails() {
        System.out.println("came into savedetails");
        Configuration cfg = new Configuration();
        cfg.configure();
        SessionFactory sf = cfg.buildSessionFactory();
        Session sess = sf.openSession();
        if(this.edit) {
            System.out.println("EMPLOYEE DETAILS in IF "+getEmployee().getFirst_Name()+"\t"+getEmployee().getLast_name());
            System.out.println("came inside if when edit is true");
            sess.update(employee);
        }else {
            System.out.println("came inside else when edit is false");
            System.out.println("EMPLOYEE DETAILS in ELSE "+getEmployee().getFirst_Name()+"\t"+getEmployee().getLast_name());
            sess.save(employee);
        }
    }

    public void search() {
        System.out.println("came into search method");
        search = true;
    }

    public void refreshData(ActionEvent ae) {
        System.out.println("came into refreshdata");
        getEmployees();
    }

    public void sortByFirstName() {
        System.out.println("came inside sortByFirstName");
        if (!status) {
            status = Boolean.TRUE;
        } else {
            status = Boolean.FALSE;
        }
        //status=Boolean.TRUE;
        getEmployees();

    }


    public String getfName() {
        return fName;
    }

    public void setfName(String fName) {
        this.fName = fName;
    }

    public String getlName() {
        return lName;
    }

    public void setlName(String lName) {
        this.lName = lName;
    }
}

My Entity class code as follows:



    package com.richfaces;

import java.io.Serializable;

public class Employee implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    String id;
    String first_Name;
    String last_name;


    public String getFirst_Name() {
        return first_Name;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public void setFirst_Name(String first_Name) {
        this.first_Name = first_Name;
    }
    public String getLast_name() {
        return last_name;
    }
    public void setLast_name(String last_name) {
        this.last_name = last_name;
    }

}
package com.richfaces.db;
导入java.lang.management.ManagementFactory;
导入java.util.ArrayList;
导入java.util.Collections;
导入java.util.List;
导入javax.faces.context.FacesContext;
导入javax.faces.event.ActionEvent;
导入javax.management.MBeanServer;
导入javax.swing.SortOrder;
导入org.hibernate.Query;
导入org.hibernate.Session;
导入org.hibernate.SessionFactory;
导入org.hibernate.cfg.Configuration;
导入com.comparator.nameparator;
导入com.comparator.namecomparator1;
导入com.richfaces.Employee;
公共类DBOperator{
字符串id;
字符串名;
字符串last_name;
字符串fName;
字符串名称;
员工;
int rowNum;
布尔编辑;
布尔搜索=Boolean.FALSE;
布尔状态=Boolean.FALSE;
列表=新的ArrayList();
List empList=new ArrayList();
公共布尔isEdit(){
返回编辑;
}
公共void setEdit(布尔编辑){
this.edit=编辑;
}
公共雇员getEmployee(){
返回员工;
}
公共作废集合雇员(雇员雇员){
this.employee=employee;
}
public int getRowNum(){
返回rowNum;
}
公共void setRowNum(int rowNum){
this.rowNum=rowNum;
}
公共字符串getFirst_Name(){
返回第一个名称;
}
公共字符串getId(){
返回id;
}
公共无效集合id(字符串id){
this.id=id;
}
public void setFirst\u Name(字符串first\u Name){
this.first\u Name=first\u Name;
}
公共字符串getLast_name(){
返回姓氏;
}
public void setLast_name(字符串last_name){
this.last_name=last_name;
}
公开名单{
System.out.println(“hghghhh”);
字符串sql2=“”;
Query=null;
String sql1=“作为emp的员工,id不为null”;
Configuration cfg=新配置();
configure();
SessionFactory sf=cfg.buildSessionFactory();
Session sess=sf.openSession();
sess.beginTransaction();
if(status==false&&search==false){
System.out.println(“普通查询+sql1”);
字符串appendedQuery=createCriteriaQuery(sql1);
System.out.println(“追加查询”
+附加查询);
query=sess.createQuery(appendedQuery);
}else if(status==true&&search==true){
System.out.println(“在搜索和状态为true时进入”);
字符串appendedQuery=createCriteriaQuery(sql1);
System.out.println(“追加查询”
+附加查询);
query=sess.createQuery(appendedQuery);
}else if(status==false&&search==true){
System.out.println(“在搜索为真而状态为假时进入”);
字符串appendedQuery=createCriteriaQuery(sql1);
System.out.println(“追加查询”
+附加查询);
query=sess.createQuery(appendedQuery);
}else if(status==true&&search==false){
System.out.println(“当搜索为假且状态为真时进入”);
字符串appendedQuery=createCriteriaQuery(sql1);
System.out.println(“追加查询”
+a
<a4j:commandButton value="Edit" action="#{dBOperator.editdetails}" execute="@this"
    oncomplete="#{rich:component('popup1')}.show();"
    render="richtable, popup1">
        <f:setPropertyActionListener target="#{dBOperator.rowNum}" value="#{it.index}" />
</a4j:commandButton>