inject homework

3 views
Skip to first unread message

Samad Nourou Atoro

unread,
Jan 13, 2010, 12:34:55 AM1/13/10
to javaee6-codecamp
Hello,

Are we supposed to build a JSF application in order to use the
ConversationScoped properly.

It doesn't seem to work from a servlet, or am I missing something? The
docs mention JSF...But from my understanding the session scope is a
portion of a user session. so should work with servlets. ???

Thanks.

shredder

unread,
Jan 13, 2010, 4:59:26 AM1/13/10
to javaee6-codecamp
I think they're just after Conversation scope for the exercise, but
what's confusing is that for the first part of the exercise we were
asked to modify HelloServlet, and then the second part, we apparently
have to introduce JSF.

Does anyone have any suggestions on how we should integrate the
HelloServlet with the JSF samples provided as hints?

Sang Shin

unread,
Jan 13, 2010, 5:48:17 AM1/13/10
to shredder, javaee6-codecamp
On 1/13/2010 4:59 AM, shredder wrote:
> I think they're just after Conversation scope for the exercise, but
> what's confusing is that for the first part of the exercise we were
> asked to modify HelloServlet, and then the second part, we apparently
> have to introduce JSF.
>
> Does anyone have any suggestions on how we should integrate the
> HelloServlet with the JSF samples provided as hints?
>
>
The homework is not meant to require you combine the Servlet and JSF
pages. I expect you test the
first part (Exercising qualifer) using Servlet as in the case of
"inject_qualifer" and the 2nd part (scoping)
exercise and 3rd part (event) using index.xhtml of the
"inject_scope_conversation" project.

I changed the homework as following so that the above is more clear
(refresh browser)

http://www.javapassion.com/handsonlabs/javaee6_injection/#Homework

Basically, you are using two different projects as bases as following

-For the first part (Exercising qualifer), use inject_qualifier project
as a base
-For the 2nd part and 3rd part, use inject_scope_conversation project as
a base

If you already submitted this homework or want to use a single project
as a base, that
is fine as well.

-Sang Shin

> On Jan 13, 12:34 pm, Samad Nourou Atoro<asnou...@gmail.com> wrote:
>
>> Hello,
>>
>> Are we supposed to build a JSF application in order to use the
>> ConversationScoped properly.
>>
>> It doesn't seem to work from a servlet, or am I missing something? The
>> docs mention JSF...But from my understanding the session scope is a
>> portion of a user session. so should work with servlets. ???
>>
>> Thanks.
>>


--
---------------------------------------------------------------
Sang Shin, sangshi...@gmail.com
http://www.javapassion.com/SangShinSchedule.html
(Life is worth living... with Passion!)
---------------------------------------------------------------
"Java EE 6 one-week online Codecamp" on Jan. 12th-19th, 2010
http://www.javapassion.com/courses/javaee6codecamp.html
"Groovy/Grails Programming" course starts from Jan. 30th, 2010
http://www.javapassion.com/groovyandgrails/
"Ajax and Web 2.0 Programming" course started from Sep. 7th, 2009
http://www.javapassion.com/ajaxcodecamp/
"Advanced Java EE Programming" course started from Oct. 1st, 2009
http://www.javapassion.com/javaee_advanced/
---------------------------------------------------------------


shredder

unread,
Jan 13, 2010, 6:37:00 AM1/13/10
to javaee6-codecamp
I just got the change, however, it still mentions about HelloServlet
in the first sub-point of Goal: Exercising Scope. I'm also not sure
how we get JSF to increment the scope counter on a refresh. Is it just
easier to to increment off the 'say hello' button?

>             Sang Shin, sangshinpass...@gmail.com

konkeong

unread,
Jan 13, 2010, 6:58:10 AM1/13/10
to javaee6-...@googlegroups.com
For this part

Create another bean called my_conversation_scope_bean with conversation scope, which has a field called my_conversation_scope_counter.  Now every time my_application_scope_counter hits multiple of 5, for example, 5, 10, 15, ..., start a conversation.  Every time my_application_scope_counter hits multiple of 5 plus 4, for example, 9, 14, 19, ..., stop the conversation. 

What is the purpose of creating the field "my_conversation_scope_counter"?
Should increment it when the applications is accessed?

