myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject svn commit: r514223 - in /myfaces/fusion/trunk/examples/src/main: java/org/apache/myfaces/examples/ballot/backings/ java/org/apache/myfaces/examples/ballot/model/ java/org/apache/myfaces/examples/lib/ webapp/WEB-INF/ webapp/ballot/
Date Sat, 03 Mar 2007 19:31:14 GMT
Author: imario
Date: Sat Mar  3 11:31:13 2007
New Revision: 514223

URL: http://svn.apache.org/viewvc?view=rev&rev=514223
Log:
made min, max and count of votes per voter configureable

Added:
    myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotVoteTopicCmp.java
Modified:
    myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotHall.java
    myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotVoteTopic.java
    myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotVoter.java
    myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/model/Item.java
    myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/model/Topic.java
    myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/model/Vote.java
    myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/lib/FacesUtils.java
    myfaces/fusion/trunk/examples/src/main/webapp/WEB-INF/applicationContext.xml
    myfaces/fusion/trunk/examples/src/main/webapp/ballot/Topic.jsp
    myfaces/fusion/trunk/examples/src/main/webapp/ballot/VoteTopic.jsp

Modified: myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotHall.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotHall.java?view=diff&rev=514223&r1=514222&r2=514223
==============================================================================
--- myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotHall.java
(original)
+++ myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotHall.java
Sat Mar  3 11:31:13 2007
@@ -72,7 +72,7 @@
 		if (!StringUtils.isEmpty(uuid) && !StringUtils.isEmpty(uid))
 		{
 			Voter voter = getVoterDao().getByKey(Long.parseLong(uid, 10));
-			if (uuid.equals(voter.getIdentification()))
+			if (voter != null && uuid.equals(voter.getIdentification()))
 			{
 				getBallotState().setVoterId(voter.getId());
 				getBallotState().setAuthenticated(true);

Modified: myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotVoteTopic.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotVoteTopic.java?view=diff&rev=514223&r1=514222&r2=514223
==============================================================================
--- myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotVoteTopic.java
(original)
+++ myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotVoteTopic.java
Sat Mar  3 11:31:13 2007
@@ -24,10 +24,10 @@
 package org.apache.myfaces.examples.ballot.backings;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.myfaces.examples.ballot.dao.ItemDao;
 import org.apache.myfaces.examples.ballot.dao.TopicDao;
 import org.apache.myfaces.examples.ballot.dao.VoteDao;
 import org.apache.myfaces.examples.ballot.dao.VoterDao;
-import org.apache.myfaces.examples.ballot.dao.ItemDao;
 import org.apache.myfaces.examples.ballot.lib.BallotState;
 import org.apache.myfaces.examples.ballot.model.Item;
 import org.apache.myfaces.examples.ballot.model.Topic;
@@ -35,25 +35,32 @@
 import org.apache.myfaces.examples.ballot.model.Voter;
 import org.apache.myfaces.examples.lib.FacesConst;
 import org.apache.myfaces.examples.lib.FacesUtils;
+import org.apache.myfaces.examples.lib.SpringUtils;
 import org.apache.myfaces.fusion.conversation.Conversation;
 import org.apache.myfaces.fusion.conversation.ConversationUtils;
-import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.PlatformTransactionManager;
 
 import javax.faces.context.FacesContext;
+import javax.faces.event.ValueChangeEvent;
 import javax.faces.model.SelectItem;
+import javax.servlet.ServletRequest;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 public class BallotVoteTopic
 {
+	private PlatformTransactionManager transactionManager;
+
 	private TopicDao topicDao;
 	private VoteDao voteDao;
 	private VoterDao voterDao;
 	private ItemDao itemDao;
 
 	private BallotState ballotState;
+	private BallotVoteTopicCmp ballotVoteTopicCmp;
 
 	private Topic topic;
 
@@ -89,6 +96,26 @@
 		}
 	}
 
+	public BallotVoteTopicCmp getBallotVoteTopicCmp()
+	{
+		return ballotVoteTopicCmp;
+	}
+
+	public void setBallotVoteTopicCmp(BallotVoteTopicCmp ballotVoteTopicCmp)
+	{
+		this.ballotVoteTopicCmp = ballotVoteTopicCmp;
+	}
+
+	public PlatformTransactionManager getTransactionManager()
+	{
+		return transactionManager;
+	}
+
+	public void setTransactionManager(PlatformTransactionManager transactionManager)
+	{
+		this.transactionManager = transactionManager;
+	}
+
 	public BallotState getBallotState()
 	{
 		return ballotState;
@@ -183,6 +210,18 @@
 		return topic;
 	}
 
+	public void voteChanged(ValueChangeEvent event)
+	{
+		Date now = new Date();
+
+		ItemInfo itemInfo = (ItemInfo) getBallotVoteTopicCmp().getItemInfoTable().getRowData();
+		Vote vote = itemInfo.getVote();
+		vote.setChanged(now);
+		
+		ServletRequest sr = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
+		vote.setRemoteIp(sr.getRemoteAddr());
+	}
+
 	public List<ItemInfo> getItems()
 	{
 		if (itemInfos != null)
@@ -217,13 +256,42 @@
 		return itemInfos;
 	}
 
-	@Transactional
 	public String saveAction()
 	{
+		int voteCount = 0;
+		
 		for (ItemInfo itemInfo : itemInfos)
 		{
-			voteDao.save(itemInfo.getVote());
+			if (itemInfo.getVote().getChoice() != 0)
+			{
+				voteCount++;
+			}
+
+			Date now = new Date();
+
+			Vote vote = itemInfo.getVote();
+			if (vote.getCreated() == null)
+			{
+				vote.setCreated(now);
+			}
+
+			if (vote.getRemoteIp() == null)
+			{
+				ServletRequest sr = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
+				vote.setRemoteIp(sr.getRemoteAddr());
+			}
+
+			voteDao.save(vote);
+		}
+
+		if (voteCount != getTopic().getMaxVoteCount())
+		{
+			FacesUtils.addErrorMessage("you have to choose (not 0 vote) exactly '" + getTopic().getMaxVoteCount()
+ "' items");
+			return FacesConst.FAILURE;
 		}
+		
+		SpringUtils.commit(transactionManager);
+		
 
 		BallotVoteTopic newBallotVoteTopic = (BallotVoteTopic) ConversationUtils.invalidateAndRestart(Conversation.getCurrentInstance());
 		newBallotVoteTopic.initTopic(getTopic().getId());
@@ -239,7 +307,7 @@
 		}
 
 		choices = new ArrayList<SelectItem>();
-		for (int i = -2; i < 3; i++)
+		for (int i = getTopic().getMinVote(); i < (getTopic().getMaxVote()+1); i++)
 		{
 			choices.add(new SelectItem(i, Integer.toString(i)));
 		}

Added: myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotVoteTopicCmp.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotVoteTopicCmp.java?view=auto&rev=514223
==============================================================================
--- myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotVoteTopicCmp.java
(added)
+++ myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotVoteTopicCmp.java
Sat Mar  3 11:31:13 2007
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2007, Your Corporation. All Rights Reserved.
+ */
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.examples.ballot.backings;
+
+import javax.faces.component.UIData;
+
+public class BallotVoteTopicCmp
+{
+	private UIData itemInfoTable;
+
+	public UIData getItemInfoTable()
+	{
+		return itemInfoTable;
+	}
+
+	public void setItemInfoTable(UIData itemInfoTable)
+	{
+		this.itemInfoTable = itemInfoTable;
+	}
+}

Modified: myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotVoter.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotVoter.java?view=diff&rev=514223&r1=514222&r2=514223
==============================================================================
--- myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotVoter.java
(original)
+++ myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/backings/BallotVoter.java
Sat Mar  3 11:31:13 2007
@@ -152,6 +152,8 @@
 		if (isNew)
 		{
 			sendMail(getVoter().getEmail());
+
+			FacesUtils.addInfoMessage("a mail has been sent to you, use the link in this mail to start
using this system");
 		}
 
 		Conversation.getCurrentInstance().invalidate();

Modified: myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/model/Item.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/model/Item.java?view=diff&rev=514223&r1=514222&r2=514223
==============================================================================
--- myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/model/Item.java
(original)
+++ myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/model/Item.java
Sat Mar  3 11:31:13 2007
@@ -52,7 +52,6 @@
 	@OneToMany(cascade = CascadeType.REMOVE, mappedBy = "item")
 	private List<Vote> votes;
 
-
 	public Long getId()
 	{
 		return id;

Modified: myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/model/Topic.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/model/Topic.java?view=diff&rev=514223&r1=514222&r2=514223
==============================================================================
--- myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/model/Topic.java
(original)
+++ myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/model/Topic.java
Sat Mar  3 11:31:13 2007
@@ -27,6 +27,7 @@
 import javax.persistence.CascadeType;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
+import javax.persistence.OrderBy;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -47,7 +48,17 @@
 	@Column(nullable = false, length = 1024)
 	private String description;
 
+	@Column(nullable = false)
+	private int minVote;
+
+	@Column(nullable = false)
+	private int maxVote;
+
+	@Column(nullable = false)
+	private int maxVoteCount;
+
 	@OneToMany(mappedBy="topic", cascade = CascadeType.ALL)
+	@OrderBy(value="content")
 	private List<Item> items;
 
 	private boolean started;
@@ -126,15 +137,33 @@
 		this.started = started;
 	}
 
-	/*
-	public List<Vote> getVotes()
+	public int getMinVote()
+	{
+		return minVote;
+	}
+
+	public void setMinVote(int minVote)
+	{
+		this.minVote = minVote;
+	}
+
+	public int getMaxVote()
+	{
+		return maxVote;
+	}
+
+	public void setMaxVote(int maxVote)
+	{
+		this.maxVote = maxVote;
+	}
+
+	public int getMaxVoteCount()
 	{
-		return votes;
+		return maxVoteCount;
 	}
 
-	public void setVotes(List<Vote> votes)
+	public void setMaxVoteCount(int maxVoteCount)
 	{
-		this.votes = votes;
+		this.maxVoteCount = maxVoteCount;
 	}
-	*/
 }

Modified: myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/model/Vote.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/model/Vote.java?view=diff&rev=514223&r1=514222&r2=514223
==============================================================================
--- myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/model/Vote.java
(original)
+++ myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/ballot/model/Vote.java
Sat Mar  3 11:31:13 2007
@@ -30,6 +30,9 @@
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.NamedQuery;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import java.util.Date;
 
 @NamedQuery(
 	name="getVotesForVoter",
@@ -53,6 +56,16 @@
 	@Column(nullable = false)
 	public int choice;
 
+	@Temporal(value= TemporalType.TIMESTAMP)
+	@Column(nullable = false)
+	public Date created;
+
+	@Temporal(value= TemporalType.TIMESTAMP)
+	public Date changed;
+
+	@Column(nullable = false)
+	public String remoteIp;
+
 	public Long getId()
 	{
 		return id;
@@ -91,5 +104,35 @@
 	public void setChoice(int choice)
 	{
 		this.choice = choice;
+	}
+
+	public Date getCreated()
+	{
+		return created;
+	}
+
+	public void setCreated(Date created)
+	{
+		this.created = created;
+	}
+
+	public Date getChanged()
+	{
+		return changed;
+	}
+
+	public void setChanged(Date changed)
+	{
+		this.changed = changed;
+	}
+
+	public String getRemoteIp()
+	{
+		return remoteIp;
+	}
+
+	public void setRemoteIp(String remoteIp)
+	{
+		this.remoteIp = remoteIp;
 	}
 }

Modified: myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/lib/FacesUtils.java
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/lib/FacesUtils.java?view=diff&rev=514223&r1=514222&r2=514223
==============================================================================
--- myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/lib/FacesUtils.java
(original)
+++ myfaces/fusion/trunk/examples/src/main/java/org/apache/myfaces/examples/lib/FacesUtils.java
Sat Mar  3 11:31:13 2007
@@ -31,12 +31,12 @@
 	public static void addErrorMessage(String message)
 	{
 		FacesContext.getCurrentInstance().addMessage(null,
-			new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message));
+			new FacesMessage(FacesMessage.SEVERITY_ERROR, null, message));
 	}
 
 	public static void addInfoMessage(String message)
 	{
 		FacesContext.getCurrentInstance().addMessage(null,
-			new FacesMessage(FacesMessage.SEVERITY_INFO, message, message));
+			new FacesMessage(FacesMessage.SEVERITY_INFO, null, message));
 	}
 }

