显示弹出窗口后检查值

时间:2017-05-29 12:08:11

标签: java oracle-adf

如果他想更改密码,我首先检查用户的用户名和密码时出现异常,所以如果他的密码错误,则根据他在数据库中存储的密码显示弹出窗口,第一次工作正常并弹出弹出窗口通常但是在关闭弹出窗口以便在没有任何更改的情况下再次进行检查时,它会抛出NullPointerException,因为用户名和密码字段为空

javax.faces.el.EvaluationException: //C:/Users/m.rashad/AppData/Roaming/JDeveloper/system12.2.1.0.42.170105.1157/o.j2ee/drs/HRSSApp/ViewControllerAppWebApp.war/LogInPG.jsf @46,114 action="#{backingBeanScope.LogInPG.cbChngPass_action}": java.lang.RuntimeException: java.lang.NullPointerException

Caused by: java.lang.RuntimeException: java.lang.NullPointerException
at oracle.hrss.view.LogInPG.showPopup(LogInPG.java:369)
at oracle.hrss.view.LogInPG.cbChngPass_action(LogInPG.java:375)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:181)
at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at org.apache.myfaces.trinidad.component.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:46)
... 72 more
Caused by: java.lang.NullPointerException
    at oracle.hrss.view.LogInPG.getMyEmp(LogInPG.java:155)
    at oracle.hrss.view.LogInPG.showPopup(LogInPG.java:346)

这是完全代码的jsf文件

    <?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html>
