Download - Workshop Jsf

Transcript
  • 8/3/2019 Workshop Jsf

    1/15

    D i s t r i b u t e d a p p l i c a t i o n s

    A d a m W a l d e n b e r g

    J o a c h i m v o n H a c h t

    W o r k s h o p 5 : J a v a S e r v e r F a c e s ( J S F )

    O b j e c t i v e s

    G a i n i n g s o m e b a s i c k n o w l e d g e a b o u t J a v a S e r v e r F a c e s a n d F a c e l e t s .

    L e a r n i n g h o w t o u s e A J A X w i t h J S F .

    B a s i c i n t r o d u c t i o n t o h i g h e r l e v e l c o m p o n e n t l i b r a r i e s ( P r i m e F a c e s & I C E F a c e s ) .

    U n d e r s t a n d i n g s c o p e s a n d h o w t o t a k e f u l l a d v a n t a g e o f t h e m w h e n d e n i n g m a n -

    a g e d b e a n s .

    L e a r n h o w t o u s e b a s i c v a l i d a t o r s i n J S F .

    U n d e r s t a n d i n g s e r v e r p u s h a n d h o w i t c a n b e u s e d i n a n a p p l i c a t i o n .

    W h a t y o u w i l l d o ( a n d h o w )

    I n t h i s w o r k s h o p y o u w i l l t a k e w h a t y o u d i d i n t h e J P A W o r k s h o p a n d a d d a w o r k i n g

    J S F f r o n t - e n d t o a t a b l e o f t h e d a t a b a s e m o d e l . Y o u w i l l w a r m u p b y i n v e s t i g a t i n g

    t h e J S F l i f e c y c l e . N e x t s t e p w i l l b e t o s t a r t a d d i n g t h e p a g e s n e e d e d f o r a b a s i c ( a n d

    p a r t i a l l y c o m p l e t e ) w e b s h o p . T h e p a g e s w i l l u t i l i z e t h e t e m p l a t i n g f u n c t i o n a l i t y f r o m

    F a c e l e t s a n d e x p l o r e h o w t o c o n n e c t l o g i c a n d f u n c t i o n i n t h e f o r m o f m a n a g e d b e a n s ,

    A J A X , p a g e n a v i g a t i o n a n d b e a n p r o p e r t y v a l i d a t i o n . T h e c o m p o n e n t s f r a m e w o r k w e

    w i l l u s e i s P r i m e F a c e s . W h e n y o u a r e d o n e w i t h t h a t , w e w i l l a l s o e x p l o r e s e r v e r p u s h

    a n d i n v e s t i g a t e a p r a c t i c a l e x a m p l e o f h o w w e c a n t a k e a d v a n t a g e o f i t b y i m p l e m e n t i n g

    a w e b n o t i c e b o a r d . W h a t y o u w i l l l e a r n i n t h i s w o r k s h o p i s q u i t e e x t e n s i v e a n d v e r y

    u s e f u l f o r t h e p r o j e c t .

    F i n a l d a t e

    M o n d a y 3 / 1 0

    P r o j e c t r e l e v a n c e

    I t i s p r e f e r r e d t h a t y o u u t i l i z e J S F o v e r o r d i n a r y s e r v l e t s i n y o u r p r o j e c t a p p l i c a t i o n . U s e

    i t t o g e t h e r w i t h s o m e k i n d o f A J A X f u n c t i o n a l i t y o r a c o m p o n e n t l i b r a r y t h a t s u p p o r t s

    A J A X . U s i n g s e r v e r p u s h i n s o m e c l e v e r w a y i n y o u r a p p l i c a t i o n i s a l s o v e r y b e n e c i a l .

    G e n e r a l T i p s

    C o n f u s i o n c a n o c c u r . T h e r e a r e m u l t i p l e a n n o t a t i o n s f o r M a n a g e d B e a n , S e s s i o n -

    S c o p e e t c . A l w a y s l o o k o u t f o r t h e c o r r e c t p a c k a g e ( f o r n o w : j a v a x . f a c e s ) .

    I f y o u n o t i c e t h a t s o m e a n n o t a t i o n s a r e n ' t w o r k i n g a s e x p e c t e d , c h e c k t h e v e r s i o n

    o f y o u r w e b d e p l o y m e n t d e s c r i p t o r ( w e b . x m l ) . I t s h o u l d b e v 2 . 5 + .

    1

  • 8/3/2019 Workshop Jsf

    2/15

    D i s t r i b u t e d a p p l i c a t i o n s

    A d a m W a l d e n b e r g

    J o a c h i m v o n H a c h t

    I f y o u c a n ' t g e t F a c e l e t s o r n a v i g a t i o n t o w o r k p r o p e r l y , m a k e s u r e t h e v e r s i o n o f

    y o u r f a c e s c o n g u r a t i o n i s r e a l l y s e t t o v 2 . 0 .

    G o t o t h e c o u r s e h o m e p a g e a n d l o o k a t t h e d e m o n s t r a t i o n b e f o r e y o u s t a r t .

    1 T h e J S F R e q u e s t c y c l e

    T h e a i m i s t o u s e a P h a s e L i s t e n e r a n d p h a s e e v e n t s t o g e t s o m e u n d e r s t a n d i n g o f t h e

    J S F r e q u e s t c y c l e .

    1 . D o w n l o a d j s f _ r e q u e s t _ c y c l e _ s a m p l e s . n b p . z i p a n d o p e n i t i n N e t B e a n s .

    2 . I n s p e c t t h e c o d e . R u n t h e a p p l i c a t i o n a n d i n s p e c t t h e G l a s s F i s h o u t p u t w i n d o w .

    3 . T r y t o g e t a g r a s p o f t h e e x e c u t i o n . D o s o m e m i n o r m o d i c a t i o n s a n d e x p l o r e w h a t

    h a p p e n s .

    N O T E T h e U R L p a t t e r n t o t r i g g e r t h e F a c e s S e r v l e t i s . . . / f a c e s / . . . S e e W e l c o m e F i l e i n

    w e b . x m l .

    2 P r e p a r i n g t h e p r o j e c t

    Y o u n e e d t o d o a f e w s i m p l e s t e p s b e f o r e a n y a c t u a l c o d i n g :

    1 . C r e a t e a n e w M a v e n w e b a p p l i c a t i o n w i t h t h e f o l l o w i n g p r o p e r t i e s :

    a ) P r o j e c t N a m e : j s f p r o d u c t s . n b p

    b ) P a c k a g e N a m e : e d u . c h l . c i d . j s f p r o d u c t s

    2 . N e x t , w e n e e d t o c o n g u r e h o w t o d e p l o y a n d w h a t s e r v e r t o u s e . R i g h t c l i c k o n

    t h e p r o j e c t a n d s e l e c t P r o p e r t i e s > R u n .

    a ) S e l e c t G l a s s F i s h a s t h e s e r v e r f o r t h e p r o j e c t .

    b ) C o n t e x t P a t h : / j s f p r o d u c t s

    3 . W e a l s o n e e d t o a d d t h e J a v a S e r v e r F a c e s f r a m e w o r k t o t h e a p p l i c a t i o n . R i g h t

    c l i c k o n t h e p r o j e c t a g a i n a n d s e l e c t P r o p e r t i e s > F r a m e w o r k s .

    a ) A d d J a v a S e r v e r F a c e s t o t h e l i s t o f u s e d f r a m e w o r k s .

    b ) J S F S e r v l e t U R L P a t t e r n : * . j s f

    4 . A s w e w a n t a w o r k i n g d a t a b a s e l a y e r f o r o u r w e b s h o p , y o u w i l l n e e d t o i m p o r t

    s o m e o f t h e w o r k y o u d i d i n t h e p r e v i o u s J P A w o r k s h o p :

    a ) I m p o r t t h e P r o d u c t e n t i t y c l a s s . T h i s w i l l b e u s e d a s t h e m a i n t a b l e i n t h e

    a p p l i c a t i o n w e a r e g o i n g t o m a k e a n d i s t h e o n l y e n t i t y w e w i l l u s e .

    2

  • 8/3/2019 Workshop Jsf

    3/15

    D i s t r i b u t e d a p p l i c a t i o n s

    A d a m W a l d e n b e r g

    J o a c h i m v o n H a c h t

    b ) Y o u w i l l a l s o n e e d t o i m p o r t t h e P r o d u c t c o n t r o l l e r c l a s s f o r p e r s i s t i n g a n d

    q u e r y i n g t h a t y o u c r e a t e d i n { 5 . 1 } i n t h e J P A w o r k s h o p .

    c ) D o n o t f o r g e t t o a d d t h e n e e d e d d e p e n d e n c i e s f o r p e r s i s t e n c e i n t o y o u r p o m . x m l

    ( D e r b y a n d E c l i p s e L i n k ) .

    d ) M a k e s u r e y o u h a v e a w o r k i n g p e r s i s t e n c e u n i t d e n e d .

    5 . A d d a f a c e s - c o n g . x m l t o t h e p r o j e c t . Y o u c a n c r e a t e s u c h a l e u s i n g N e w >

    O t h e r > J a v a S e r v e r F a c e s > J S F F a c e s C o n g u r a t i o n .

    6 . D e l e t e a n y i n d e x . j s p l e ( u n d e r W e b P a g e s ) t h a t w a s a u t o m a t i c a l l y c r e a t e d w i t h

    t h e p r o j e c t .

    7 . A d d t h e f o l l o w i n g t w o f r a g m e n t s t o y o u r p o m . x m l , t a k i n g c a r e o f w h e r e y o u p a s t e

    t h e m :

    < r e p o s i t o r i e s >

    < r e p o s i t o r y >

    < i d > p r i m e r e p o < / i d >

    < n a m e > P r i m e F a c e s M a v e n R e p o s i t o r y < / n a m e >

    < u r l > h t t p : / / r e p o s i t o r y . p r i m e f a c e s . o r g < / u r l >

    < l a y o u t > d e f a u l t < / l a y o u t >

    < / r e p o s i t o r y >

    < / r e p o s i t o r i e s >

    < d e p e n d e n c y >

    < g r o u p I d > o r g . p r i m e f a c e s < / g r o u p I d >

    < a r t i f a c t I d > p r i m e f a c e s < / a r t i f a c t I d >

    < v e r s i o n > 2 . 1 < / v e r s i o n >

    < / d e p e n d e n c y >

    8 . I f y o u r u n a n d d e p l o y t h e p r o j e c t y o u s h o u l d s e e t h e w e l c o m e p a g e . A l s o i n s p e c t

    t h e G l a s s F i s h c o n s o l e f o r a n y e r r o r s .

    3

  • 8/3/2019 Workshop Jsf

    4/15

    D i s t r i b u t e d a p p l i c a t i o n s

    A d a m W a l d e n b e r g

    J o a c h i m v o n H a c h t

    3 M a k i n g a f a c e w i t h F a c e l e t s

    I n t h e w o r k s h o p a b o u t b a s i c w e b a p p l i c a t i o n s y o u d e n e d ( i n c l u d e d ) a h e a d e r a n d f o o t e r

    u s i n g a s i m p l e J S P c o m m a n d . W h i l e t h i s m e t h o d w o r k s , i t i s n ' t v e r y e x i b l e . W i t h

    t h e r e l e a s e o f J S F 2 , t h e F a c e l e t s t e c h n o l o g y b e c a m e s t a n d a r d . T h i s i s a v e r y v e r s a t i l e

    t e c h n o l o g y w h i c h g i v e s u s t h e p o s s i b i l i t y t o c r e a t e t e m p l a t e s , i n c l u d e p a g e f r a g m e n t s

    a n d d e n e c u s t o m t a g l i b r a r i e s . W e w i l l f o c u s o n e x p l o r i n g h o w t o u s e t e m p l a t i n g w i t h

    F a c e l e t s .

    N O T E : D o n ' t f o r g e t a b o u t t h e b r o w s e r c a c h e w h e n w o r k i n g w i t h t h e f o l l o w i n g a s -

    s i g n m e n t . I t c a n r e a l l y p l a y t r i c k s o n y o u ! A l w a y s r e l o a d w h e n s o m e t h i n g t h a t y o u t h i n k

    r e a l l y s h o u l d b e w o r k i n g , i s n ' t w o r k i n g .

    1 . E d i t t h e d e p l o y m e n t d e s c r i p t o r ( w e b . x m l ) i n y o u r p r o j e c t . M o d i f y t h e w e l c o m e

    p a g e t o t h e f o l l o w i n g ( o v e r w r i t e a n y o l d c o n g u r a t i o n ) :

    < w e l c o m e

    f i l e

    l i s t >

    < w e l c o m e f i l e > v i e w P r o d u c t s . j s f < / w e l c o m e f i l e >

    < / w e l c o m e

    f i l e

    l i s t >

    2 . C r e a t e t h r e e p u b l i c p a g e s ; v i e w C a r t . x h t m l , v i e w P r o d u c t s . x h t m l a n d a d -

    d P r o d u c t . x h t m l . T h e s e p a g e s s h o u l d b e s t a n d a r d J S F p a g e s a n d u t i l i z e f a c e l e t s .

    a ) Y o u c a n c r e a t e t h e s e a t N e w > O t h e r > J a v a S e r v e r F a c e s > J S F P a g e . M a k e

    s u r e t h e F a c e l e t s o p t i o n i s s e l e c t e d .

    b ) T o a c c e s s f a c e l e t s y o u n e e d t o a d d t h e f o l l o w i n g n a m e s p a c e :

    x m l n s : u i = " h t t p : / / j a v a . s u n . c o m / j s f / f a c e l e t s " .

    3 . U s e F a c e l e t s t e m p l a t i n g a n d g i v e t h e t h r e e p a g e s a h e a d e r a n d a f o o t e r o f y o u r

    c h o i c e . T h e h e a d e r s h o u l d b e s o m e k i n d o f g r a p h i c a l l o g o ( n d s o m e t h i n g a p p r o -

    p r i a t e u s i n g G o o g l e ) . T h e f o o t e r s h o u l d b e t e x t - b a s e d . T I P : A F a c e l e t s t e m p l a t e

    s h o u l d n o t b e a c c e s s i b l e d i r e c t l y f r o m t h e b r o w s e r . T h i s m e a n s y o u s h o u l d p u t i t

    s o m e w h e r e u n d e r W E B - I N F / , l i k e W E B - I N F / f a c e l e t s / t e m p l a t e . x h t m l .

    a ) A f a c e l e t s t e m p l a t e i s a l s o j u s t a J S F p a g e a n d c a n b e c r e a t e d i n t h e s a m e

    w a y a s t h e t h r e e p u b l i c p a g e s c r e a t e d p r e v i o u l s y .

    b ) T h e t e m p l a t e s h o u l d b e a c o m p l e t e J S F p a g e w i t h a u i : i n s e r t t a g d e n e d .

    T h i s t a g s p e c i e s w h e r e i n t h e t e m p l a t e t h e p a g e s t h a t u s e t h e t e m p l a t e c a n

    p a s t e i n t h e i r c o n t e n t .

    c ) T h e t e m p l a t e s h o u l d d e n e t h e h e a d e r a n d f o o t e r .

    d ) C o n n e c t t h e t h r e e p a g e s t o t h e t e m p l a t e a n d m a k e s u r e y o u g e t c o r r e c t o u t p u t .

    4 . W e w a n t t o g i v e e a c h p a g e a n a p p r o p r i a t e t i t l e a n d h e a d e r ( u s i n g a h 1 t a g ) .

    T h e s e t a g s s h o u l d b e d e n e d i n s i d e t h e t e m p l a t e . U s i n g F a c e l e t s , w e c a n d e n e

    a p a r a m e t e r t h a t w i l l b e s e n t i n t o t h e t e m p l a t e . W e c a n t h e n u s e t h a t d e n e d

    p a r a m e t e r a n d d i s p l a y i t ' s c o n t e n t i n s i d e t h e t a g s .

    4

  • 8/3/2019 Workshop Jsf

    5/15

    D i s t r i b u t e d a p p l i c a t i o n s

    A d a m W a l d e n b e r g

    J o a c h i m v o n H a c h t

    a ) Y o u c a n s e t a p a r a m e t e r u s i n g t h e u i : p a r a m c o m m a n d .

    b ) T h e p a r a m e t e r c a n b e a c c e s s e d f r o m w i t h i n t h e t e m p l a t e u s i n g # { p a r a m e -

    t e r _ n a m e } .

    c ) Y o u s h o u l d o u t p u t y o u r d e n e d p a r a m e t e r i n s i d e t h e h 1 a n d t i t l e t a g s o f t h e

    t e m p l a t e .

    5 . Y o u s h o u l d e n d u p w i t h s o m e t h i n g s o m e w h a t s i m i l a r t o t h e i m a g e b e l o w ( s h o w i n g

    t h e v i e w P r o d u c t s . x h t m l p a g e ) . T h e s h o p i m a g e u s e d i n t h e s c r e e n s h o t c a n b e

    f o u n d a t h t t p : / / c o m m o n s . w i k i m e d i a . o r g / w i k i / F i l e : S h o p . s v g .

    4 A d i s c u s s i o n a b o u t m a n a g e d b e a n s

    B e f o r e w e s t a r t w r i t i n g a n y b e a n s , w e n e e d t o h a v e a s m a l l d i s c u s s i o n a b o u t b e a n s i n

    J S F :

    1 . C a n w e s o m e h o w c a t e g o r i z e t h e d i e r e n t m a n a g e d b e a n s t h a t a r e u s u a l l y u s e d i n

    a t y p i c a l J S F a p p l i c a t i o n ? H o w i s i t a p p r o p r i a t e t o c a t e g o r i z e o u r b e a n a n d u n d e r

    w h i c h s c o p e s h o u l d t h e y b e d e n e d ?

    2 . W h e n d e s i g n i n g a b i g g e r a p p l i c a t i o n i n J S F w e h a v e t o c a r e f u l l y c o n s i d e r w h a t

    k i n d o f b e a n s w e n e e d :

    a ) B a c k i n g B e a n s - C o n n e c t t o a p a g e a n d b a c k u p t h e p r o p e r t i e s o f v i e w s

    ( p a g e s ) . T h u s , t h e n a m e b a c k i n g b e a n . T y p i c a l l y ( b u t n o t n e c e s s a r i l y ) , e a c h

    v i e w h a s e x a c t l y o n e b a c k i n g b e a n c o n n e c t e d t o i t . B a c k i n g b e a n s c a n b e s t o r e d

    i n a l m o s t a n y s c o p e , w i t h t h e e x c e p t i o n o f a p p l i c a t i o n s c o p e . W h a t s c o p e t o

    u s e d e p e n d s o n w h a t y o u w a n t t h e b e a n t o a c h i e v e i n y o u r a p p l i c a t i o n a n d

    w h a t f r a m e w o r k y o u a r e u s i n g . B a c k i n g b e a n s o f t e n c o n n e c t t h e i r p r o p e r t i e s

    t o a d a t a b a s e m o d e l . E a c h c l i e n t t y p i c a l l y g e t s a p r i v a t e l y i n s t a n t i a t e d b a c k i n g

    b e a n w h e n v i e w i n g a p a g e .

    5

  • 8/3/2019 Workshop Jsf

    6/15

    D i s t r i b u t e d a p p l i c a t i o n s

    A d a m W a l d e n b e r g

    J o a c h i m v o n H a c h t

    b ) C o n t r o l l e r B e a n s - T h e s e b e a n s e i t h e r h a n d l e n a v i g a t i o n o r i m p l e m e n t l i s -

    t e n e r s u s e d i n v i e w s . I n t h e l a t t e r c a s e , c o n t r o l l e r b e a n s o f t e n m o d i f y p r o p e r -

    t i e s o f t h e m o d e l o r t h e b a c k i n g b e a n t h e y a r e a s s o c i a t e d w i t h , w h e n a c e r t a i n

    e v e n t h a p p e n s . U s u a l l y s t o r e d i n t h e s a m e s c o p e a s t h e b a c k i n g b e a n ( s ) t h e y

    a r e c o n n e c t e d t o .

    c ) M o d e l B e a n s - P u r e m o d e l b e a n s t h a t h o l d p r o p e r t i e s t h a t a r e c o m m o n f o r

    t h e a p p l i c a t i o n o r c l i e n t . T h e s e b e a n s h o l d m o d e l p r o p e r t i e s t h a t w e d o n o t

    ( o r s h o u l d n o t ) p u t i n s i d e a d a t a b a s e . U s u a l l y d e n e d i n s e s s i o n o r a p p l i c a t i o n

    s c o p e .

    d ) S u p p o r t B e a n s - T h e s e b e a n s a r e s i m i l a r t o m o d e l b e a n s , b u t a r e u s e d

    s p e c i c a l l y t o s u p p o r t c o m p o n e n t s s h o w n i n a v i e w . T h e y a r e o f t e n t i g h t l y

    c o u p l e d t o t h e v i e w , r e t u r n i n g d a t a t h a t i s s p e c i a l i z e d t o t h e v i e w i t s e l f . T h e y

    c a n a l s o b e u s e d a s a c o n t a i n e r w h e n d e v e l o p i n g c u s t o m c o m p o n e n t s . T h e s e

    b e a n s u s u a l l y d o n ' t h a v e a n y w r i t a b l e p r o p e r t i e s a n d a r e a l m o s t a l w a y s d e n e d

    i n a p p l i c a t i o n s c o p e t o s a v e m e m o r y i n t h e a p p l i c a t i o n s e r v e r . T h i s w a y

    i n s t a n c e s c a n b e s h a r e d b e t w e e n c l i e n t s .

    e ) U t i l i t y B e a n s - C o n t a i n h e l p e r m e t h o d s t h a t c a n b e u s e d b y o t h e r b e a n s .

    U s u a l l y d e n e d i n a p p l i c a t i o n s c o p e .

    Backing Bean

    View

    ControllerController Bean

    Model Bean

    Model

    3 . S o w h y s h o u l d w e d i v i d e o u r b e a n s i n t h e a b o v e ( o r s o m e o t h e r s i m i l a r ) m a n n e r ?

    a ) W e w a n t t o c l e a r l y d i v i d e o u r a p p l i c a t i o n i n t o l o g i c a l p a r t s .

    b ) W e w a n t t o m i n i m i z e r e s o u r c e u s e ( s u c h a s m e m o r y ) .

    c ) W e w a n t t o t a k e t h e M V C p a t t e r n i n t o c o n s i d e r a t i o n .

    4 . A c o m m o n m i s t a k e i s t h a t p r o g r a m m e r s o f t e n p u t a l l t h e i r b a c k i n g b e a n s i n t o

    s e s s i o n s c o p e ( e v e n i f t h i s i s n o t n e e d e d ) a n d i n j e c t t h e m i n t o e a c h o t h e r . W h y i s

    t h i s m o s t l y a b a d i d e a ?

    6

  • 8/3/2019 Workshop Jsf

    7/15

    D i s t r i b u t e d a p p l i c a t i o n s

    A d a m W a l d e n b e r g

    J o a c h i m v o n H a c h t

    5 . I f y o u r @ A p p l i c a t i o n S c o p e d b e a n i s n o t i m m u t a b l e , y o u h a v e t o c o n s i d e r

    t h r e a d - s a f e t y .

    6 . T o d e n e m a n a g e d b e a n s , u s e t h e @ M a n a g e d B e a n a n n o t a t i o n . W h e n y o u w a n t t o

    i n j e c t o n e b e a n i n t o a n o t h e r y o u c a n u s e @ M a n a g e d P r o p e r t y t o g e t h e r w i t h a s e t t e r

    a n d g e t t e r .

    5 U s i n g m a n a g e d b e a n s

    N o w i t ' s t i m e t o u s e t h e i n f o r m a t i o n d i s c u s s e d i n { 4 } a n d a c t u a l l y i m p l e m e n t s o m e t h i n g

    u s i n g J S F .

    1 . W h a t w e w a n t t o d o r s t , i s t o m o d i f y t h e t e m p l a t e w e d i d i n { 3 } a n d o u t p u t t h e

    c u r r e n t d a t e a n d t i m e i n s i d e t h e f o o t e r . F o r t h i s w e n e e d t o u s e a b e a n .

    a ) A d d a J S F b e a n D a t e T i m e < b e a n T y p e > B e a n . j a v a , w h e r e < b e a n T y p e > i s t h e

    t y p e o f b e a n t o u s e . C o n s i d e r c a r e f u l l y w h a t t y p e o f b e a n i s m o s t a p p r o p r i -

    a t e . R e m e m b e r t h a t w e w a n t t o m i n i m i z e r e s o u r c e u s e . D e n e t h e f o l l o w i n g

    m e t h o d i n s i d e :

    g e t C u r r e n t D a t e T i m e ( ) - R e t u r n s a s t r i n g w i t h t h e c u r r e n t d a t e a n d t i m e

    ( i n c l u d i n g s e c o n d s ) .

    b ) U s e a n n o t a t i o n s t o a n n o t a t e t h e b e a n a n d d e n e w h a t s c o p e i t s h o u l d u s e .

    C a r e f u l l y c o n s i d e r w h a t t y p e o f s c o p e y o u n e e d .

    c ) M o d i f y t h e t e m p l a t e s o t h a t i t f e t c h e s t h e c u r r e n t t i m e f r o m t h e b e a n a n d

    p u t s i t i n t o t h e f o o t e r . R e d e n e t h e f o o t e r a s a < h : o u t p u t T e x t > t a g .

    d ) S t y l e t h e o u t p u t T e x t t a g w i t h s o m e C S S t h a t c h a n g e s t h e c o l o u r t o s i e n n a

    a n d m a k e s t h e f o n t s m a l l e r .

    2 . T h e p u b l i c p a g e s v i e w C a r t . x h t m l , v i e w P r o d u c t s . x h t m l a n d a d d P r o d u c t . x h t m l

    s h o u l d a l l h a v e a m a n a g e d b e a n c o n n e c t e d t o t h e m . Y o u r t a s k i s t o c o n n e c t

    t h e r i g h t t y p e o f m a n a g e d b e a n t o e a c h p a g e ( v i e w ) . N a m e y o u r c l a s s e s V i e w -

    C a r t < b e a n T y p e > B e a n . j a v a , V i e w P r o d u c t s < b e a n T y p e > B e a n . j a v a a n d s o o n . I n

    a l a t e r a s s i g n m e n t , y o u w i l l u s e t h e d a t a s u b m i t t e d i n t h o s e b e a n s t o a c c o m p l i s h

    n a v i g a t i o n a n d o t h e r a c t i o n s w h e n a f o r m i s s u b m i t t e d . A f t e r t h a t , t h e d a t a f r o m

    t h e b e a n s i s n o l o n g e r n e e d e d . W h a t i s t h e m o s t a p p r o p r i a t e s c o p e f o r t h e t h r e e

    b e a n s ?

    3 . C r e a t e a s h o p p i n g c a r t . T h e c l a s s s h o u l d h o l d a l i s t o f p r o d u c t s t h a t h a v e b e e n

    a d d e d t o t h e c a r t . T h e s h o p p i n g c a r t c l a s s s h o u l d b e a m a n a g e d b e a n o f s o m e

    k i n d . T h e q u e s t i o n i s , w h a t k i n d ? B o t h t h e v i e w p r o d u c t s p a g e a n d t h e v i e w c a r t

    p a g e w i l l b e a b l e t o e m p t y t h e c a r t . A l s o c o n s i d e r w h a t s c o p e i s m o s t a p p r o p r i a t e

    f o r t h i s b e a n . Y o u w i l l c o n n e c t t h e s h o p p i n g c a r t b e a n t o t h e a p p l i c a t i o n a t a l a t e r

    s t a g e .

    7

  • 8/3/2019 Workshop Jsf

    8/15

    D i s t r i b u t e d a p p l i c a t i o n s

    A d a m W a l d e n b e r g

    J o a c h i m v o n H a c h t

    4 . N e x t , w e w i l l a d d s o m e s t a n d a r d J S F c o m p o n e n t s t o a l l t h r e e p a g e s . U s e s t a n d a r d

    J S F c o m p o n e n t s f o r t h e f o r m s ( h : c o m p o n e n t N a m e ) . M a k e s u r e y o u c o n n e c t t h e

    v a l u e s o f t h e c o m p o n e n t s t o a p r o p e r t y i n a m a n a g e d b e a n .

    a ) v i e w P r o d u c t s . x h t m l - T h i s p a g e w i l l l a t e r b e e x t e n d e d w i t h f u n c t i o n a l i t y

    f r o m P r i m e F a c e s . F o r n o w , j u s t m a k e s u r e t h e p a g e h a s a f o r m w i t h t h e

    f o l l o w i n g c o m p o n e n t :

    A b u t t o n f o r n a v i g a t i n g t o a d d P r o d u c t . x h t m l .

    A b u t t o n f o r n a v i g a t i n g t o v i e w C a r t . x h m t l .

    A b u t t o n f o r e m p t y i n g t h e s h o p p i n g c a r t .

    A n o u t p u t t e x t d e s c r i b i n g t h e n u m b e r o f i t e m s c u r r e n t l y i n t h e s h o p p i n g

    c a r t .

    b ) v i e w C a r t . x h t m l - W i l l a l s o u s e P r i m e F a c e s l a t e r . A d d a f o r m w i t h t h e

    f o l l o w i n g c o m p o n e n t t o t h e p a g e :

    A b u t t o n f o r n a v i g a t i n g t o v i e w P r o d u c t s . x h t m l .

    A b u t t o n f o r e m p t y i n g a s h o p p i n g c a r t a n d t h e n n a v i g a t i n g t o v i e w -

    P r o d u c t s . x h t m l .

    A n o u t p u t t e x t d e s c r i b i n g t h e n u m b e r o f i t e m s c u r r e n t l y i n t h e s h o p p i n g

    c a r t .

    c ) a d d P r o d u c t . x h t m l - C r e a t e a s i m p l e f o r m t h a t c a n b e u s e d t o a d d a p r o d u c t .

    A d d t h e f o l l o w i n g c o m p o n e n t s :

    A t e x t e l d f o r e n t e r i n g a p r o d u c t n a m e .

    A t e x t e l d f o r e n t e r i n g a p r o d u c t c a t e g o r y .

    A t e x t e l d f o r e n t e r i n g a p r i c e .

    A s u b m i t ( a d d p r o d u c t ) b u t t o n .

    5 . C o n n e c t t h e c o m p o n e n t s t o p r o p e r t i e s i n t h e m a n a g e d b e a n s ( w h e r e i t ' s n e e d e d ) .

    6 . Y o u s h o u l d n o w h a v e t h r e e p a g e s t h a t s h o w s o m e c o n t e n t b u t d o n ' t r e a l l y d o

    a n y t h i n g y e t . T o a d d s o m e l i f e t o t h e m , w e n e e d t o a d d s o m e n a v i g a t i o n r u l e s a n d

    c o n t r o l l e r s . . .

    8

  • 8/3/2019 Workshop Jsf

    9/15

    D i s t r i b u t e d a p p l i c a t i o n s

    A d a m W a l d e n b e r g

    J o a c h i m v o n H a c h t

    6 N a v i g a t i o n a n d c o n t r o l l e r b e a n s

    N o w t h a t y o u h a v e d e n e d y o u r r s t w o r k i n g b e a n s , i t ' s t i m e t o c o n t i n u e a n d a d d n a v i -

    g a t i o n r u l e s t o y o u r p a g e s . L o o k a t t h e f o l l o w i n g d i a g r a m :

    viewCart.xhtml

    viewProducts.xhtml

    addProduct.xhtml

    onViewProducts

    onAddProduct

    onViewAddProduct

    onViewCartonEmptpyCart

    1 . Y o u r t a s k i s t o a d d n a v i g a t i o n r u l e s i n s i d e f a c e s - c o n g . x m l t h a t w o r k i n t h e a b o v e

    m a n n e r . Y o u c a n e i t h e r w r i t e t h e r u l e s b y h a n d o r u s e t h e p a g e o w e d i t o r i n

    N e t B e a n s , w h i c h c a n b e f o u n d w h e n y o u d o u b l e c l i c k o n t h e f a c e s - c o n g . x m l l e .

    W h e n s o m e o n e a d d s a p r o d u c t , t h e v i e w p r o d u c t s p a g e s h o u l d b e s h o w n . A d d a

    r u l e t h a t c a n b e u s e d t o s e n d t h e b r o w s e r f r o m t h e v i e w p r o d u c t s p a g e t o t h e a d d

    p r o d u c t p a g e w h e n t h e b u t t o n i n t h e f o r m e r p a g e i s p r e s s e d . T h e r e s h o u l d a l s o

    b e s i m i l a r r u l e s t h a t c o n n e c t t h e v i e w c a r t p a g e w i t h t h e v i e w p r o d u c t s p a g e , a s

    d e s c r i b e d b y t h e d i a g r a m .

    2 . O n c e t h e n a v i g a t i o n r u l e s f o r a l l p a g e s a r e s e t u p , y o u n e e d t o a c t u a l l y i m p l e m e n t

    e a c h c o n t r o l l e r b e a n p r o p e r l y . N a v i g a t i o n s h o u l d b e a c c o m p l i s h e d b y u s i n g t h e

    o u t c o m e s o f t h e n a v i g a t i o n r u l e s d e n e d i n f a c e s - c o n g . x m l . Y o u s h o u l d r e a l i z e

    t h a t y o u d o n o t h a v e t o c o n n e c t a l l t h e n a v i g a t i o n c o m p o n e n t s t o a n

    a c t u a l c o n t r o l l e r m e t h o d . Y o u s h o u l d o n l y d o t h i s w h e n y o u r e a l l y n e e d

    i t . T h i s w a y , i f y o u n e e d t o m a k e s i m p l e c h a n g e s , y o u w o n ' t h a v e t o r e c o m p i l e .

    a ) A d d P r o d u c t C o n t r o l l e r B e a n - W h e n t h e s u b m i t b u t t o n i s p r e s s e d , a d d

    t h e p r o d u c t t o t h e d a t a b a s e a n d n a v i g a t e t o t h e v i e w p r o d u c t s p a g e . Y o u w i l l

    h a v e t o a c c e s s t h e m a n a g e d b e a n t h a t h o l d s p r o p e r t i e s f o r t h e p a g e t h a t t h i s

    c o n t r o l l e r i s c o n n e c t e d t o .

    b ) V i e w C a r t C o n t r o l l e r B e a n - I f t h e u s e r p r e s s e s t h e b u t t o n f o r e m p t y i n g t h e

    c a r t , i n v a l i d a t e t h e s e s s i o n a n d t h e n n a v i g a t e t o t h e v i e w p r o d u c t s p a g e . T I P :

    F a c e s C o n t e x t . g e t C u r r e n t I n s t a n c e ( ) . g e t E x t e r n a l C o n t e x t ( ) - . g e t S e s s i o n ( . . . ) . . .

    c ) V i e w P r o d u c t s C o n t r o l l e r B e a n - Y o u s h o u l d i n v a l i d a t e t h e s e s s i o n a n d r e l o a d

    t h e p a g e w h e n t h e b u t t o n f o r e m p t y i n g t h e c a r t i s p r e s s e d .

    9

  • 8/3/2019 Workshop Jsf

    10/15

    D i s t r i b u t e d a p p l i c a t i o n s

    A d a m W a l d e n b e r g

    J o a c h i m v o n H a c h t

    3 . Y o u s h o u l d n o w h a v e a w o r k i n g a p p l i c a t i o n w h e r e y o u c a n a d d p r o d u c t s t o t h e

    d a t a b a s e a n d n a v i g a t e t h e p a g e s ( e v e n i f y o u c a n ' t v i e w t h e c a r t o r t h e p r o d u c t s

    y e t ) .

    7 W h a t a b o u t A J A X i n J S F ?

    T h e t e m p l a t e f o o t e r o u t p u t t i n g t h e c u r r e n t t i m e i s v e r y s t a t i c a n d o n l y u p d a t e s i f t h e

    p a g e i s r e l o a d e d . L e t ' s m o d i f y i t s o t h a t t h e f o o t e r u p d a t e s o n c e e v e r y v e s e c o n d s o r

    w h e n e v e r a b u t t o n i s c l i c k e d . W e c a n a c c o m p l i s h t h i s b y u s i n g a n f : a j a x t a g a n d s o m e

    v e r y s i m p l e J a v a S c r i p t .

    1 . T o s t a r t w i t h , a d d a b u t t o n t h a t , w h e n c l i c k e d , u p d a t e s t h e f o o t e r .

    a ) F i r s t , a d d a h : c o m m a n d B u t t o n w i t h t h e t e x t U p d a t e f o o t e r .

    b ) C o n n e c t a f : a j a x e v e n t t o t h e b u t t o n . W h e n t h e b u t t o n i s c l i c k e d , i t s h o u l d

    u p d a t e t h e h : o u t p u t T e x t t a g t h a t o u t p u t s t h e d a t e a n d t i m e . N O T E :

    U p d a t e o n l y t h e h : o u t p u t T e x t a n d n o o t h e r p a r t o f t h e p a g e .

    2 . ( O P T I O N A L ) Y o u r n e x t t a s k i s t o r e f r e s h t h e f o o t e r o n c e e v e r y v e s e c o n d s . Y o u

    h a v e t o a d d t h e J a v a S c r i p t t h a t h a n d l e s t h i s i n a n u n o b t r u s i v e m a n n e r . T h e t r i g -

    g e r i n g o f t h e u p d a t e c a n b e s o l v e d b y e x e c u t i n g a r e q u e s t f o r a n u p d a t e e v e r y v e

    s e c o n d u s i n g j s f . a j a x . r e q u e s t ( ) . T h i s f u n c t i o n c a n b e f o u n d i n s i d e a J a v a S c r i p t

    l i b r a r y i n c l u d e d i n J S F 2 ; j s f . j s . W h e n e v e r t h e f a c e s s e r v l e t d e t e c t s f : a j a x t a g s

    u p o n l o a d i n g , t h i s J a v a S c r i p t l e s h o u l d b e i n c l u d e d i n t h e h e a d e r a u t o m a t i c a l l y ,

    m e a n i n g w e d o n ' t h a v e t o i n c l u d e i t m a n u a l l y i n t h e t e m p l a t e . I n s p e c t t h e d o c u -

    m e n t a t i o n f o r j s f . a j a x . r e q u e s t ( ) a n d r e a n u p d a t e o f t h e h : o u t p u t T e x t i n s i d e

    t h e f o o t e r o n c e e v e r y v e s e c o n d s .

    3 . ( O P T I O N A L ) I f y o u h a p p e n t o r e l o a d t h e p a g e a t t h e e x a c t m o m e n t a r e q u e s t i s

    m a d e u s i n g j s f . a j a x . r e q u e s t ( ) , t h a t r e q u e s t w i l l b e i n t e r r u p t e d a n d a n a n n o y i n g

    1 0

  • 8/3/2019 Workshop Jsf

    11/15

    D i s t r i b u t e d a p p l i c a t i o n s

    A d a m W a l d e n b e r g

    J o a c h i m v o n H a c h t

    h t t p E r r o r a l e r t w i l l p o p u p . T h i s i s b e c a u s e t h e r e i s s o m e d e b u g g i n g c o d e p r e s e n t

    i n s i d e j s f . j s f o r c a s e s w h e r e t h i s h a p p e n s o n a n a c t u a l l i v e p a g e ( n o t w h e n r e l o a d i n g

    i n t h e b r o w s e r ) . T h i s a l e r t c a n b e d i s a b l e d i n a n a l a p p l i c a t i o n b y c h a n g i n g t h e

    p r o j e c t s t a g e t o p r o d u c t i o n s t a t u s b y m o d i f y i n g w e b . x m l . N O T E : T h i s s h o u l d

    o n l y b e d o n e i n a n a l r e l e a s e :

    < c o n t e x t

    p a r a m >

    < p a r a m

    n a m e > j a v a x . f a c e s . P R O J E C T _ S T A G E < / p a r a m

    n a m e >

    < p a r a m

    v a l u e > P r o d u c t i o n < / p a r a m

    v a l u e >

    < / c o n t e x t

    p a r a m >

    8 T a k i n g i t o n e s t e p f u r t h e r w i t h P r i m e F a c e s

    A d d i n g A J A X f u n c t i o n a l i t y c o m p l e t e l y o n y o u r o w n u s i n g f : a j a x , a s y o u d i d i n t h e

    p r e v i o u s a s s i g n m e n t , w o r k s . H o w e v e r , t h i s m e a n s t h a t y o u h a v e t o m a k e y o u r o w n c u s t o m

    c o m p o n e n t s i f y o u d e c i d e t o b u i l d y o u r a p p l i c a t i o n c o m p l e t e l y i n t h i s m a n n e r . T h i s o f

    c o u r s e m e a n s e x t r a w o r k . W h e n d o i n g s o m e o f t h e a s s i g n m e n t s i n t h e R I A W o r k s h o p ,

    y o u g o t t o u s e o n e o f t h e b e s t J a v a S c r i p t l i b r a r i e s a v a i l a b l e ; J Q u e r y . P r i m e F a c e s i s a

    c o m p o n e n t s u i t e f o r J S F , t h e c o m p o n e n t a r e i m p l e m e n t e d u s i n g J Q u e r y . M a n y u p d a t e s

    i n P r i m e F a c e s c o m p o n e n t s a r e a u t o m a t i c ( o r u s e a n u p d a t e t a g ) a n d d o n o t r e q u i r e t h e

    u s e o f f : a j a x t o g e t f u l l A J A X f u n c t i o n a l i t y .

    1 . M o d i f y t h e v i e w P r o d u c t s . x h t m l p a g e t o u s e P r i m e F a c e s c o m p o n e n t s a n d a d d a

    P r i m e F a c e s t a b l e . I n t h i s t a b l e , v i e w a l l t h e p r o d u c t s t h a t h a v e b e e n a d d e d t o t h e

    d a t a b a s e :

    a ) Y o u s h o u l d h a v e c o l u m n s i n t h e t a b l e f o r a l l t h e e l d s i n a p r o d u c t ( s u c h a s

    t h e p r o d u c t n a m e a n d c a t e g o r y ) .

    b ) Y o u d o n o t h a v e t o s u p p o r t p a g i n a t i o n .

    c ) W h e n p r e s s i n g t h e h e a d e r s o f t h e t a b l e , t h e i t e m s s h o u l d b e s o r t e d a c c o r d i n g

    t o t h e p r e s s e d c o l u m n .

    d ) E a c h r o w i n t h e t a b l e s h o u l d h a v e t w o b u t t o n s :

    O n e b u t t o n f o r r e m o v i n g t h e p r o d u c t o n t h a t r o w f r o m t h e d a t a b a s e .

    W h e n a p r o d u c t i s r e m o v e d , i t ' s r e f e r e n c e s i n t h e s h o p p i n g c a r t s h o u l d

    a l s o b e r e m o v e d .

    A n o t h e r b u t t o n f o r a d d i n g a p r o d u c t t o t h e s h o p p i n g c a r t .

    T h e r e i s a b u g i n P r i m e F a c e s 2 . 1 t h a t r e s u l t s i n a t a b l e n o t u p d a t i n g i f t h e

    b u t t o n w i t h t h e a c t i o n L i s t e n e r i s i n s i d e a c e l l i n t h e t a b l e . T o w o r k a r o u n d

    t h i s , y o u c a n u s e u p d a t e = " @ f o r m " w h e n d e n i n g t h e a c t i o n L i s t e n e r . T h i s

    w i l l f o r c e a n u p d a t e t o t h e w h o l e f o r m . A n o t h e r s o l u t i o n i s t o w r a p t h e t a b l e

    i n s i d e s o m e t h i n g l i k e a p : o u t p u t P a n e l a n d r e f e r e n c e t h a t p a n e l f r o m t h e

    u p d a t e a t t r i b u t e .

    1 1

  • 8/3/2019 Workshop Jsf

    12/15

    D i s t r i b u t e d a p p l i c a t i o n s

    A d a m W a l d e n b e r g

    J o a c h i m v o n H a c h t

    2 . A d d a s i m i l a r P r i m e F a c e s t a b l e t o t h e v i e w C a r t . x h t m l p a g e . S i m i l a r r e q u i r e -

    m e n t s a r e p r e s e n t h e r e a s i n t h e t a b l e m e n t i o n e d e a r l i e r . T h e d i e r e n c e i s o f c o u r s e

    t h a t t h i s t a b l e s h o u l d i n s t e a d d i s p l a y i t e m s i n t h e s h o p p i n g c a r t . I n t h i s t a b l e

    y o u w i l l o n l y r e q u i r e o n e b u t t o n o n e a c h r o w ( f o r r e m o v i n g t h e p r o d u c t f r o m t h e

    s h o p p i n g c a r t ) .

    9 V a l i d a t i n g b e a n p r o p e r t i e s

    N e x t , w e w i l l a d d b e a n p r o p e r t y v a l i d a t i o n t o o n e o f t h e p a g e s . W h i l e i t ' s p o s s i b l e t o

    d e n e c u s t o m v a l i d a t o r s y o u s h o u l d u s e t h e a n n o t a t i o n s t h a t a r e a v a i l a b l e i n J S F . T h e y

    c o v e r t h e m o s t c o m m o n v a l i d a t i o n s n e e d e d .

    1 . M o d i f y a d d P r o d u c t . x h t m l t o u s e P r i m e F a c e s c o m p o n e n t s . T h e a d v a n t a g e o f

    u s i n g P r i m e F a c e s c o m p o n e n t s i s t h a t w e c a n v a l i d a t e i n r e a l - t i m e u s i n g A J A X

    w h e n e v e r t h a t f u n c t i o n a l i t y i s n e e d e d .

    2 . A d d a n n o t a t i o n s t o t h e p r o p e r t i e s o f t h e a d d p r o d u c t p a g e . T h e f o l l o w i n g s h o u l d

    h o l d :

    a ) T h e p r i c e s h o u l d b e a v a l i d n u m b e r ( w i t h o r w i t h o u t d e c i m a l s ) .

    b ) T h e p r o d u c t n a m e h a s t o b e a t l e a s t 3 c h a r a c t e r s l o n g a n d c a n ' t b e e m p t y .

    c ) T h e p r o d u c t c a t e g o r y c a n b e e m p t y .

    3 . W h e n y o u t r y t o s u b m i t a n i n c o r r e c t f o r m i n a d d P r o d u c t . x h t m l , t h e r e s h o u l d

    b e a n e r r o r m e s s a g e s h o w n n e x t t o t h e e n t r y w h e r e a n e r r o r w a s f o u n d .

    4 . F o r t h i s t o u p d a t e w i t h A J A X , y o u n e e d t o a c t u a l l y u s e P r i m e F a c e s c o m p o n e n t s

    f o r e v e r y t h i n g a n d s p e c i f y t h e a r e a t o u p d a t e w h e n e v e r t h e p : c o m m a n d B u t t o n

    i s p r e s s e d ( s e e t h e u p d a t e a t t r i b u t e ) . P u t a l l t h e c o m p o n e n t s t h a t h a v e m e s s a g e s

    a t t a c h e d i n s i d e a p : p a n e l a n d g i v e t h e p a n e l a n i d . Y o u c a n t h e n r e f e r e n c e t h a t

    p a n e l f r o m t h e c o m m a n d b u t t o n .

    5 . A s y o u m i g h t h a v e n o t i c e d , t h e v a l i d a t i o n d o e s n ' t r u n u n t i l y o u a c t u a l l y p r e s s t h e

    c o m m a n d b u t t o n . T h i s c a n b e i m p r o v e d b y u s i n g J a v a S c r i p t a n d a d d i n g a f o r m

    s u b m i s s i o n c a l l t o t h e o n b l u r a t t r i b u t e o f e a c h i n p u t T e x t . Y o u c a n a l s o u s e p : a j a x

    w i t h o n b l u r t o v a l i d a t e t h e f o r m a s y n c h r o n o u s l y w i t h A J A X a n d a c h i e v e a s i m i l a r

    e e c t .

    1 0 S e r v e r p u s h w i t h I C E F a c e s ( O P T I O N A L )

    S e r v e r p u s h s i m p l y m e a n s t h a t t h e s e r v e r c a n c o n t i n u o u s l y p u s h d a t a t o t h e c l i e n t . T h e

    c l i e n t c a n t h e n f e t c h t h e d a t a a n d u p d a t e i t ' s v i e w a c c o r d i n g l y . T h i s f u n c t i o n a l i t y i s

    i m p l e m e n t e d d i e r e n t l y i n d i e r e n t c o m p o n e n t l i b r a r i e s . S o m e u s e p e r s i s t e n t c o n n e c -

    t i o n s , w h i l e o t h e r s u s e p o l l i n g o n t h e c l i e n t s i d e . W h i l e s e r v e r p u s h i s i m p l e m e n t e d

    i n P r i m e F a c e s , i t i s n ' t a s r o b u s t a s t h e i m p l e m e n t a t i o n i n I C E F a c e s a n d r e q u i r e s m o r e

    1 2

  • 8/3/2019 Workshop Jsf

    13/15

    D i s t r i b u t e d a p p l i c a t i o n s

    A d a m W a l d e n b e r g

    J o a c h i m v o n H a c h t

    w o r k f r o m t h e p r o g r a m m e r t h a n i t ' s c o u n t e r p a r t i n I C E F a c e s . T h e r e f o r e , w e w i l l u s e

    I C E F a c e s t o d e m o n s t r a t e a p r a c t i c a l e x a m p l e o f h o w s e r v e r p u s h c a n b e u s e d . Y o u w i l l

    i m p l e m e n t a v e r y s i m p l e w e b b a s e d n o t i c e b o a r d u s i n g I C E F a c e s a n d i t ' s S e s s i o n R e n d e r e r

    c l a s s . D i e r e n t b r o w s e r s w i l l b e a b l e t o s h a r e t h e s a m e n o t i c e b o a r d a n d s e e c h a n g e s i n

    r e a l - t i m e .

    1 . C r e a t e a n e w M a v e n w e b a p p l i c a t i o n c a l l e d j s f n o t i c e b o a r d . n b p .

    2 . T h e c e n t r a l M a v e n r e p o s i t o r y s e e m s t o b e m i s s i n g t h e I C E F a c e s p u s h s e r v e r . T h e r e -

    f o r e , w e h a v e t o a d d t h e I C E F a c e s r e p o s i t o r y i n o r d e r t o g e t a c c e s s t o i t . A d d t h e

    f o l l o w i n g d e p e n d e n c i e s t o y o u r p o m . x m l :

    < r e p o s i t o r i e s >

    < r e p o s i t o r y >

    < i d > I C E F a c e s M a v e n R e p o < / i d >

    < u r l > h t t p : / / a n o n s v n . i c e f a c e s . o r g / r e p o / m a v e n 2 / r e l e a s e s / < / u r l >

    < / r e p o s i t o r y >

    < / r e p o s i t o r i e s >

    < d e p e n d e n c y >

    < g r o u p I d > o r g . i c e f a c e s < / g r o u p I d >

    < a r t i f a c t I d > i c e f a c e s < / a r t i f a c t I d >

    < v e r s i o n > 2 . 0 . 2 < / v e r s i o n >

    < e x c l u s i o n s >

    < e x c l u s i o n >

    < g r o u p I d > j a v a x . f a c e s < / g r o u p I d >

    < a r t i f a c t I d > j s f

    i m p l < / a r t i f a c t I d >

    < / e x c l u s i o n >

    < e x c l u s i o n >

    < g r o u p I d > j a v a x . f a c e s < / g r o u p I d >

    < a r t i f a c t I d > j s f a p i < / a r t i f a c t I d >

    < / e x c l u s i o n >

    < / e x c l u s i o n s >

    < / d e p e n d e n c y >

    < d e p e n d e n c y >

    < g r o u p I d > o r g . i c e f a c e s < / g r o u p I d >

    < a r t i f a c t I d > i c e f a c e s c o m p a t < / a r t i f a c t I d >

    < v e r s i o n > 2 . 0 . 2 < / v e r s i o n >

    < / d e p e n d e n c y >

    < d e p e n d e n c y >

    < g r o u p I d > o r g . i c e f a c e s < / g r o u p I d >

    < a r t i f a c t I d > i c e f a c e s a c e < / a r t i f a c t I d >

    < v e r s i o n > 2 . 0 . 2 < / v e r s i o n >

    < / d e p e n d e n c y >

    < d e p e n d e n c y >

    < g r o u p I d > o r g . i c e p u s h < / g r o u p I d >

    < a r t i f a c t I d > i c e p u s h < / a r t i f a c t I d >

    < v e r s i o n > 2 . 0 . 2 < / v e r s i o n >

    < / d e p e n d e n c y >

    3 . R e m o v e i n d e x . j s p a n d r e p l a c e i t w i t h a n i n d e x . x h t m l p a g e . M a k e s u r e t h e r e i s

    a v a l i d w e b . x m l . A l s o m a k e s u r e t h a t t h e i n d e x p a g e i s t h e d e f a u l t w e l c o m e p a g e

    a n d a l s o a d d t h e f o l l o w i n g t o w e b . x m l :

    1 3

  • 8/3/2019 Workshop Jsf

    14/15

    D i s t r i b u t e d a p p l i c a t i o n s

    A d a m W a l d e n b e r g

    J o a c h i m v o n H a c h t

    < s e r v l e t >

    < s e r v l e t

    n a m e > R e s o u r c e S e r v l e t < / s e r v l e t

    n a m e >

    < s e r v l e t

    c l a s s >

    c o m . i c e s o f t . f a c e s . w e b a p p . C o m p a t R e s o u r c e S e r v l e t

    < / s e r v l e t

    c l a s s >

    < l o a d

    o n

    s t a r t u p > 1 < / l o a d

    o n

    s t a r t u p >

    < / s e r v l e t >

    < s e r v l e t

    m a p p i n g >

    < s e r v l e t

    n a m e > R e s o u r c e S e r v l e t < / s e r v l e t

    n a m e >

    < u r l

    p a t t e r n > / x m l h t t p /

    < / u r l

    p a t t e r n >

    < / s e r v l e t

    m a p p i n g >

    4 . A d d a v e r s i o n 2 f a c e s - c o n g . x m l , l i k e y o u d i d i n t h e p r e v i o u s p r o j e c t .

    5 . I n t h e i n d e x p a g e , a d d t h e f o l l o w i n g :

    a ) A h e a d e r d e s c r i b i n g t h e p a g e .

    b ) A n I C E F a c e s s e r i e s p a n e l t h a t c a n h o l d a n a r b i t r a r y n u m b e r o f n o t i c e s ( e l e -

    m e n t s ) . Y o u c a n n d m o r e i n f o r m a t i o n a b o u t h o w t h e s e r i e s p a n e l i n I C E -

    F a c e s w o r k s a t t h e I C E F a c e s C o m p o n e n t s S h o w c a s e s i t e ; h t t p : / / c o m p o n e n t -

    s h o w c a s e . i c e f a c e s . o r g / . I n s i d e e a c h n o t i c e i n t h e s e r i e s p a n e l y o u s h o u l d p u t

    a r e m o v a l b u t t o n o f s o m e k i n d ( f o r r e m o v i n g t h e n o t i c e ) .

    c ) A t e x t e n t r y ( w h e r e a n e w n o t i c e c a n b e e n t e r e d ) a n d a b u t t o n t o s u b m i t t h a t

    n o t i c e t o t h e n o t i c e b o a r d .

    6 . C r e a t e t h e m o d e l b e a n N o t i c e B o a r d M o d e l B e a n . j a v a , t h a t h o l d s a c e r t a i n a m o u n t

    o f n o t i c e s p o s t e d t o t h e n o t i c e b o a r d . W h a t i s t h e a p p r o p r i a t e s c o p e f o r t h i s b e a n ?

    E a c h n o t i c e i n t h e m o d e l s h o u l d h o l d t h e f o l l o w i n g i n f o r m a t i o n :

    a ) T h e n o t i c e ( m e s s a g e ) i t s e l f .

    b ) A n i d t o u n i q u e l y i d e n t i f y a n o t i c e .

    c ) T h e I P a d d r e s s o f t h e c l i e n t t h a t a d d e d t h e n o t i c e .

    d ) T h e s e r v e r t i m e t h a t t h e n o t i c e w a s a d d e d .

    S h o w t h i s i n f o r m a t i o n o n t h e p a g e i n e a c h i n d i v i d u a l e l e m e n t o f t h e s e r i e s p a n e l .

    7 . C r e a t e a b a c k i n g b e a n t h a t c o n n e c t s t o t h e p r o p e r t i e s o f t h e c o m p o n e n t s o n t h e

    p a g e , c a l l i t N o t i c e B o a r d B a c k i n g B e a n . j a v a .

    1 4

  • 8/3/2019 Workshop Jsf

    15/15

    D i s t r i b u t e d a p p l i c a t i o n s

    A d a m W a l d e n b e r g

    J o a c h i m v o n H a c h t

    8 . M a k e t h e n o t i c e b o a r d f u n c t i o n a l a n d s t y l e a l l y o u r p a g e s w i t h C S S . Y o u c a n r e v i e w

    t h e s c r e e n s h o t s a b o v e i n o r d e r t o g e t s o m e i d e a s f o r t h e n a l l a y o u t . N o t i c e h o w

    t h e b u t t o n i n t h e i m a g e t o t h e r i g h t i s g h o s t e d w h e n t h e n o t i c e b o a r d i s f u l l .

    a ) Y o u s h o u l d d e n e t h e l e N o t i c e B o a r d C o n t r o l l e r B e a n . j a v a a n d i m p l e -

    m e n t a n y l i s t e n e r s i n t h a t l e . F r o m t h e p a g e , t h e u s e r s h o u l d b e a b l e t o d o

    t h e f o l l o w i n g :

    i . R e m o v e i n d i v i d u a l m e s s a g e s f r o m t h e n o t i c e b o a r d .

    i i . A d d n e w m e s s a g e s t o t h e n o t i c e b o a r d .

    i i i . I f t h e b o a r d i s f u l l , t h e b u t t o n f o r a d d i n g a n e w n o t i c e s h o u l d b e g h o s t e d .

    9 . O n c e y o u a r e d o n e , t r y t o v i s i t t h e a p p l i c a t i o n w i t h t w o b r o w s e r s . Y o u s h o u l d

    n o t i c e t h a t i t d o e s n ' t w o r k a s o n e w o u l d w a n t . U s i n g s e r v e r p u s h , w e w i l l f o r c e a

    c l i e n t u p d a t e w h e n e v e r a n o t h e r c l i e n t p o s t s o r r e m o v e s a n o t i c e .

    1 0 . R e a d t h e d o c u m e n t a t i o n f o r t h e I C E F a c e s S e s s i o n R e n d e r e r c l a s s . W e w i l l u s e t h i s

    c l a s s i n o r d e r t o t a k e a d v a n t a g e o f t h e p u s h f u n c t i o n a l i t y i n I C E F a c e s . M a k e s u r e

    y o u u n d e r s t a n d h o w i t w o r k s b e f o r e y o u c o n t i n u e .

    1 1 . W h e n t h e N o t i c e B o a r d B a c k i n g B e a n i n i t i a l i z e s , i t s h o u l d j o i n t h e N O T I C E _ B O A R D

    g r o u p u s i n g :

    S e s s i o n R e n d e r e r . a d d C u r r e n t S e s s i o n ( N O T I C E _ B O A R D )

    W h e n t h e b e a n i s l a t e r d e s t r o y e d , i t s h o u l d r e m o v e i t s e l f f r o m t h e N O T I C E _ B O A R D

    g r o u p . W h e n t h e c o n t r o l l e r b e a n m a k e s a c h a n g e t o t h e m o d e l , y o u s h o u l d c a l l :

    S e s s i o n R e n d e r e r . r e n d e r ( N O T I C E _ B O A R D )

    W h e n e v e r a c l i e n t t h e n c a l l s r e n d e r ( ) , I C E F a c e s w i l l f o r c e a n u p d a t e t o a l l o t h e r

    c l i e n t s p a r t o f t h e s a m e g r o u p .

    1 2 . V i s i t t h e a p p l i c a t i o n w i t h t w o b r o w s e r s a g a i n . H o p e f u l l y , i t ' s n o w w o r k i n g a s

    e x p e c t e d .

    1 5


Top Related