Modified: myfaces/fusion/trunk/examples/src/main/webapp/WEB-INF/applicationContext.xml
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/examples/src/main/webapp/WEB-INF/applicationContext.xml?view=diff&rev=514223&r1=514222&r2=514223
==============================================================================
--- myfaces/fusion/trunk/examples/src/main/webapp/WEB-INF/applicationContext.xml (original)
+++ myfaces/fusion/trunk/examples/src/main/webapp/WEB-INF/applicationContext.xml Sat Mar 
3 11:31:13 2007
@@ -196,6 +196,15 @@
 	</bean>
 
 	<bean
+		name="ballotVoteTopicCmp"
+		class="org.apache.myfaces.examples.ballot.backings.BallotVoteTopicCmp"
+		scope="request">
+
+		<aop:scoped-proxy/>
+
+	</bean>
+
+	<bean
 		name="ballotVoteTopic"
 		class="org.apache.myfaces.examples.ballot.backings.BallotVoteTopic"
 		scope="conversation"

Modified: myfaces/fusion/trunk/examples/src/main/webapp/ballot/Topic.jsp
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/examples/src/main/webapp/ballot/Topic.jsp?view=diff&rev=514223&r1=514222&r2=514223
==============================================================================
--- myfaces/fusion/trunk/examples/src/main/webapp/ballot/Topic.jsp (original)
+++ myfaces/fusion/trunk/examples/src/main/webapp/ballot/Topic.jsp Sat Mar  3 11:31:13 2007
@@ -68,7 +68,6 @@
 				<h:outputLabel
 					for="name"
 					value="Name"/>