Peter Johansson

unread,
Jan 13, 2010, 7:07:14 AM1/13/10
to javaee6-codecamp
I guess to incremet it and show the result.

I have a problem though, Do not know how to use a conversationscoped
bean from HelloServlet, I get an Exception when trying to start the
conversation.

Injected it like
@Inject my_conversation_scope_bean convScopeBean;

and class declaration of it is
@Named
@ConversationScoped
public class my_conversation_scope_bean implements Serializable {
private int my_conversation_scope_counter;

@Inject
Conversation conversation;
...

javax.enterprise.context.ContextNotActiveException: No active contexts
for scope type javax.enterprise.context.ConversationScoped
at org.jboss.weld.BeanManagerImpl.getContext
(BeanManagerImpl.java:928)
at
org.jboss.weld.bean.proxy.ClientProxyMethodHandler.getProxiedInstance
(ClientProxyMethodHandler.java:140)

matthieu vidal

unread,
Jan 13, 2010, 7:19:30 AM1/13/10
to javaee6-codecamp
Hi

I think that ConversationScoped Bean cannot be used without a JSF in
front (see javadoc).

On 13 jan, 13:07, Peter Johansson <theironicprogram...@gmail.com>
wrote:

Sang Shin

unread,
Jan 13, 2010, 7:39:51 AM1/13/10
to shredde...@gmail.com, javaee6-codecamp
On 1/13/2010 6:37 AM, shredder wrote:
> I just got the change, however, it still mentions about HelloServlet
> in the first sub-point of Goal: Exercising Scope. I'm also not sure
> how we get JSF to increment the scope counter on a refresh. Is it just
> easier to to increment off the 'say hello' button?
>

Ah. My mistake. Yes, "everytime the Say Hello button is pressed".
Thanks.
(The homework is updated.)

--
---------------------------------------------------------------
Sang Shin, sangshi...@gmail.com

Samad Nourou Atoro

unread,
Jan 13, 2010, 8:38:55 AM1/13/10
to javaee6-codecamp
OK.
Another thing that is confusing to me is when the homework says something like: every time the application is refreshed, increment the application scope counter.
 
I took this as if we're supposed to increment the application scope counter everytime any web component in the application is refreshed and had to use a ServletRequestListener to handle it. But from reading this thread, I think Sang meant to say everytime the HelloServlet is refreshed. Am I correct?
 
Thanks.
 
Samad

--
You received this message because you are subscribed to the Google Groups "javaee6-codecamp" group.
To post to this group, send email to javaee6-...@googlegroups.com.
To unsubscribe from this group, send email to javaee6-codeca...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/javaee6-codecamp?hl=en.




Peter Johansson

unread,
Jan 13, 2010, 8:40:29 AM1/13/10
to javaee6-codecamp
To clarify, should that link be changed, so that it triggers the
conversation bean or can it be implemented from another conversation
scoped bean?

I seam not to get the conversation bean to increase whatever I do try
to call it from teh applicationscoped but I tend to get 1 all the time
and start/end does not seam to work to satisfactory

/Peter

matthieu vidal

unread,
Jan 13, 2010, 8:47:19 AM1/13/10
to javaee6-codecamp
I'm stuck too ... trying to start the conversation from the
applicationBean

conversation.End() seem's to work (if we start the conversation using
the start conversation button) but I have this warning :

WELD-000301 Could not restore long-running
conversation 31 because id not known


Something is really not clear about the conversationScoped and it's
cid param. it seam's to work only when directly called from the JSF.

On 13 jan, 14:40, Peter Johansson <theironicprogram...@gmail.com>
wrote:

Peter Johansson

unread,
Jan 13, 2010, 9:35:39 AM1/13/10
to javaee6-codecamp
I reworked a bit, to let the Print.java wich is triggered when
klicking say hello
to
start and stop the other conversation, don't know if that the best
solution but it works.

/Peter

Samad Nourou Atoro

unread,
Jan 13, 2010, 9:54:20 AM1/13/10
to m...@matthieu-vidal.com, javaee6-codecamp
You need to start the coversation inside the ConversationScopeBean itself.
 
Have the action listener for the hello button increment the counter and begin/end the conversation when needed.

Sang Shin