<f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
        xmlns:h="http://java.sun.com/jsf/html">
    <af:document title="LogInPG.jsf" id="d1" binding="#{backingBeanScope.LogInPG.d1}">
        <af:form id="f1" binding="#{backingBeanScope.LogInPG.f1}">
            <af:pageTemplate viewId="/oracle/templates/threeColumnTemplate.jspx" id="pt1"
                             binding="#{backingBeanScope.LogInPG.pt1}">
                <f:facet name="center">
                    <!--
                    <af:decorativeBox theme="dark" id="db2">
                        <f:facet name="center">
                            <af:decorativeBox theme="medium" id="db1">
                                <f:facet name="center">                -->
                    <af:panelStretchLayout id="psl1" topHeight="33%" bottomHeight="33%">
                        <f:facet name="center">
                            <af:panelGroupLayout id="pgl1" layout="vertical" halign="center">
                                <af:panelFormLayout id="pflLogin" rows="2" maxColumns="1">
                                    <af:panelLabelAndMessage id="plm1" for="HrUsername" label="رقم الهوية"
                                                             showRequired="true">
                                        <af:inputText id="HrUsername" label="UserName" simple="true" maximumLength="10"
                                                      valueChangeListener="#{backingBeanScope.LogInPG.testValuChangeListener}"
                                                      autoSubmit="true" value="#{backingBeanScope.LogInPG.userName}"
                                                      requiredMessageDetail="يجب إدخال رقم الهوية" required="true"
                                                      inlineStyle="text-align:center;"/>
                                        <f:facet name="end">
                                            <af:outputText id="ot1" partialTriggers="HrUsername"
                                                           value="#{backingBeanScope.LogInPG.userDesc}"
                                                           inlineStyle="font-family:Arial; font-weight:bolder;"/>
                                        </f:facet>
                                        <af:spacer width="20" height="10" id="s4"
                                                   binding="#{backingBeanScope.LogInPG.s4}"/>
                                    </af:panelLabelAndMessage>
                                    <af:inputText label="كلمة المرور" id="HrPassword" secret="true" maximumLength="20"
                                                  value="#{backingBeanScope.LogInPG.userPass}"
                                                  requiredMessageDetail="يجب إدخال كلمة المرور" required="true"
                                                  inlineStyle="text-align:center;"/>
                                    <af:spacer width="10" height="10" id="s1"/>
                                    <af:panelGroupLayout id="pgl4" binding="#{backingBeanScope.LogInPG.pgl4}"
                                                         halign="center">
                                        <af:commandButton text="دخول" id="cbLogin"
                                                          action="#{backingBeanScope.LogInPG.login_action}"/>
                                        <af:spacer width="50" height="10" id="s2"
                                                   binding="#{backingBeanScope.LogInPG.s2}"/>
                                        <af:commandButton text="تغيير كلمة المرور" id="cbChngPass"
                                                          action="#{backingBeanScope.LogInPG.cbChngPass_action}">
                                            <af:showPopupBehavior popupId="p1" triggerType="action" disabled="true"/>
                                        </af:commandButton>
                                        <af:popup childCreation="deferred" id="p1"
                                                  binding="#{backingBeanScope.LogInPG.p1}" contentDelivery="immediate"
                                                  animate="true"
                                                  partialTriggers="HrUsername">
                                            <af:panelWindow id="pw1" binding="#{backingBeanScope.LogInPG.pw1}"
                                                            modal="true" stretchChildren="first"
                                                            styleClass="AFStretchWidth">
                                                <af:panelGroupLayout id="pgl5"
                                                                     binding="#{backingBeanScope.LogInPG.pgl5}"
                                                                     halign="center" layout="vertical">
                                                    <af:panelFormLayout id="pfl1"
                                                                        binding="#{backingBeanScope.LogInPG.pfl1}"
                                                                        maxColumns="1" rows="3">
                                                        <af:outputText id="ot2" partialTriggers="HrUsername"
                                                                       value="#{backingBeanScope.LogInPG.userDesc}"
                                                                       inlineStyle="font-family:Arial; font-weight:bolder;"/>
                                                        <af:spacer width="10" height="10" id="s5"
                                                                   binding="#{backingBeanScope.LogInPG.s5}"/>
                                                        <af:inputText label="كلمة المرور الجديدة" id="HrNewPassword"
                                                                      secret="true" maximumLength="20"
                                                                      inlineStyle="text-align:center;"
                                                                      showRequired="true"/>
                                                        <af:inputText label="تأكيد كلمة المرور الجديدة"
                                                                      id="HrCNewPassword" secret="true"
                                                                      maximumLength="20"
                                                                      inlineStyle="text-align:center;"
                                                                      showRequired="true"/>
                                                        <f:facet name="footer">
                                                            <af:panelGroupLayout id="pgl6"
                                                                                 binding="#{backingBeanScope.LogInPG.pgl6}"
                                                                                 layout="horizontal" halign="center">
                                                                <af:commandButton text="حفظ" id="b1"/>
                                                                <af:spacer width="40" height="10" id="s3"
                                                                           binding="#{backingBeanScope.LogInPG.s3}"/>
                                                                <af:button text="إلغاء الأمر" id="b2"
                                                                           binding="#{backingBeanScope.LogInPG.b2}"/>
                                                            </af:panelGroupLayout>
                                                        </f:facet>
                                                    </af:panelFormLayout>
                                                </af:panelGroupLayout>
                                            </af:panelWindow>
                                        </af:popup>
                                    </af:panelGroupLayout>
                                </af:panelFormLayout>
                            </af:panelGroupLayout>
                        </f:facet>
                        <f:facet name="top">
                            <af:panelGroupLayout id="pgl2" layout="vertical" halign="center"/>
                        </f:facet>
                        <f:facet name="bottom">
                            <af:panelGroupLayout id="pgl3" layout="vertical" halign="center"/>
                        </f:facet>
                    </af:panelStretchLayout>
                    <!--
                              </f:facet>
                            </af:decorativeBox>
                        </f:facet>
                    </af:decorativeBox> -->
                </f:facet>
                <f:facet name="header"/>
                <f:facet name="branding"/>
                <f:facet name="copyright"/>
                <f:facet name="status"/>
            </af:pageTemplate>
        </af:form>
    </af:document>
    <!--oracle-jdev-comment:auto-binding-backing-bean-name:LogInPG-->
</f:view>

更改密码按钮的代码