-
 				<h:inputText
 					id="name"
 					value="#{ballotTopic.topic.name}"
@@ -90,9 +89,60 @@
 					rendered="#{ballotTopic.topicEditable && ballotState.authenticated}">
 					<f:validateLength maximum="1024" />
 				</h:inputTextarea>
-
 				<h:outputText
 					value="#{ballotTopic.topic.description}"
+					rendered="#{!ballotTopic.topicEditable || !ballotState.authenticated}"/>
+
+				<h:outputLabel
+					for="minVote"
+					value="Minimum vote choice"/>
+				<h:inputText
+					id="minVote"
+					value="#{ballotTopic.topic.minVote}"
+					size="5"
+					maxlength="5"
+					rendered="#{ballotTopic.topicEditable && ballotState.authenticated}">
+					<s:convertNumber
+						minFractionDigits="0"
+						maxFractionDigits="0" />
+				</h:inputText>
+				<h:outputText
+					value="#{ballotTopic.topic.inVote}"
+					rendered="#{!ballotTopic.topicEditable || !ballotState.authenticated}"/>
+
+				<h:outputLabel
+					for="maxVote"
+					value="Maximum vote choice"/>
+				<h:inputText
+					id="maxVote"
+					value="#{ballotTopic.topic.maxVote}"
+					size="5"
+					maxlength="5"
+					rendered="#{ballotTopic.topicEditable && ballotState.authenticated}">
+					<s:convertNumber
+						minFractionDigits="0"
+						maxFractionDigits="0" />
+				</h:inputText>
+				<h:outputText
+					value="#{ballotTopic.topic.minVote}"
+					rendered="#{!ballotTopic.topicEditable || !ballotState.authenticated}"/>
+
+				<h:outputLabel
+					for="maxVoteCount"
+					value="Maximum number of votes per voter"/>
+				<h:inputText
+					id="maxVoteCount"
+					value="#{ballotTopic.topic.maxVoteCount}"
+					size="5"
+					maxlength="5"
+					rendered="#{ballotTopic.topicEditable && ballotState.authenticated}">
+					<f:validateLongRange minimum="0" maximum="99999" />
+					<s:convertNumber
+						minFractionDigits="0"
+						maxFractionDigits="0" />
+				</h:inputText>
+				<h:outputText
+					value="#{ballotTopic.topic.maxVoteCount}"
 					rendered="#{!ballotTopic.topicEditable || !ballotState.authenticated}"/>
 
 				<h:outputLabel