unread,
Jan 13, 2010, 10:54:25 AM1/13/10
to asno...@gmail.com, javaee6-codecamp
On 1/13/2010 8:38 AM, Samad Nourou Atoro wrote:
OK.
Another thing that is confusing to me is when the homework says something like: every time the application is refreshed, increment the application scope counter.

As was mentioned in another thread, the homework is changed so that
"instead of application refreshed", you click "Say Hello" button to
increment the counter.

-Sang Shin

MarcinOS

unread,
Jan 13, 2010, 2:51:35 PM1/13/10
to javaee6-codecamp
Hi,

I think it would be good to increment both counters on every button
click. The counter in conversation scope would increment only if
conversation is started and it would be going back to its initial
value after the end of conversation. IMO it would be great showcase of
what's going on.

Nikolaos Apostolakos

unread,
Jan 13, 2010, 3:16:06 PM1/13/10
to marcin.sw...@gmail.com, javaee6-codecamp
I agree with MarcinOS. In the exercises description is not mentioned anywhere when the conversation scoped counter should be increased (probably this instruction was forgotten). My guess was also that it should be increased on every click of the "Say Hello" button (this is what I implemented), as I couldn't imagine any other place where it would make sense to increase it. Is this the case?

Sang Shin

unread,
Jan 13, 2010, 3:24:59 PM1/13/10
to niko...@gmail.com, marcin.sw...@gmail.com, javaee6-codecamp
On 1/13/2010 3:16 PM, Nikolaos Apostolakos wrote:
I agree with MarcinOS. In the exercises description is not mentioned anywhere when the conversation scoped counter should be increased (probably this instruction was forgotten). My guess was also that it should be increased on every click of the "Say Hello" button (this is what I implemented), as I couldn't imagine any other place where it would make sense to increase it. Is this the case?


Yes, that was what I intended as a homework.  (I will add it to the homework.)

-S

P.S.: I know this homework would be challenging to get it right.  I guess we are getting there
at least. :-)
-- 
---------------------------------------------------------------
           Sang Shin, sangshi...@gmail.com

Tristan Stephens

unread,
Jan 14, 2010, 12:12:09 AM1/14/10
to Sang Shin, javaee6-codecamp
Thanks for that. I've been able to complete the homework now.

charyorde

unread,
Jan 14, 2010, 7:49:20 AM1/14/10
to javaee6-codecamp
Does anybody know how to implement the multiple of 5 logic. Any hint
would be appreciated.

Thanks

On Jan 14, 5:12 am, Tristan Stephens <shredderts2...@gmail.com> wrote:
> Thanks for that. I've been able to complete the homework now.
>

Peter Johansson

unread,
Jan 14, 2010, 8:05:16 AM1/14/10
to javaee6-codecamp
Hint would be to use modula division

