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用JS的問題
cool3690





發文: 44
積分: 0
於 2017-08-01 01:08 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
大家好:
想問個問題
我寫一個簡易的登入系統
想判斷
EX:
A帳號登入可以觀看A,B,C網頁
B帳號登入可以看D,E,F網頁
所以我寫
xhtml

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
function para()
     {var a,d,i=0;
         for(i=0;i<5;i++){
        d+=" <p:menuitem value="1234" outcome="#{loginBean.dede[i]}"/>";
            }
//loginBean.dede[i]}java 已經設定好陣列
       document.getElementById("tes").show =d;
         
     }
    </script>
    </h:head>
 
    <h:body>
 
        <p:layout fullPage="true">
            <p:layoutUnit position="north" size="50" resizable="true" collapsible="true">    
                <ui:include src="/TopBanner.xhtml"/>
            </p:layoutUnit>
            <p:layoutUnit position="west" size="175" header="功能選單" collapsible="true">
                <p:menu>              
                    <p:submenu label="生產管制" id ="tes">                     
                    </p:submenu>
                   /*show para()*/
                </p:menu>
            </p:layoutUnit>
            
            <p:layoutUnit position="center">                
                <ui:insert name="source" />
            </p:layoutUnit>

但都會編譯失敗,連跑for都不行...
網路上好像說不建議用JS這樣寫,那我該怎麼做會比較好呢?
請各位指教,謝謝


reply to postreply to post
作者 Re:JSF用JS的問題 [Re:cool3690]
snowbean71





發文: 92
積分: 0
於 2017-08-02 16:14 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
你用js產生jsf的code,就算js能跑,jsf也不會產生對映的html code

因為js 是在clent 端跑的,而jsf 是在server瑞跑的
而且是jsf先跑完,再到browser上跑js

要改就直接寫到 manager bean 中,然後用 jsf 的語法寫出來 ui:repeat


reply to postreply to post
javabean71.....snowbean71......JSF+JPA+Primefaces
作者 Re:JSF用JS的問題 [Re:snowbean71]
cool3690





發文: 44
積分: 0
於 2017-08-04 03: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
了解了,我最後都乾脆寫在java端了
但發現一個問題
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
public String checkLogin()
    { 
        getEmpData();
        if(ans.equals("B-RD02") )
        {int i;
  for(i=0;i<qw.length;i++)
  {qw[i]=sale[i];
  }
            return "sales/DelayStock";
        }
    if....
  
    }
    public List<ZX> getEmpData() //throws SQLException
    {
        try
        {
         Class.forName("oracle.jdbc.driver.OracleDriver");
         Connection con=DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.....","aa","aa");      
      Statement st=con.createStatement();
       System.out.println(st);
         ResultSet rs=st.executeQuery("select zx01,zx03 from zx_file where zx01= 'useracc' ");          
            while(rs.next())
            {
                ZX e=new ZX();
                e.setZx01(rs.getString("zx01"));//zx01員工編號
                         
               ans=rs.getString("zx03");//權限代號
                zxtest.add(e);
            }
            rs.close();
            st.close();
            con.close();
        }
        catch(ClassNotFoundException ex)
        {
            System.out.println("Invalid Driver..."+ex.getMessage());
        }
       zxtest;
    }
 

我發現rs.getString("zx03");
無法將直存入ans中
請問還要在加什麼?


cool3690 edited on 2017-08-04 08:28
reply to postreply to post
作者 Re:JSF用JS的問題 [Re:snowbean71]
cool3690





發文: 44
積分: 0
於 2017-08-08 08:56 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
終於可以傳值了
想再請教一下大大知道 spring security 嗎?

我發現我的web.xml
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
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    
    
    
    
    
    <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>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/security-config.xml
    </param-value>
</context-param>

    <resource-ref>
        <res-ref-name>jdbc:oracle:thin:@192.168.10.21:1521:topprod</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
</web-app>


這樣執行是OK的
但是加了
1
2
3
4
5
6
7
8
9
10
11
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>
</filter-mapping>

後就會無法執行
我也爬文過了,說要加security-config dependence
但還是沒效........
想問大大了解這塊嗎?
謝謝


reply to postreply to post
作者 Re:JSF用JS的問題 [Re:cool3690]
snowbean71





發文: 92
積分: 0
於 2017-08-08 13:18 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
https://www.youtube.com/watch?v=ymP_nmROZs0

不必用 spring ,jsf 可以配合 jdbc realm 做。
當然如果你一定要用 spring 的話,也可以,但我對spring 真的不太熟。


reply to postreply to post
javabean71.....snowbean71......JSF+JPA+Primefaces
作者 Re:JSF用JS的問題 [Re:snowbean71]
cool3690





