jsf函数的页面顺序

时间:2014-02-05 07:40:58

标签: jsf jsf-2

在我的jsf页面中有搜索和插入功能。 但是在我开始插入过程后,我可以开始搜索过程。 所以我必须首先插入搜索人,否则搜索按钮不起作用我该如何解决这个问题?

public void search() {

    getOsList(getUsername(), getSurname(), getTcidno());
    System.out.println("osList : " + osList);

}

public List<KisiBean> getOsList(String ad, String soyad, String tckimlikno) {

    Session session = null;
    Transaction tx = null;

    List<KisiBean> osList = new ArrayList<KisiBean>();

    session = HibernateSessionFactory.getSession();
    tx = session.beginTransaction();

    String sql = "select upper(k.ad),upper(k.soyad),k.temelkimlik.mernisno "
            + "from com.revir.domain.Kisi as k "
            + "where k.kisituru.kisiturid in (1,9,29,30)";

    if (!ad.isEmpty()) {
        sql = sql + "  AND  ((upper(ltrim(rtrim(k.ad))) like upper(:ad))"
                + "        OR "
                + "        (lower(ltrim(rtrim(k.ad))) like lower(:ad)))";

    }

    if (!soyad.isEmpty()) {
        sql = sql
                + "  AND  ((upper(ltrim(rtrim(k.soyad))) like upper(:soyad))"
                + "        OR "
                + "        (lower(ltrim(rtrim(k.soyad))) like lower(:soyad)))";
    }

    if (!tckimlikno.isEmpty()) {
        sql = sql
                + "  AND upper(k.temelkimlik.mernisno) like upper(:mernisno) ";
    }

    sql = sql
            + " order by NLSSORT(lower(k.soyad),'nls_sort=xturkish') asc,"
            + "NLSSORT(lower(k.ad),'nls_sort=xturkish') asc ";

    try {
        Query queryObject = session.createQuery(sql).setMaxResults(100);
        if (!ad.isEmpty())
            queryObject.setString("ad", "%" + ad.trim() + "%");
        if (!soyad.isEmpty())
            queryObject.setString("soyad", "%" + soyad.trim() + "%");
        if (!tckimlikno.isEmpty())
            queryObject
                    .setString("mernisno", "%" + tckimlikno.trim() + "%");

        System.out.println("SQL : " + sql);

        List list = queryObject.list();

        Object[] o;

        for (Iterator it = list.iterator(); it.hasNext();) {
            o = (Object[]) it.next();

            KisiBean osBean = new KisiBean();

            if (o[0] != null) {
                osBean.setAd((String) o[0].toString().trim());
                System.out.println("Ad : "
                        + (String) o[0].toString().trim());
            }

            if (o[1] != null) {
                osBean.setSoyad((String) o[1].toString().trim());
                System.out.println("Soyad : "
                        + (String) o[1].toString().trim());
            }

            if (o[2] != null) {
                osBean.setMernisno((String) o[2].toString());
                System.out.println("Kimlik No : "
                        + (String) o[2].toString());
            }

            System.out
                    .println("----------------------------------------------");

            osList.add(osBean);
        }

        tx.commit();
        log.debug("KisiInfoProcess - getStudentList - End DAO and Process Work");
    } catch (Exception e) {
        log.error("KisiInfoProcess - getStudentList - Error");
        tx.rollback();
        throw e;
    } finally {
        if (session != null && session.isOpen()) {
            session.close();
        }
    }

    log.debug("KisiInfoProcess - getStudentList - End / Returning");
    return osList;
}


public void savePerson() {

    saveOsList(getPusername(), getPsurname(), getPtcidno(),
            getPdogumtarihi(), getPcinsiyet());
    System.out.println("saveperson" + " - " + getPusername() + " - "
            + getPsurname() + " - " + getPtcidno() + " - "
            + getPdogumtarihi() + " - " + getPcinsiyet());

}

public void saveOsList(String ad, String soyad, String tcno,
        Date dogumtarihi, char cinsiyet) {

    System.out.println("saveOSList");

    Session session = null;
    Transaction tx = null;

    try {
        session = HibernateSessionFactory.getSession();
        tx = session.beginTransaction();

        TrvrKisi tkisi = new TrvrKisi();
        TrvrKisiDAO tkisiDAO = new TrvrKisiDAO();
        tkisi.setAd(ad);
        tkisi.setSoyad(soyad);
        tkisi.setTcno(tcno);

        SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
        String dateInString = "07/06/2013";
        dogumtarihi = formatter.parse(dateInString);
        System.out.println(dogumtarihi);
        System.out.println(formatter.format(dogumtarihi));
        tkisi.setDogumtarihi(dogumtarihi);
        tkisi.setCinsiyet(cinsiyet);

        tkisiDAO.save(tkisi);

        tx.commit();
        log.debug("KisiInfoProcess - getStudentList - End DAO and Process Work");
    } catch (Exception e) {
        log.error("KisiInfoProcess - getStudentList - Error");
        tx.rollback();
    } finally {
        if (session != null && session.isOpen()) {
            session.close();
        }
    }

    log.debug("KisiInfoProcess - getStudentList - End / Returning");
}

layout.xhtml:

<?xml version="1.0" encoding="UTF-8"?>
<!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:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html">
    <h:form id="form">
        <h:head>

            <f:facet name="first">
                <meta http-equiv="X-UA-Compatible" content="EmulateIE8" />
                <meta content='text/html; charset=UTF-8' http-equiv="Content-Type" />
                <title>REVİR HASTA KAYIT</title>
            </f:facet>

            <link type="text/css" rel="stylesheet"
                href="#{request.contextPath}/css/default.css" />



            <style type="text/css">
.ui-layout-north {
    z-index: 20 !important;
    overflow: visible !important;;
}