int cnt = curNumber
if(cnt % 5 == 0){

charyorde

unread,
Jan 14, 2010, 10:18:19 AM1/14/10
to javaee6-codecamp
Firstly, thank you Peter.

There's something I don't understand about starting the conversation
at a multiple of 5 and ending it at a multiple of 5 plus 4. When I
click the "Say Hello" button, the conversation starts, but by the time
it gets to the next multiple of 5 it throws an IllegalStateException
"java.lang.IllegalStateException: Attempt to call begin() on a long-
running conversation".

I believe that the multiple of 5 plus 4 is suppose to prevent that
exception since it is meant to end the conversation.

I need some explanation please.

On Jan 14, 1:05 pm, Peter Johansson <theironicprogram...@gmail.com>
wrote:

Peter Johansson

unread,
Jan 14, 2010, 10:25:26 AM1/14/10
to javaee6-codecamp
Actually I made some assumptions.

I start the conversation on 5,10,15 etc. That is, I do not include 0
as a multiple of 5,
Probably you get the Exception because you try to start a conversation
when it is already stated, I had some similar problems.

if then use start and stop in this manner (maybe a bit dirty hacking
but anyway)
if(cnt%5==0){
// start
}
if(cnt > 5 && (cnt-4)%5==0){
// end
}

/Peter
http://ironicprogrammer.blogspot.com/

charyorde

unread,
Jan 14, 2010, 10:43:07 AM1/14/10
to javaee6-codecamp
Thanks Peter.

By the way where do you get that logic from. It's really smart.

Thanks.

On Jan 14, 3:25 pm, Peter Johansson <theironicprogram...@gmail.com>
wrote:


> Actually I made some assumptions.
>
> I start the conversation on 5,10,15 etc. That is, I do not include 0
> as a multiple of 5,
> Probably you get the Exception because you try to start a conversation
> when it is already stated, I had some similar problems.
>
> if then use start and stop in this manner (maybe a bit dirty hacking
> but anyway)
> if(cnt%5==0){
> // start}
>
> if(cnt > 5 && (cnt-4)%5==0){
> // end
>
> }
>

> /Peterhttp://ironicprogrammer.blogspot.com/

Sang Shin

unread,
Jan 14, 2010, 11:26:12 AM1/14/10
to theironic...@gmail.com, javaee6-codecamp
On 1/14/2010 10:25 AM, Peter Johansson wrote:
> Actually I made some assumptions.
>
> I start the conversation on 5,10,15 etc. That is, I do not include 0
> as a multiple of 5,
> Probably you get the Exception because you try to start a conversation
> when it is already stated, I had some similar problems.
>
> if then use start and stop in this manner (maybe a bit dirty hacking
> but anyway)
> if(cnt%5==0){
> // start
> }
> if(cnt> 5&& (cnt-4)%5==0){
> // end
> }

Given that computing these numbers is not real focus of the exercise,
I've added the above as a hint as following.

http://www.javapassion.com/handsonlabs/javaee6_injection/#Hint_2

Thanks.

-Sang Shin

--
---------------------------------------------------------------
Sang Shin, sangshi...@gmail.com

Gadnex

unread,
Jan 16, 2010, 7:42:21 AM1/16/10
to javaee6-codecamp
Hi,

After several hours of trying to complete the homework for the CDI
topic and looking for help on the forums I am still stuck on what to
do and need some help/guidance.

I am stuck on the part of the homework where the
inject_scope_conversation project needs to be updated. I do not expect
anyone to give away the answer, just to be pointed in the right
direction. Here are some questions regarding things in the assignment
I do not understand.
1.) The name my_application_scope_bean confuses me, because we are
told to create a bean and a bean is a class, where the naming
convention is usually different i.e. MyApplicationScopeBean. Should I
create a class called MyApplicationScopeBean?
2.) How should MyApplicationScopeBean be annotated? I currently have
it as @ManagedBean and @ApplicationScoped.
3.) Should MyApplicationScopeBean be injected (@Inject) into the
Printer class?
4.) If so, should MyApplicationScopeBean's counter be incremented in
the Printer class's createSalutation method?
5.) How is the my_application_scope_counter displayed in the JSF page,
via the Printer class or directly via the MyApplicationScopeBean?

Regards,
Gadnex

> >>>>>> (Thehomeworkis updated.)


>
> >>>>>> -Sang Shin
>
> >>>>>>> On Jan 13, 5:48 pm, Sang Shin<sangshinpass...@gmail.com>    wrote:
>
> >>>>>>>> On 1/13/2010 4:59 AM, shredder wrote:>    I think they're just after
> >>>>>>>> Conversation scope for the exercise, but
>
> >>>>>>>>> what's confusing is that for the first part of the exercise we were
> >>>>>>>>> asked to modify HelloServlet, and then the second part, we apparently
> >>>>>>>>> have to introduce JSF.
>
> >>>>>>>>> Does anyone have any suggestions on how we should integrate the
> >>>>>>>>> HelloServlet with the JSF samples provided as hints?
>

> >>>>>>>> Thehomeworkis not meant to require you combine the Servlet and JSF


> >>>>>>>> pages.  I expect you test the
> >>>>>>>> first part (Exercising qualifer) using Servlet as in the case of
> >>>>>>>> "inject_qualifer" and the 2nd part (scoping)
> >>>>>>>> exercise and 3rd part (event) using index.xhtml of the
> >>>>>>>> "inject_scope_conversation" project.
>

> >>>>>>>> I changed thehomeworkas following so that the above is more clear