public String cbChngPass_action() {
        // Add event code here...
        showPopup(p1, true);
        return null;
    }

showPopup void

 private void showPopup(RichPopup pop, boolean visible) {
        // Add event code here...
        try {
            FacesMessage msg; //("**VALUE CHANGE LISTENER CALLED** " + valueChangeEvent.getNewValue());
            FacesContext context = FacesContext.getCurrentInstance();
            EmpData Emp = getMyEmp(); // Error here
            if (context != null && pop != null) {
                String popupId = pop.getClientId(context);
                if (popupId != null) {
                    StringBuilder script = new StringBuilder();
                    script.append("var popup = AdfPage.PAGE.findComponent('").append(popupId).append("'); ");
                    if (visible) {
                        if (Emp == null) {
                            msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "يوجد خطأ في بيانات الموظف", "");
                            context.addMessage("", msg);
                            return;
                        } else {
                            script.append("if (!popup.isPopupVisible()) { ").append("popup.show();}");
                        }
                    } else {
                        script.append("if (popup.isPopupVisible()) { ").append("popup.hide();}");
                    }
                    ExtendedRenderKitService erks =
                        Service.getService(context.getRenderKit(), ExtendedRenderKitService.class);
                    erks.addScript(context, script.toString());
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

getMyEmp void

private EmpData getMyEmp() {
    String UserID = this.getUserName().toString(); // Error here 
    String UserPas = this.getUserPass().toString(); // Error here 
    String AMDefin = "oracle.hrss.model.HrssAM";
    String StrConfig = "HrssAMLocal";
    ApplicationModule AMi = Configuration.createRootApplicationModule(AMDefin, StrConfig);
    HrssAMImpl AM = (HrssAMImpl) AMi;
    EmpData Emp = AM.FindMyEmp(UserID, UserPas);
    return Emp;
}

java文件的完整代码如下

package oracle.hrss.view;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.faces.application.FacesMessage;
import javax.faces.component.html.HtmlCommandButton;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;

import oracle.adf.view.rich.component.rich.RichDocument;
import oracle.adf.view.rich.component.rich.RichForm;
import oracle.adf.view.rich.component.rich.RichPanelWindow;
import oracle.adf.view.rich.component.rich.RichPopup;
import oracle.adf.view.rich.component.rich.fragment.RichPageTemplate;

import oracle.adf.view.rich.component.rich.layout.RichPanelFormLayout;
import oracle.adf.view.rich.component.rich.layout.RichPanelGroupLayout;

import oracle.adf.view.rich.component.rich.nav.RichButton;
import oracle.adf.view.rich.component.rich.output.RichActiveOutputText;
import oracle.adf.view.rich.component.rich.output.RichSpacer;

import oracle.hrss.model.EmpData;
import oracle.hrss.model.HrssAMImpl;

import oracle.jbo.ApplicationModule;

import oracle.jbo.client.Configuration;

import oracle.jdbc.OracleDriver;

import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;

public class LogInPG {
    private RichPageTemplate pt1;
    private RichForm f1;
    private RichDocument d1;
    private String UserName;
    private String UserPass;
    private String UserDesc;
    private RichPanelGroupLayout pgl4;
    private RichSpacer s2;
    private HtmlCommandButton cb1;
    private RichPopup p1;
    private RichPanelWindow pw1;
    private RichActiveOutputText aot1;
    private RichPanelGroupLayout pgl5;
    private RichPanelFormLayout pfl1;
    private HtmlCommandButton cb2;
    private HtmlCommandButton cb3;
    private RichButton b1;
    private RichPanelGroupLayout pgl6;
    private RichButton b2;
    private RichSpacer s3;
    private RichSpacer s4;
    private RichSpacer s5;

    public void setPt1(RichPageTemplate pt1) {
        this.pt1 = pt1;
    }

    public RichPageTemplate getPt1() {
        return pt1;
    }

    public void setF1(RichForm f1) {
        this.f1 = f1;
    }

    public RichForm getF1() {
        return f1;
    }

    public void setD1(RichDocument d1) {
        this.d1 = d1;
    }

    public RichDocument getD1() {
        return d1;
    }

    public void setUserName(String UserName) {
        this.UserName = UserName;
    }

    public String getUserName() {
        return UserName;
    }

    public void setUserPass(String UserPass) {
        this.UserPass = UserPass;
    }

    public String getUserPass() {
        return UserPass;
    }

    public void setUserDesc(String UserDesc) {
        this.UserDesc = UserDesc;
    }

    public String getUserDesc() {
        return UserDesc;
    }

    public String login_action() {
        // Add event code here...
        FacesMessage msg; //("**VALUE CHANGE LISTENER CALLED** " + valueChangeEvent.getNewValue());
        FacesContext cont = FacesContext.getCurrentInstance(); //.addMessage(null, msg);
        EmpData Emp = getMyEmp();
        if (Emp == null) {
            msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "يوجد خطأ فى البيانات", "");
        } else {
            msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "الموظف موجود : " + Emp.getEmp_Name(), "");
            cont.getExternalContext().getSessionMap().put("EmpUser", Emp);
            //cont.getExternalContext().redirect("HomePage.jsp");
        }
        cont.addMessage("", msg);
        return null;
        /*
       Connection conn;

       try {
           conn = getConnection();
           CallableStatement cstmt = conn.prepareCall("{? = call ENCRYPT(?)}");
           cstmt.registerOutParameter(1, Types.VARCHAR);
           cstmt.setString(2, UserPas);
           cstmt.execute();
           String output = cstmt.getString(1);
           Statement stmt = conn.createStatement();
           ResultSet rset =
               stmt.executeQuery("SELECT 'x' FROM EMPLOYEE_MST WHERE LEAV_DT IS NULL AND ID_NO = '" + UserID +
                                 "' AND PASWORD = '" + output + "'");
           if (rset.next()) {
               conn.close();
               return null;
           }
           conn.close();

       } catch (SQLException e) {
           System.out.println(e);
       }
       System.out.println("Success");
       return null; */

    }

    private EmpData getMyEmp() {
        String UserID = getUserName().toString();
        String UserPas = getUserPass().toString();
        String AMDefin = "oracle.hrss.model.HrssAM";
        String StrConfig = "HrssAMLocal";
        ApplicationModule AMi = Configuration.createRootApplicationModule(AMDefin, StrConfig);
        HrssAMImpl AM = (HrssAMImpl) AMi;
        EmpData Emp = AM.FindMyEmp(UserID, UserPas);
        return Emp;
    }

    public void testValuChangeListener(ValueChangeEvent valueChangeEvent) {
        if (valueChangeEvent.getNewValue() != null) {
            Connection conn = null;
            Statement stmt = null;
            ResultSet rset = null;
            HrssAMImpl ConInst = new HrssAMImpl();
            //ConInst = null;
            try {
                conn = ConInst.getConnection();
                stmt = conn.createStatement();
                rset =
                    stmt.executeQuery("SELECT EMP_NAME FROM EMPLOYEE_MST WHERE LEAV_DT IS NULL AND ID_NO = '" +
                                      valueChangeEvent.getNewValue() + "'");
                if (rset.next()) {
                    UserDesc = rset.getString("EMP_NAME").toString();
                    //conn.close();
                    /* return "good"; */
                    //return null;
                }
                //conn.close();
            } catch (SQLException e) {
                System.out.println(e);
            } finally {
                try {
                    if (rset != null) {
                        rset.close();
                    }
                    if (stmt != null) {
                        stmt.close();
                    }
                    if (conn != null) {
                        conn.close();
                    }
                } catch (Exception e) {
                    // TODO: Add catch code
                    e.printStackTrace();
                }
            }
            //FacesMessage msg = new FacesMessage("**VALUE CHANGE LISTENER CALLED** " + valueChangeEvent.getNewValue());
            //FacesContext.getCurrentInstance().addMessage(null, msg);
        }
    }


    public void setPgl4(RichPanelGroupLayout pgl4) {
        this.pgl4 = pgl4;
    }

    public RichPanelGroupLayout getPgl4() {
        return pgl4;
    }

    public void setS2(RichSpacer s2) {
        this.s2 = s2;
    }

    public RichSpacer getS2() {
        return s2;
    }


    public void setCb1(HtmlCommandButton cb1) {
        this.cb1 = cb1;
    }

    public HtmlCommandButton getCb1() {
        return cb1;
    }

    public void setP1(RichPopup p1) {
        this.p1 = p1;
    }

    public RichPopup getP1() {
        return p1;
    }


    public void setPw1(RichPanelWindow pw1) {
        this.pw1 = pw1;
    }

    public RichPanelWindow getPw1() {
        return pw1;
    }

    public void setAot1(RichActiveOutputText aot1) {
        this.aot1 = aot1;
    }

    public RichActiveOutputText getAot1() {
        return aot1;
    }


    public void setPgl5(RichPanelGroupLayout pgl5) {
        this.pgl5 = pgl5;
    }

    public RichPanelGroupLayout getPgl5() {
        return pgl5;
    }

    public void setPfl1(RichPanelFormLayout pfl1) {
        this.pfl1 = pfl1;
    }

    public RichPanelFormLayout getPfl1() {
        return pfl1;
    }


    public void setCb2(HtmlCommandButton cb2) {
        this.cb2 = cb2;
    }

    public HtmlCommandButton getCb2() {
        return cb2;
    }

    public void setCb3(HtmlCommandButton cb3) {
        this.cb3 = cb3;
    }

    public HtmlCommandButton getCb3() {
        return cb3;
    }


    public void setB1(RichButton b1) {
        this.b1 = b1;
    }

    public RichButton getB1() {
        return b1;
    }

    public void setPgl6(RichPanelGroupLayout pgl6) {
        this.pgl6 = pgl6;
    }

    public RichPanelGroupLayout getPgl6() {
        return pgl6;
    }

    public void setB2(RichButton b2) {
        this.b2 = b2;
    }

    public RichButton getB2() {
        return b2;
    }

    public void setS3(RichSpacer s3) {
        this.s3 = s3;
    }

    public RichSpacer getS3() {
        return s3;
    }

    public void setS4(RichSpacer s4) {
        this.s4 = s4;
    }

    public RichSpacer getS4() {
        return s4;
    }

    public void setS5(RichSpacer s5) {
        this.s5 = s5;
    }

    public RichSpacer getS5() {
        return s5;
    }

    private void showPopup(RichPopup pop, boolean visible) {
        // Add event code here...
        try {
            FacesMessage msg; //("**VALUE CHANGE LISTENER CALLED** " + valueChangeEvent.getNewValue());
            FacesContext context = FacesContext.getCurrentInstance();
            EmpData Emp = getMyEmp();
            if (context != null && pop != null) {
                String popupId = pop.getClientId(context);
                if (popupId != null) {
                    StringBuilder script = new StringBuilder();
                    script.append("var popup = AdfPage.PAGE.findComponent('").append(popupId).append("'); ");
                    if (visible) {
                        if (Emp == null) {
                            msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "يوجد خطأ في بيانات الموظف", "");
                            context.addMessage("", msg);
                            return;
                        } else {
                            script.append("if (!popup.isPopupVisible()) { ").append("popup.show();}");
                        }
                    } else {
                        script.append("if (popup.isPopupVisible()) { ").append("popup.hide();}");
                    }
                    ExtendedRenderKitService erks =
                        Service.getService(context.getRenderKit(), ExtendedRenderKitService.class);
                    erks.addScript(context, script.toString());
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public String cbChngPass_action() {
        // Add event code here...
        showPopup(p1, true);
        return null;
    }
}

第二次出现错误而没有UserName或UserPass字段的任何更改

0 个答案:

没有答案