.ui-layout-north .ui-layout-unit-content {
    overflow: visible !important;
}
</style>


        </h:head>
        <h:body>

            <p:layout fullPage="true">

                <p:layoutUnit position="north">
                    <p:layout>

                        <p:layoutUnit position="north">
                            <h:outputText value="Middle top unit content." />
                        </p:layoutUnit>

                        <p:layoutUnit position="south">
                            <p:layout>
                                <p:layoutUnit position="north">
                                    <p:menubar>
                                        <p:submenu label="Duyurular" outcome="duyurular.xhtml"></p:submenu>
                                        <p:submenu label="Hasta Arama" url="#"></p:submenu>
                                    </p:menubar>

                                </p:layoutUnit>
                                <p:layoutUnit position="center" size="200">
                                    <ui:include src="/search.xhtml" />

                                </p:layoutUnit>
                            </p:layout>
                        </p:layoutUnit>

                        <p:layoutUnit position="west">
                            <h:outputText value="Middle left unit content." />
                        </p:layoutUnit>

                        <p:layoutUnit position="east">
                            <h:panelGrid columns="1">
                                <h:outputText value="Hoşgeldin #{loginBean.username}"></h:outputText>
                                <h:outputLink
                                    value="#{request.contextPath}/j_spring_security_logout">Oturumu Kapat</h:outputLink>
                            </h:panelGrid>
                        </p:layoutUnit>

                        <p:layoutUnit position="center">
                            <h:outputText value="REVİR HASTA OTOMASYON SİSTEMİ" />
                        </p:layoutUnit>

                    </p:layout>
                </p:layoutUnit>

                <p:layoutUnit position="south" size="50">
                    <h:outputText value="South unit content." />
                </p:layoutUnit>

                <p:layoutUnit position="west" size="900">

                    <ui:include src="/searchresults.xhtml" />

                </p:layoutUnit>

                <p:layoutUnit position="center">


                </p:layoutUnit>

            </p:layout>

        </h:body>


        <p:dialog id="modalDialog" header="Yeni Hasta Kayıt" widgetVar="dlg2"
            modal="true" height="300" width="300">


            <p:panel id="panel">
                <p:messages id="messages" />
                <h:panelGrid columns="2" columnClasses="column1">

                    <h:outputText value="Ad: *" />
                    <p:inputText id="username" value="#{userOS.pusername}"
                        required="true" label="Ad">
                        <f:validateLength minimum="2" />
                    </p:inputText>
                    <br />
                    <p:message for="username" />

                    <h:outputText value="Soyad: *" />
                    <p:inputText id="surname" value="#{userOS.psurname}"
                        required="true" label="Soyad" />
                    <br />
                    <p:message for="surname" />

                    <h:outputText value="TC Kimlik: *" />
                    <p:inputText id="tcidno2" value="#{userOS.ptcidno}" required="true"
                        label="TC Kimlik" />
                    <br />
                    <p:message for="tcidno" />

                    <h:outputText value="Doğum Tarihi:" />
                    <p:inputMask value="#{userOS.pdogumtarihi}" mask="99/99/9999" />


                    <h:outputText value="Cinsiyet: " />
                    <p:selectOneRadio id="options" value="#{userOS.pcinsiyet}">
                        <f:selectItem itemLabel="Erkek" itemValue="E" />
                        <f:selectItem itemLabel="Kadın" itemValue="K" />
                        <br></br>
                    </p:selectOneRadio>

                </h:panelGrid>
            </p:panel>

            <p:commandButton value="Ekle" id="ajax"
                actionListener="#{userOS.savePerson}" />
        </p:dialog>
    </h:form>

</f:view>
</html>

search.xhtml:

<?xml version="1.0" encoding="UTF-8"?>
<!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:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:ui="http://java.sun.com/jsf/facelets">
<body>
    <ui:composition>
        <p:panel header="Arama" style="margin-bottom:10px;">
            <h:panelGrid columns="2">
                <h:outputText value="Ad : "></h:outputText>
                <p:inputText id="ad" value="#{userOS.username}" label="Keyword" />
                <h:outputText value="Soyad : "></h:outputText>
                <p:inputText id="soyad" value="#{userOS.surname}" label="Keyword" />
                <h:outputText value="TC Kimlik no : "></h:outputText>
                <p:inputText id="tcidno" value="#{userOS.tcidno}" label="Keyword" />
                <p:watermark for="ad" value="Ad giriniz" />
                <p:watermark for="soyad" value="Soyad giriniz" />
                <p:watermark for="tcidno" value="TC Kimlik no giriniz" />
                <p:commandButton actionListener="#{userOS.search}" value="Arama"
                    update=":form:users" />
            </h:panelGrid>

        </p:panel>
    </ui:composition>
</body>
</html>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
  <display-name>Revir Kayit</display-name>
  <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/css/*</url-pattern>
  </servlet-mapping>
  <servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>
                    org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
            /WEB-INF/dispatcher-servlet.xml,
            /WEB-INF/applicationContext.xml,
         </param-value>
  </context-param>

  <listener>
    <listener-class>
            org.springframework.web.context.request.RequestContextListener
        </listener-class>
  </listener>
  <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Production</param-value>
  </context-param>
  <context-param>
    <param-name>primefaces.THEME</param-name>
    <param-value>casablanca</param-value>
  </context-param>
  <welcome-file-list>
    <welcome-file>login.jsf</welcome-file>
  </welcome-file-list>
  <session-config>
    <session-timeout>10</session-timeout>
  </session-config>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
  </servlet-mapping>
  <filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
  </filter-mapping>
  <resource-ref>
    <description>REVIR DB Connection</description>
    <res-ref-name>jdbc/REVIR</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
</web-app>

0 个答案:

没有答案