> >>>>>>>> (refresh browser)
>
> >>>>>>>>    http://www.javapassion.com/handsonlabs/javaee6_injection/#Homework
>
> >>>>>>>> Basically, you are using two different projects as bases as following
>
> >>>>>>>> -For the first part (Exercising qualifer), use inject_qualifier project
> >>>>>>>> as a base
> >>>>>>>> -For the 2nd part and 3rd part, use inject_scope_conversation project as
> >>>>>>>> a base
>

> >>>>>>>> If you already submitted thishomeworkor want to use a single project

Kayode Odeyemi

unread,
Jan 17, 2010, 5:48:22 AM1/17/10
to javaee6-codecamp
@Gadnex

Pardon me, but the reason why you are stuck is because you are not
punching your keyboard. Try to code and experience your assumptions.
Most of your itemized assumptions are in the right direction. You just
need to try it and see.

If you are having problems naming your bean like
MyApplicationScopeBean, try to name as described in the homework, like
my_application_scope_bean.

Good luck.

On Jan 16, 12:42 pm, Gadnex <gad...@gmail.com> wrote:
> Hi,
>

> After several hours of trying to complete thehomeworkfor the CDI


> topic and looking for help on the forums I am still stuck on what to
> do and need some help/guidance.
>

> I am stuck on the part of thehomeworkwhere the

finger.k4

unread,
Jan 18, 2010, 4:44:01 PM1/18/10
to javaee6-codecamp
It might be the case that I am missing something, but incrementing the
'Say Hello' button click in the application scoped bean just does not
work.

The bean:

@Named
@ApplicationScoped
public class my_application_scope_bean implements Serializable {
private int my_application_scope_counter = 0;

public int getMy_application_scope_counter() {
return my_application_scope_counter;
}

public void setMy_application_scope_counter(int
my_application_scope_counter) {
this.my_application_scope_counter =
my_application_scope_counter;
}

}

I believe that I properly inject it:

public class Printer implements Serializable {

@Inject
@Informal
Greeting greeting;
@Inject
Conversation conversation;
@Inject
MyConversationStatus cstatus;
private String name;
private String salutation = "nothing yet!";
private String old_salutation = "nothing yet!";
@Inject
private my_application_scope_bean appCounterBean;
.....

And I modified the method which is invoked when the button is clicked:

public void createSalutation() {
appCounterBean.setMy_application_scope_counter
(appCounterBean.getMy_application_scope_counter() + 1);
System.out.println("counterBean = " +
appCounterBean.getMy_application_scope_counter());
this.old_salutation = salutation;
this.salutation = greeting.greet(name);
}

I have two problems so far:

1) index.xhtml always shows 0 as the value of clicks. I've used the
same code snipet given in the homework !

2) I have added to the method 'System.out.println("counterBean = " +
appCounterBean.getMy_application_scope_counter());' just for debugging
and my observation is that this value is always 1.... how is that
possible??

Any help would be appreciated!

Ivo

On Jan 17, 12:48 pm, Kayode Odeyemi <drey...@gmail.com> wrote:
> @Gadnex
>
> Pardon me, but the reason why you are stuck is because you are not
> punching your keyboard. Try to code and experience your assumptions.
> Most of your itemized assumptions are in the right direction. You just
> need to try it and see.
>
> If you are having problems naming your bean like

> MyApplicationScopeBean, try to name as described in thehomework, like

Jason Porter

unread,
Jan 18, 2010, 4:51:36 PM1/18/10
to gad...@gmail.com, javaee6-codecamp
On Sat, Jan 16, 2010 at 05:42, Gadnex <gad...@gmail.com> wrote:
> Hi,
>
> After several hours of trying to complete the homework for the CDI
> topic and looking for help on the forums I am still stuck on what to
> do and need some help/guidance.
>
> I am stuck on the part of the homework where the
> inject_scope_conversation project needs to be updated. I do not expect
> anyone to give away the answer, just to be pointed in the right
> direction. Here are some questions regarding things in the assignment
> I do not understand.
> 1.) The name my_application_scope_bean confuses me, because we are
> told to create a bean and a bean is a class, where the naming
> convention is usually different i.e. MyApplicationScopeBean. Should I
> create a class called MyApplicationScopeBean?

The @Named annotation has a value (they only attribute, so you can
leave out the name) that is a string, you can change the EL name
(which is all @Named is for) to anything you like.

> 2.) How should MyApplicationScopeBean be annotated? I currently have
> it as @ManagedBean and @ApplicationScoped.

