Permalink
Browse files

Fix conversation manager to have per session list of used ids

  • Loading branch information...
1 parent 9d24863 commit 0d2f07ed0c13115e384b886415e92bea6a8d6d12 @ccordenier committed Oct 21, 2010
View
53 src/main/java/com/tap5/conversation/services/ConversationManagerImpl.java
@@ -17,16 +17,16 @@
public class ConversationManagerImpl implements ConversationManager
{
+ private static final String ENDED = "conversation_ended";
+
+ private static final String CREATED = "conversation_created";
+
private final Request request;
private final MetaDataLocator locator;
private final PageRenderLinkSource linkSource;
- private final List<Long> created = new ArrayList<Long>();
-
- private final List<Long> ended = new ArrayList<Long>();
-
public ConversationManagerImpl(Request request, MetaDataLocator locator,
PageRenderLinkSource linkSource)
{
@@ -39,7 +39,7 @@ public ConversationManagerImpl(Request request, MetaDataLocator locator,
public Long createConversation()
{
Long cid = getIncrement().getAndIncrement();
- created.add(cid);
+ getList(CREATED).add(cid);
return cid;
}
@@ -54,33 +54,21 @@ public void end(String conversationName, Long cid)
session.setAttribute(name, null);
}
- created.remove(cid);
- ended.add(cid);
+ getList(CREATED).remove(cid);
+ getList(ENDED).add(cid);
}
public boolean isValid()
{
- return created.contains(getActiveConversation())
- && !ended.contains(getActiveConversation());
+ return getList(CREATED).contains(getActiveConversation())
+ && !getList(ENDED).contains(getActiveConversation());
}
public String getConversationName(String pageName)
{
return locator.findMeta(ConversationConstants.CONVERSATION_NAME, pageName, String.class);
}
- private AtomicLong getIncrement()
- {
- Session session = request.getSession(true);
- AtomicLong increment = (AtomicLong) session.getAttribute("conversation_increment");
- if (increment == null)
- {
- increment = new AtomicLong();
- session.setAttribute("conversation_increment", increment);
- }
- return increment;
- }
-
public boolean isConversational(String pageName)
{
return ConversationConstants.CONVERSATION.equals(locator.findMeta(
@@ -141,4 +129,27 @@ public Link createLink(String pageName, Object... context)
return result;
}
+ private AtomicLong getIncrement()
+ {
+ Session session = request.getSession(true);
+ AtomicLong increment = (AtomicLong) session.getAttribute("conversation_increment");
+ if (increment == null)
+ {
+ increment = new AtomicLong();
+ session.setAttribute("conversation_increment", increment);
+ }
+ return increment;
+ }
+
+ private List<Long> getList(String list)
+ {
+ Session session = request.getSession(true);
+ List<Long> result = (List<Long>) session.getAttribute(list);
+ if (result == null)
+ {
+ result = new ArrayList<Long>();
+ session.setAttribute(list, result);
+ }
+ return result;
+ }
}
View
5 src/main/java/com/tap5/hotelbooking/pages/Search.java
@@ -57,7 +57,10 @@ private HotelDataSource(Session session, @SuppressWarnings("rawtypes") Class ent
@Override
protected void applyAdditionalConstraints(Criteria crit)
{
- crit.add(Restrictions.ilike("name", criteria.getSearchPattern()));
+ if (criteria.getSearchPattern() != null)
+ {
+ crit.add(Restrictions.ilike("name", criteria.getSearchPattern()));
+ }
}
}
View
1 src/main/java/com/tap5/hotelbooking/pages/Signin.java
@@ -26,7 +26,6 @@
private String flashmessage;
@Property
- @Persist(PersistenceConstants.FLASH)
private String username;
@Property
View
16 src/main/java/com/tap5/hotelbooking/pages/Signup.java
@@ -1,9 +1,9 @@
package com.tap5.hotelbooking.pages;
-import org.apache.tapestry5.PersistenceConstants;
+import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.InjectPage;
-import org.apache.tapestry5.annotations.Persist;
+import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.beaneditor.Validate;
import org.apache.tapestry5.corelib.components.Form;
@@ -28,17 +28,15 @@
{
@Property
- @Persist(PersistenceConstants.FLASH)
+ @Validate("username")
private String username;
@Property
- @Persist(PersistenceConstants.FLASH)
@Validate("required, minlength=3, maxlength=50")
private String fullName;
@Property
- @Persist(PersistenceConstants.FLASH)
- @Validate("required, email")
+ @Validate("required,email")
private String email;
@Property
@@ -47,6 +45,9 @@
@Property
private String verifyPassword;
+ @Property
+ private String kaptcha;
+
@Inject
private CrudServiceDAO crudServiceDAO;
@@ -62,7 +63,8 @@
@InjectPage
private Signin signin;
- public Object onSubmitFromRegisterForm()
+ @OnEvent(value = EventConstants.SUCCESS, component = "RegisterForm")
+ public Object proceedSignup()
{
if (!verifyPassword.equals(password))
{
View
2 src/main/webapp/Signup.tml
@@ -48,7 +48,7 @@
</td>
</tr>
<tr>
- <th><label t:type="label" t:for="fcaptcha"></label></th>
+ <th><label t:type="label" t:for="fcaptcha">Enter text displayed below</label></th>
<td>
<t:tapx.kaptchafield image="kaptcha" t:id="fcaptcha" />
</td>

0 comments on commit 0d2f07e

Please sign in to comment.