Modified: myfaces/fusion/trunk/examples/src/main/webapp/ballot/VoteTopic.jsp
URL: http://svn.apache.org/viewvc/myfaces/fusion/trunk/examples/src/main/webapp/ballot/VoteTopic.jsp?view=diff&rev=514223&r1=514222&r2=514223
==============================================================================
--- myfaces/fusion/trunk/examples/src/main/webapp/ballot/VoteTopic.jsp (original)
+++ myfaces/fusion/trunk/examples/src/main/webapp/ballot/VoteTopic.jsp Sat Mar  3 11:31:13
2007
@@ -73,6 +73,7 @@
 			</h:panelGrid>
 
 			<t:dataTable
+				binding="#{ballotVoteTopicCmp.itemInfoTable}"
 				styleClass="inputTable"
 				var="itemInfo"
 				value="#{ballotVoteTopic.items}"
@@ -103,7 +104,9 @@
 						<h:outputText value="Vote"/>
 					</f:facet>
 
-					<h:selectOneRadio value="#{itemInfo.vote.choice}">
+					<h:selectOneRadio
+						value="#{itemInfo.vote.choice}"
+						valueChangeListener="#{ballotVoteTopic.voteChanged}">
 						<f:selectItems value="#{ballotVoteTopic.choices}" />
 					</h:selectOneRadio>
 



Mime
View raw message