JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Web Framework » JSF  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 JSF資料庫查詢傳值
cool3690





發文: 44
積分: 0
於 2017-07-11 02:28 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
大家好:
想問一個問題

如圖:
我希望查詢按下去,不會跳頁,底下的資料就會變成我查的號碼資料
但我輸入厚植似乎都沒傳到java那邊.....
請問該怎麼做呢?
感謝,以下程式碼
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<h:form>
           Login: <h:inputText value="#{pur.tt}"/><br/>
           <h:commandButton value="search" action="#{pur.innum}" />
            
           <h:dataTable value="#{pur.purData}" var="pur"
                         styleClass="table" headerClass="header"
                         rowClasses="oddrow,evenrow">
                
                <h:column>
                    <f:facet name="header">Emno</f:facet>
                    #{pur.pri}
                </h:column>
               <h:column>
                    <f:facet name="header">Emno</f:facet>
                    #{pur.pname}
                </h:column>
            </h:dataTable><br/>
        </h:form>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
public class Pur
{public String tt="T0012";
 
    public String getTt() {
  return tt;
    }
 
    public void setTt(String tt) {
  this.tt = tt;
    }
    public List<Purtxt> getPurData()
    {
        List<Purtxt> purlist=new LinkedList<Purtxt>();
        try
        {
         Class.forName("oracle.jdbc.driver.OracleDriver");
         Connection con=DriverManager.getConnection("jdbc:oracle.....","tt","tn");      
      Statement st=con.createStatement();
       System.out.println(st);
        //ResultSet rs=st.executeQuery("select zx01,zx02,zx04 from zx_file where rownum<21"); 
         ResultSet rs=st.executeQuery(
        "select a1.pmn24,a1.pmn20,a1.pmn31,a2.pmm12 from pmn_file a1, pmm_file a2 where a1.pmn01=a2.pmm01 and rownum<51  ");          
         
     while(rs.next())
            {
                Purtxt e=new Purtxt();
     // e.setTt(rs.getString(tt));
    if(rs.getString("pmm12").equals(tt))
    {
        e.setNum(rs.getString("pmn24"));
        e.setPri(rs.getInt("pmn20"));
        e.setCoun(rs.getInt("pmn31"));
        e.setPname(rs.getString("pmm12"));
    }
    else{continue;}
    //e.setSum(rs.getInt("pmn20")*rs.getInt("pmn31"));
                purlist.add(e);
            }
            rs.close();
            st.close();
            con.close();
        }
        catch(ClassNotFoundException ex)
        {
            System.out.println("Invalid Driver..."+ex.getMessage());
        }
        catch(SQLException ex)
        {
            System.out.println("SQL Exception..."+ex.getMessage());
        }
        return purlist;
    }
    public String innum()
    { if(!tt.equals("pmm12"))
        {
         return "error";
  }
    return "error";
    }
}


reply to postreply to post
作者 Re:JSF資料庫查詢傳值 [Re:cool3690]
erics





發文: 17
積分: 0
於 2017-07-11 13:15 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Jsp裡的action:pur.innum,在後端程式中沒有對應的方法

reply to postreply to post
作者 Re:JSF資料庫查詢傳值 [Re:erics]
cool3690





發文: 44
積分: 0
於 2017-07-13 09:48 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我希望在底下更新
發現做不到
所以我就想讓她跳頁後更新
但我無法了解
為何我輸入T0013
按查詢為何還是他還是查T0012
該怎樣才能把直傳回去呢?


reply to postreply to post
作者 Re:JSF資料庫查詢傳值 [Re:cool3690]
yjy198410





發文: 27
積分: 0
於 2017-07-14 06:41 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你要先決定用哪一種JSF ManagedBean(算是 JSF Controller Bean),看是SessionScoped, ViewScoped 還是RequestScoped等不同的生命週期,實作方式會有點差異。導航的方式要用動態還是靜態(在faces-config.xml)。

#{pur.innum}是指呼叫innum(),必須把搜尋資料的動作寫在innum()內。

若用SessionScoped ManagedBean,#{pur.tt}會被儲存,應該會正常運作。
若用RequestScoped ManagedBean,#{pur.tt}不會被儲存,必須用取得Http post參數方法取得tt值,在最小修改code的範圍內在getPurData()內加入 String tt=FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("tt");把tt加入sql內。 <h:inputText value="#{pur.tt}"/>加上name="tt"。 應該就可以運作了。

話說JSF學起來蠻複雜


reply to postreply to post
十年磨一劍,我老是在磨劍。那怕磨劍不成,鐵杵磨成繡花針。
琢磨JSF, JavaFX, Design Pattern
作者 Re:JSF資料庫查詢傳值 [Re:yjy198410]
cool3690





發文: 44
積分: 0
於 2017-07-14 10:09 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你好:
我已經改了,但是出現錯誤


我的java是寫這樣
1
2
3
4
5
6
7
public String innum()
    { if(!tt.equals("pmm12"))
        {
        tt=FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("tt");
  }
    return "error";
    }

請問還有甚麼漏掉的嗎?
謝謝


reply to postreply to post
作者 Re:JSF資料庫查詢傳值 [Re:yjy198410]
cool3690





發文: 44
積分: 0
於 2017-07-14 10:27 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
改成id就沒錯誤了
但是我輸入T0013他還是會跳T0012的資料....
1
2
3
4
5
6
7
8
9
10
11
  Login: <h:inputText value="#{pur.tt}" id="tt"/><br/>
           <p:commandButton value="search" action="#{pur.innum()}" />
            
           <h:dataTable   value="#{pur.purData}" var="pur"
                         styleClass="table" headerClass="header"
                         rowClasses="oddrow,evenrow">
                
                <h:column>
                    <f:facet name="header">Emno</f:facet>
                    #{pur.pri}
                </h:column>


reply to postreply to post
作者 Re:JSF資料庫查詢傳值 [Re:cool3690]
cool3690





發文: 44
積分: 0
於 2017-07-20 01:02 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
OK了

reply to postreply to post
作者 Re:JSF資料庫查詢傳值 [Re:cool3690]
yjy198410





發文: 27
積分: 0
於 2017-07-20 04:03 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
用equals比較,到時候記得overwrite compare相關的method

reply to postreply to post
十年磨一劍,我老是在磨劍。那怕磨劍不成,鐵杵磨成繡花針。
琢磨JSF, JavaFX, Design Pattern
作者 Re:JSF資料庫查詢傳值 [Re:yjy198410]
cool3690





發文: 44
積分: 0
於 2017-07-21 01:23 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
好的,謝謝

reply to postreply to post
» JWorld@TW »  Web Framework » JSF

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8