發文: 44
積分: 0
於 2017-08-10 03:57 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
了解,謝謝
不過上司要我用spring
我只能研究看看了


reply to postreply to post
作者 Re:JSF用JS的問題 [Re:snowbean71]
cool3690





發文: 44
積分: 0
於 2017-08-15 10:01 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有沒有甚麼套件是可以畫圓餅圖或長條圖的啊?


reply to postreply to post
作者 Re:JSF用JS的問題 [Re:cool3690]
snowbean71





發文: 92
積分: 0
於 2017-08-15 13:31 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
https://www.primefaces.org/showcase/ui/chart/bar.xhtml https://www.primefaces.org/showcase/ui/chart/pie.xhtml

reply to postreply to post
javabean71.....snowbean71......JSF+JPA+Primefaces
作者 Re:JSF用JS的問題 [Re:snowbean71]
cool3690





發文: 44
積分: 0
於 2017-08-16 01:53 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
作者 Re:JSF用JS的問題 [Re:snowbean71]
cool3690





發文: 44
積分: 0
於 2017-08-17 04:01 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
snowbean71 大大好

想請教一下

1.連SQL==>OK
2.chart範例執行==>OK
3將SQL抓到的資料用chart畫出來==>失敗!!

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.jj.dbcon;
 
@ManagedBean
public class ChartView implements Serializable {
 
    private BarChartModel barModel;
    private HorizontalBarChartModel horizontalBarModel;
  public int a[];
 public int b[];
 public int i=0;
/*
set/get
*/
    @PostConstruct
    public void init() {
        createBarModels();
    }
 
    private BarChartModel initBarModel() {
        BarChartModel model = new BarChartModel();
 
        ChartSeries boys = new ChartSeries();
        boys.setLabel("Boys");
  for(int j=0;j<a.length;j++)
  {
      boys.set(a[j], b[j]);
  }
        model.addSeries(boys); 
        return model;
    }
     
    private void createBarModels() {
        createBarModel();
       
    }
     
    private void createBarModel() {
        barModel = initBarModel();
         
        barModel.setTitle("Bar Chart");
        barModel.setLegendPosition("ne");
         
        Axis xAxis = barModel.getAxis(AxisType.X);
        xAxis.setLabel("Gender");
         
        Axis yAxis = barModel.getAxis(AxisType.Y);
        yAxis.setLabel("Births");
        yAxis.setMin(0);
        yAxis.setMax(200);
    }
     
    public List<Purtxt> getPurData()
    {
        List<Purtxt> purlist=new LinkedList<Purtxt>();
        try
        {
         Class.forName("oracle.jdbc.driver.OracleDriver");
         Connection con=DriverManager.getConnection("jdbc:oracle:thin:@192....","ee","ee");      
      Statement st=con.createStatement();
       System.out.println(st);      
         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  ");          
         
     while(rs.next())
            {
                 Purtxt e=new Purtxt();    
        e.setPri(rs.getInt("pmn20"));
        e.setCoun(rs.getInt("pmn31"));
                purlist.add(e);
     a[i]=rs.getInt("pmn31");
     b[i]=rs.getInt("pmn20");
 /*問題主要在這裡,想把值放進去,但發現他放不進去.....
        a[i],b[i]依舊是空值
        我有試著將a[i],b[i]直接存入數字(不使用SQL)她就可以顯示.....
        求把rs.getInt("pmn31")值存入a[i]的方法...感謝
       */
    i++;
            }
            rs.close();
            st.close();
            con.close();
        }
        //catch.....
        return purlist;
    }
 
}

想問我把值都存在 a[i]=rs.getInt("pmn31");
但a[i]仍然是空的........
謝謝


cool3690 edited on 2017-08-17 09:48
reply to postreply to post
作者 Re:JSF用JS的問題 [Re:cool3690]
snowbean71





發文: 92
積分: 0
於 2017-08-19 08:53 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
public int a[] ;
public int b[] ;
我看程式都沒初始化,應該要有一行 a=new int [size] ; 而size 應該大於你sql 傳回來的筆數。

如果我寫我會直接用List ,不然就要先傳回筆數

1
2
3
4
5
6
7
8
9
10
11
12
13
List<Integer> a1=new ArrayList<>();
List<Integer> b2=new ArrayList<>();
 
while(rs.next()){
     a1.add(rs.getInt("pmn31"));
     b2.add(rs.getInt("pmn20"));
}
 
a = new int[a1.size()];
a1.toArray(a);
 
b = new int[b2.size()];
b2.toArray(b);


這應該是java 語言的基礎問題吧


reply to postreply to post
javabean71.....snowbean71......JSF+JPA+Primefaces
作者 Re:JSF用JS的問題 [Re:snowbean71]
cool3690





發文: 44
積分: 0
於 2017-08-22 03:40 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
» 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