[jboss-svn-commits] JBL Code SVN: r7818 - in labs/jbossforums/branches/forums26/forums/src: main/org/jboss/portlet/forums/commands/post main/org/jboss/portlet/forums/ui/action resources/portal-forums-war/views/topics

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Nov 24 16:04:14 EST 2006


Author: unibrew
Date: 2006-11-24 16:04:05 -0500 (Fri, 24 Nov 2006)
New Revision: 7818

Modified:
   labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/commands/post/PostTools.java
   labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/action/EditPost.java
   labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/action/NewTopic.java
   labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/action/PollController.java
   labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/action/PostAction.java
   labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/views/topics/posting_edit_body.xhtml
   labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/views/topics/posting_new_body.xhtml
Log:
[JBFORUMS-148] Adding missing functionality for Polls and modifying old one.

Modified: labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/commands/post/PostTools.java
===================================================================
--- labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/commands/post/PostTools.java	2006-11-24 21:02:52 UTC (rev 7817)
+++ labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/commands/post/PostTools.java	2006-11-24 21:04:05 UTC (rev 7818)
@@ -17,9 +17,11 @@
 import org.jboss.portlet.forums.helper.ForumsTools;
 import org.jboss.portlet.forums.model.Message;
 import org.jboss.portlet.forums.model.Poll;
+import org.jboss.portlet.forums.model.PollOption;
 
 /**
  * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @author <a href="mailto:ryszard.kozmik at jboss.com">Ryszard Kozmik</a>
  * @version $Revision: 878 $
  */
 public class PostTools
@@ -58,26 +60,26 @@
    public static void validate(Poll poll)
       throws ValidationException
    {
-      //      if (isNullOrBlank(poll.title))
-      //      {
-      //         throw new ValidationException(CommandConstants.TYPE_INVALID_POLL_TITLE);
-      //      }
-      //      if (poll.options.size() < 2)
-      //      {
-      //         throw new ValidationException(CommandConstants.TYPE_TOO_FEW_POLL_OPTION);
-      //      }
-      if (poll.getOptions().size() > 10) // $board_config['max_poll_options']
-      {
-         throw new ValidationException(CommandConstants.TYPE_TOO_MANY_POLL_OPTION);
-      }
+        if (poll.getTitle()==null || poll.getTitle().trim().length()==0)
+        {
+           throw new ValidationException(CommandConstants.TYPE_INVALID_POLL_TITLE);
+        }
+        if (poll.getOptions().size() < 2)
+        {
+           throw new ValidationException(CommandConstants.TYPE_TOO_FEW_POLL_OPTION);
+        }
+        if (poll.getOptions().size() > 10) // $board_config['max_poll_options']
+        {
+           throw new ValidationException(CommandConstants.TYPE_TOO_MANY_POLL_OPTION);
+        }
 
-      for (Iterator i = poll.getOptions().iterator(); i.hasNext();)
-      {
-         String txt = (String)i.next();
-         if (ForumsTools.isNullOrBlank(txt))
-         {
-            throw new ValidationException(CommandConstants.TYPE_INVALID_POLL_OPTION);
-         }
-      }
-   }
+        for (Iterator i = poll.getOptions().iterator(); i.hasNext();)
+        {
+           PollOption option = (PollOption)i.next();
+           if (option.getQuestion()==null || option.getQuestion().trim().length()==0)
+           {
+              throw new ValidationException(CommandConstants.TYPE_INVALID_POLL_OPTION);
+           }
+        }
+    }
 }
\ No newline at end of file

Modified: labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/action/EditPost.java
===================================================================
--- labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/action/EditPost.java	2006-11-24 21:02:52 UTC (rev 7817)
+++ labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/action/EditPost.java	2006-11-24 21:04:05 UTC (rev 7818)
@@ -26,27 +26,26 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Collection;
+import java.util.TreeMap;
 
 import org.jboss.portlet.forums.ui.BaseController;
 import org.jboss.portlet.forums.ui.Constants;
 import org.jboss.portlet.forums.ui.ForumUtil;
 import org.jboss.portlet.forums.ui.JSFUtil;
 import org.jboss.portlet.forums.ui.PortalUtil;
-
 import org.jboss.portlet.forums.commands.ValidationException;