I suggest using @Named, @ManagedBean is from JSF, and the @Named
annotation is better anyway. Any CDI beans will implicitly be a
managed bean.

> 3.) Should MyApplicationScopeBean be injected (@Inject) into the
> Printer class?

That would be one way of doing it. There are many, many ways you could do this.

> 4.) If so, should MyApplicationScopeBean's counter be incremented in
> the Printer class's createSalutation method?

You're call.

> 5.) How is the my_application_scope_counter displayed in the JSF page,
> via the Printer class or directly via the MyApplicationScopeBean?

You could do either.

> --
> You received this message because you are subscribed to the Google Groups "javaee6-codecamp" group.
> To post to this group, send email to javaee6-...@googlegroups.com.
> To unsubscribe from this group, send email to javaee6-codeca...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/javaee6-codecamp?hl=en.
>
>
>
>

--
Jason Porter
Real Programmers think better when playing Adventure or Rogue.

PGP key id: 926CCFF5
PGP fingerprint: 64C2 C078 13A9 5B23 7738 F7E5 1046 C39B 926C CFF5
PGP key available at: keyserver.net, pgp.mit.edu

Jason Porter

unread,
Jan 18, 2010, 4:54:04 PM1/18/10
to fing...@gmail.com, javaee6-codecamp
On Mon, Jan 18, 2010 at 14:44, finger.k4 <fing...@gmail.com> wrote:
> It might be the case that I am missing something, but incrementing the
> 'Say Hello' button click in the application scoped bean just does not
> work.
>
> The bean:
>
> @Named
> @ApplicationScoped
> public class my_application_scope_bean implements Serializable {
>    private int my_application_scope_counter = 0;
>
>    public int getMy_application_scope_counter() {
>        return my_application_scope_counter;
>    }
>
>    public void setMy_application_scope_counter(int
> my_application_scope_counter) {
>        this.my_application_scope_counter =
> my_application_scope_counter;
>    }
>
> }
>
> I believe that I properly inject it:

Are there any annotations on the Printer class? Everything else is
looking good.

finger.k4

unread,
Jan 18, 2010, 6:51:25 PM1/18/10
to javaee6-codecamp
Nothing other than the usual, i used the Printer class from the lab.

@Named
@ConversationScoped


