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.
Does anyone have any suggestions on how we should integrate the
HelloServlet with the JSF samples provided as hints?
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/
---------------------------------------------------------------
> Sang Shin, sangshinpass...@gmail.com
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)
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:
Ah. My mistake. Yes, "everytime the Say Hello button is pressed".
Thanks.
(The homework is updated.)
--
---------------------------------------------------------------
Sang Shin, sangshi...@gmail.com
--
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.
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
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
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 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.
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, sangshi...@gmail.com
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.
>
int cnt = curNumber
if(cnt % 5 == 0){
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:
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/
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/
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
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
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
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
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
Are there any annotations on the Printer class? Everything else is
looking good.
@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 »
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-
Is the problem resolved? It works for me
Let me know. Can you also paste the index.xhtml file.
Mahesh
> ...
>
> read more »
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 »