-import org.jboss.portlet.forums.model.Forum;
 import org.jboss.portlet.forums.model.Poll;
 import org.jboss.portlet.forums.model.PollOption;
-import org.jboss.portlet.forums.model.Poster;
 import org.jboss.portlet.forums.model.Message;
 import org.jboss.portlet.forums.model.Topic;
 import org.jboss.portlet.forums.model.Post;
 import org.jboss.portlet.forums.model.Attachment;
 
-/*
+/**
  * Created on May 2, 2006
  *
  * @author <a href="mailto:sohil.shah at jboss.com">Sohil Shah</a>
+ * @author <a href="mailto:ryszard.kozmik at jboss.com">Ryszard Kozmik</a>
  */
 public class EditPost extends PostAction
 {
@@ -127,7 +126,7 @@
         {                        	        
 	        //cleanout poll related data from this controller
 	        this.question = null;
-	        this.options = new ArrayList();
+	        this.options = new TreeMap();
 	        this.activeDuration = 0;
 	        
 	        navState = Constants.SUCCESS;
@@ -190,7 +189,7 @@
 	        //TODO: cleanup this poll update process............move this as a private method
 	        //setup poll information
 	        List localPollOptions = new ArrayList();
-            for(Iterator itr=this.options.iterator();itr.hasNext();)
+            for(Iterator itr=this.options.keySet().iterator();itr.hasNext();)
             {
                 String option = (String)itr.next();
                 PollOption pollOption = PortalUtil.createPollOption();

Modified: labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/action/NewTopic.java
===================================================================
--- labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/action/NewTopic.java	2006-11-24 21:02:52 UTC (rev 7817)
+++ labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/action/NewTopic.java	2006-11-24 21:04:05 UTC (rev 7818)
@@ -45,7 +45,7 @@
 
 /**
  * @author <a href="mailto:sohil.shah at jboss.com">Sohil Shah</a>
- *
+ * @author <a href="mailto:ryszard.kozmik at jboss.com">Ryszard Kozmik</a>
  */
 public class NewTopic extends PostAction
 {            
@@ -130,16 +130,18 @@
                poll.setTitle(this.question);               
                poll.setLength(this.activeDuration);
                List pollOptions = new ArrayList();
-               for(Iterator itr=this.options.iterator();itr.hasNext();)
+               for(Iterator itr=this.options.keySet().iterator();itr.hasNext();)
                {
                    String option = (String)itr.next();
                    PollOption pollOption = PortalUtil.createPollOption();
-                   pollOption.setQuestion(option);
+                   pollOption.setQuestion((String)options.get(option));
                    pollOption.setVotes(0);
                    pollOptions.add(pollOption);
                }
                poll.setOptions(pollOptions);
            }
+           
+           PostTools.validate(poll);
                                  
            //actually create the topic in this forum
            //use this method when poll and attachments are actually integrated

Modified: labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/action/PollController.java
===================================================================
--- labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/action/PollController.java	2006-11-24 21:02:52 UTC (rev 7817)
+++ labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/action/PollController.java	2006-11-24 21:04:05 UTC (rev 7818)
@@ -28,22 +28,14 @@
 import org.jboss.portlet.forums.model.PollOption;
 import org.jboss.portlet.forums.model.Poster;
 
-/*
+/**
  * Created on May 5, 2006
  *
  * @author <a href="mailto:sohil.shah at jboss.com">Sohil Shah</a>
+ * @author <a href="mailto:ryszard.kozmik at jboss.com">Ryszard Kozmik</a>
  */
 public class PollController extends ActionController 
 {
-    /**
-     * 
-     * Created on May 5, 2006
-     *
-     * @author <a href="mailto:sohil.shah at jboss.com">Sohil Shah</a>
-     */
-    public PollController()
-    {        
-    }
     
     /**
      * accepts a vote and processes it
@@ -80,7 +72,7 @@
 	            //perform the voting on the selected option
 	            if(poster!=null)
 	            {
-	                poll.getVoted().add(poster.getUserId());
+	                poll.getVoted().add(new Integer(poster.getUserId()));
 	            }
 	            selectedOption.incVotes();
 	        }

Modified: labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/action/PostAction.java
===================================================================
--- labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/action/PostAction.java	2006-11-24 21:02:52 UTC (rev 7817)
+++ labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/action/PostAction.java	2006-11-24 21:04:05 UTC (rev 7818)
@@ -26,16 +26,19 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
 import java.text.SimpleDateFormat;
 
+
 import org.jboss.portlet.forums.ui.Constants;
 import org.jboss.portlet.forums.ui.ForumUtil;
 import org.jboss.portlet.forums.ui.JSFUtil;
 import org.jboss.portlet.forums.ui.PortalUtil;
 import org.jboss.portlet.forums.helper.TempFileBinding;
-
+import org.jboss.portlet.forums.impl.AttachmentImpl;
 import org.jboss.portlet.forums.model.Attachment;
-import org.jboss.portlet.forums.impl.AttachmentImpl;
 import org.jboss.portlet.forums.model.Poll;
 import org.jboss.portlet.forums.model.PollOption;
 import org.jboss.portlet.forums.model.Post;
@@ -46,6 +49,7 @@
 
 /**
  * @author <a href="mailto:sohil.shah at jboss.com">Sohil Shah</a>
+ * @author <a href="mailto:ryszard.kozmik at jboss.com">Ryszard Kozmik</a>
  *
  */
 public abstract class PostAction extends ActionController
@@ -57,8 +61,10 @@
     
     //poll related data view data
     protected String question = null;
-    protected Collection options = new ArrayList();
+    protected Map options = new TreeMap();
     protected int		 activeDuration = 0;
+    protected String option = null;
+    //protected Map optionRow = null;
     
     
     //attachment related view data
@@ -177,7 +183,7 @@
      */
     public String getOption() 
     {
-        return null;
+        return this.option;
     }
     
     /**
@@ -185,16 +191,37 @@
      */
     public void setOption(String option) 
     {
+        this.option = option;
+    }
+    
+    public void addOption () {
         if(option!=null && option.trim().length()>0)
         {
-            this.options.add(option);
+            TreeMap map = (TreeMap)options;
+            this.options.put(Integer.toString(Integer.parseInt((String)map.lastKey())+1),option);
         }
+        this.option=null;
     }
     
-    public Collection getOptions()
+    public Map getOptions()
     {
+        if (this.options==null) {
+            this.options = new TreeMap();
+        }
         return this.options;
     }
+    
+    public void setOptions(Map options)
+    {
+        this.options=options;
+    }
+    
+    public Set getEntrySet() {
+        if (this.options==null) {
+            this.options = new TreeMap();
+        }
+        return this.options.entrySet();
+    }
             
     /**
      * @return Returns the attachmentComment.
@@ -326,7 +353,7 @@
         
         //cleanup poll related data
         this.question = null;
-        this.options = new ArrayList();
+        this.options = new TreeMap();
         this.activeDuration = 0;
         
         //cleanup attachment related data
@@ -388,11 +415,13 @@
 	        List pollOptions = poll.getOptions();
 	        if(pollOptions!=null && pollOptions.size()>0)
 	        {
-	            this.options = new ArrayList();
+	            this.options = new TreeMap();
+                    int counter = 1;
 	            for(Iterator itr=pollOptions.iterator();itr.hasNext();)
 	            {
 	                PollOption cour = (PollOption)itr.next();
-	                this.options.add(cour.getQuestion());
+	                this.options.put(Integer.toString(counter),cour.getQuestion());
+                        counter++;
 	            }
 	        }
         }
@@ -454,18 +483,32 @@
         String navState = null;
         try
         {
-            int optionIndex = Integer.parseInt(ForumUtil.getParameter(Constants.p_option));
-                                    
-            //actually remove the option value
-            optionIndex--;
-            ((ArrayList)this.options).remove(optionIndex);
+            String optionIndex = ForumUtil.getParameter(Constants.p_option);
+            this.options.remove(optionIndex);
         }
         catch(Exception e)
         {
             JSFUtil.handleException(e);
         }
         return navState;
-    }            
+    }
+    
+    public String updateOption()
+    {
+        String navState = null;
+        try
+        {
+            String optionIndex = ForumUtil.getParameter(Constants.p_option);
+            String value = ForumUtil.getParameter("option_"+optionIndex);
+            this.options.put(optionIndex,value);
+        }
+        catch(Exception e)
+        {
+            JSFUtil.handleException(e);
+        }
+        return navState;
+    }
+    
     //-----------------attachment related------------------------------------------------------------------------------------------    
     /**
      * 

Modified: labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/views/topics/posting_edit_body.xhtml
===================================================================
--- labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/views/topics/posting_edit_body.xhtml	2006-11-24 21:02:52 UTC (rev 7817)
+++ labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/views/topics/posting_edit_body.xhtml	2006-11-24 21:04:05 UTC (rev 7818)
@@ -500,12 +500,13 @@
 		   <tr>
 		      <td class="row1"><span class="gen"><b>${resource.Poll_option}</b></span></td>
 		      <td class="row2">
-		      		<span class="genmed">	      		
-			            <h:inputText id="option_${idx.index}" value="#{optionRow}" size="50" class="post" maxlength="255"/>
+		      		<span class="genmed">
+			            <input type="text" id="option_${idx.index}" name="option_${idx.index}" value="${optionRow}" size="50" class="post" maxlength="255"/>
 		            </span>&#160;            
-		            <h:commandButton action="updateOption" value="${resource.Update}" styleClass="liteoption"/>
+		            <h:commandButton action="#{editPost.updateOption}" value="${resource.Update}" styleClass="liteoption"
+                            onclick="selectOption(${idx.index});"/>
 		            <h:commandButton action="#{editPost.deleteOption}" value="${resource.Delete}" styleClass="liteoption"
-		            onclick="selectOption('${idx.index}');"/>            
+		            onclick="selectOption(${idx.index});"/>            
 		      </td>
 		   </tr>
 		</c:forEach>
@@ -518,7 +519,7 @@
 		   	<span class="genmed">   		
 		   		<h:inputText value="#{editPost.option}" size="50" maxlength="255" styleClass="post"/>
 		   	</span> &#160;   	
-		   	<h:commandButton action="addOption" value="${resource.Add_option}" styleClass="liteoption"/>
+		   	<h:commandButton action="#{editPost.addOption}" value="${resource.Add_option}" styleClass="liteoption"/>
 		   </td>
 		</tr>
 		

Modified: labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/views/topics/posting_new_body.xhtml
===================================================================
--- labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/views/topics/posting_new_body.xhtml	2006-11-24 21:02:52 UTC (rev 7817)
+++ labs/jbossforums/branches/forums26/forums/src/resources/portal-forums-war/views/topics/posting_new_body.xhtml	2006-11-24 21:04:05 UTC (rev 7818)
@@ -499,16 +499,17 @@
 		
 		<!-- update poll options already added -->
 		<input type="hidden" name="o"/>
-		<c:forEach items="#{newTopic.options}" var="optionRow" varStatus="idx">
+		<c:forEach items="${newTopic.options}" var="optionRow" varStatus="idx">
 		   <tr>
 		      <td class="row1"><span class="gen"><b>${resource.Poll_option}</b></span></td>
 		      <td class="row2">
-		      		<span class="genmed">	      		
-			            <h:inputText id="option_${idx.index}" value="#{optionRow}" size="50" class="post" maxlength="255"/>
+		      		<span class="genmed">
+			            <input type="text" id="option_${idx.index}" name="option_${idx.index}" value="${optionRow}" size="50" class="post" maxlength="255"/>
 		            </span>&#160;            
-		            <h:commandButton action="updateOption" value="${resource.Update}" styleClass="liteoption"/>
+		            <h:commandButton action="#{newTopic.updateOption}" value="${resource.Update}" styleClass="liteoption"
+                            onclick="selectOption(${idx.index});"/>
 		            <h:commandButton action="#{newTopic.deleteOption}" value="${resource.Delete}" styleClass="liteoption"
-		            onclick="selectOption('${idx.index}');"/>            
+		            onclick="selectOption(${idx.index});"/>            
 		      </td>
 		   </tr>
 		</c:forEach>
@@ -521,7 +522,7 @@
 		   	<span class="genmed">   		
 		   		<h:inputText value="#{newTopic.option}" size="50" maxlength="255" styleClass="post"/>
 		   	</span> &#160;   	
-		   	<h:commandButton action="addOption" value="${resource.Add_option}" styleClass="liteoption"/>
+		   	<h:commandButton action="#{newTopic.addOption}" value="${resource.Add_option}" styleClass="liteoption"/>
 		   </td>
 		</tr>
 		




More information about the jboss-svn-commits mailing list