public class Printer implements Serializable {

...

i seriously have no idea what could be wrong...

On Jan 18, 11:54 pm, Jason Porter <lightguard...@gmail.com> wrote:

> ...
>
> read more »

Jason Porter

unread,
Jan 18, 2010, 10:14:35 PM1/18/10
to fing...@gmail.com, javaee6-codecamp
Yeah, with what you've given, I'm not sure either. Have to see the
whole app.

Sent from my iPhone

> --
> You received this message because you are subscribed to the Google
> Groups "javaee6-codecamp" group.
> To post to this group, send email to javaee6-

> code...@googlegroups.com.

Mahesh

unread,
Jan 19, 2010, 2:53:40 PM1/19/10
to javaee6-codecamp
Hi,

Is the problem resolved? It works for me

Let me know. Can you also paste the index.xhtml file.

Mahesh

> ...
>
> read more »

finger.k4

unread,
Jan 20, 2010, 7:38:46 AM1/20/10
to javaee6-codecamp
Unfortunately not, the problem still exists :(
Here are the contents of the most relevant files of the project , the
other like greeting and the greeting interfaces and annotations are
not included because they were provided in the lab samples:

index.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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">
<ui:composition template="/template.xhtml">

<ui:define name="title">Simple Greeting</ui:define>
<ui:define name="head">Simple Greeting</ui:define>
<ui:define name="content">
<h:form id="greetme">
<p><h:outputLabel value="Enter your name: " for="name"/
>
<h:inputText id="name" value="#{printer.name}"/></
p>
<p><h:commandButton value="Say Hello" action="#
{printer.createSalutation}"/></p>
<p><h:commandButton value="Start conversation"
action="#{printer.startConversation}"/></p>
<p><h:commandButton value="End conversation" action="#
{printer.endConversation}"/></p>
<p><h:outputText value="printer.salutation = #
{printer.salutation}"/> </p>
<p><h:outputText value="printer.old_salutation = #
{printer.old_salutation}"/> </p>
<p><h:outputText
value="myConversationStatus.conversationSattus = #
{myConversationStatus.conversationSattus}"/> </p>
<p><h:outputText
value="my_application_scope_bean.my_application_scope_counter = #
{my_application_scope_bean.my_application_scope_counter}"/> </p>
<p><h:outputText
value="my_conversation_scope_bean.my_conversation_scope_counter = #
{my_conversation_scope_bean.my_conversation_scope_counter}"/> </p>
</h:form>
</ui:define>

</ui:composition>
</html>


------------------

Application Scope Bean

---------------

package greetings;

import java.io.Serializable;
import javax.faces.bean.ApplicationScoped;
import javax.inject.Named;

/**
*
* @author Ivo Neskovic <ivo.ne...@gmail.com>
*/


@Named
@ApplicationScoped
public class my_application_scope_bean implements Serializable {
private int my_application_scope_counter = 0;

public void incrementCounter() {
my_application_scope_counter++;
}

public int getMy_application_scope_counter() {
return my_application_scope_counter;
}

public void setMy_application_scope_counter(int
my_application_scope_counter) {
this.my_application_scope_counter =
my_application_scope_counter;
}

}

--------------------

Conversation Scope Bean

-----------------------

package greetings;

import java.io.Serializable;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Named;

/**
*
* @author Ivo Neskovic <ivo.ne...@gmail.com>
*/
@Named
@ConversationScoped
public class my_conversation_scope_bean implements Serializable {

private int my_conversation_scope_counter = 0;

public void incrementCounter() {
my_conversation_scope_counter++;
}

public int getMy_conversation_scope_counter() {
return my_conversation_scope_counter;
}

public void setMy_conversation_scope_counter(int
my_conversation_scope_counter) {
this.my_conversation_scope_counter =
my_conversation_scope_counter;
}

}


--------------------------


Printer


--------------------------

package greetings;

import java.io.Serializable;
import java.util.Random;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;

@Named
@ConversationScoped


public class Printer implements Serializable {

@Inject
@Informal
Greeting greeting;
@Inject
Conversation conversation;
@Inject
MyConversationStatus cstatus;
private String name;
private String salutation = "nothing yet!";
private String old_salutation = "nothing yet!";
@Inject
private my_application_scope_bean appCounterBean;

@Inject
private my_conversation_scope_bean convCounterBean;

public void startConversation() {
cstatus.setConversationSattus("on");
conversation.begin();
}

public void endConversation() {
cstatus.setConversationSattus("off");
conversation.end();
}

public void createSalutation() {
appCounterBean.setMy_application_scope_counter
(appCounterBean.getMy_application_scope_counter() + 1);

System.out.println("AppCounterBean = " +
appCounterBean.getMy_application_scope_counter());
convCounterBean.setMy_conversation_scope_counter
(convCounterBean.getMy_conversation_scope_counter() + 1);
System.out.println("ConvCounterBean = " +
convCounterBean.getMy_conversation_scope_counter());

this.old_salutation = salutation;
this.salutation = greeting.greet(name);

int counter = appCounterBean.getMy_application_scope_counter
();
if (counter % 5 == 0) {
// start
this.startConversation();
Random random = new Random();
convCounterBean.setMy_conversation_scope_counter
(random.nextInt(100));
}
if (counter > 5 && (counter - 4) % 5 == 0) {
// end
this.endConversation();
}
}

public String getSalutation() {
return salutation;
}

public void setName(String name) {
this.name = name;
}

public String getName() {
return name;
}

/**
* @return the old_salutation
*/
public String getOld_salutation() {
return old_salutation;
}

/**
* @param old_salutation the old_salutation to set
*/
public void setOld_salutation(String old_salutation) {
this.old_salutation = old_salutation;
}
}


-------------------------------

I would really appreciate if someone could figure it out. Btw, I also
added the conversation scoped bean as you can see, and whenever I
click the say hello button, that counter is incremented (it shows in
the System.out.println) however in web page only the first change is
registered, i.e. if i click once it goes to 1, however when I click
again it stays at 1 in the web page, and System.out.println registers
2 etc...

Help? :)

Rgz,
Ivo

> ...
>
> read more »

Reply all
Reply to author
Forward
0 new messages