[weld-commits] Weld SVN: r6459 - in examples/trunk/jsf/pastecode/src/main: webapp and 1 other directories.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Wed Jun 16 15:21:33 EDT 2010


Author: pete.muir at jboss.org
Date: 2010-06-16 15:21:32 -0400 (Wed, 16 Jun 2010)
New Revision: 6459

Added:
   examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/PasteWindow.java
Removed:
   examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Paster.java
Modified:
   examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManagerImpl.java
   examples/trunk/jsf/pastecode/src/main/webapp/WEB-INF/faces-config.xml
   examples/trunk/jsf/pastecode/src/main/webapp/display.xhtml
   examples/trunk/jsf/pastecode/src/main/webapp/help.xhtml
   examples/trunk/jsf/pastecode/src/main/webapp/home.xhtml
   examples/trunk/jsf/pastecode/src/main/webapp/rightMenuDefault.xhtml
Log:
tidy up paster, tidy up xhtml

Modified: examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManagerImpl.java
===================================================================
--- examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManagerImpl.java	2010-06-16 19:15:22 UTC (rev 6458)
+++ examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/CodeFragmentManagerImpl.java	2010-06-16 19:21:32 UTC (rev 6459)
@@ -30,7 +30,9 @@
 import javax.ejb.Stateless;
 import javax.ejb.TransactionAttribute;
 import javax.ejb.TransactionAttributeType;
+import javax.enterprise.inject.Produces;
 import javax.inject.Inject;
+import javax.inject.Named;
 import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
 import javax.persistence.Query;
@@ -142,6 +144,7 @@
       }
    }
 
+   @Produces @Named
    public List<CodeFragment> getRecentCodeFragments()
    {
       Query query = entityManager.createQuery("SELECT c FROM CodeFragment c WHERE hash=null ORDER BY datetime DESC ");

Copied: examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/PasteWindow.java (from rev 6456, examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Paster.java)
===================================================================
--- examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/PasteWindow.java	                        (rev 0)
+++ examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/PasteWindow.java	2010-06-16 19:21:32 UTC (rev 6459)
@@ -0,0 +1,107 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.weld.examples.pastecode.session;
+
+import javax.ejb.EJBException;
+import javax.enterprise.inject.Model;
+import javax.inject.Inject;
+
+import org.jboss.weld.examples.pastecode.model.CodeFragment;
+
+/**
+ * PasteWindow holds the code fragment and other selections when a code fragment is viewed and entered
+ *
+ */
+ at Model
+public class PasteWindow
+{
+   private CodeFragment codeFragment;
+
+   private String codeFragmentId;
+
+   private Theme theme;
+
+   private boolean privateFragment;
+
+   @Inject
+   private CodeFragmentManager codeFragmentManager;
+
+   public PasteWindow()
+   {
+      this.codeFragment = new CodeFragment();
+      this.theme = Theme.DEFAULT;
+   }
+
+   // The send method is called when we hit the Send button
+   public String send()
+   {
+      codeFragmentManager.addCodeFragment(codeFragment, privateFragment);
+      return "success";
+   }
+
+   // loadCodeFragment is a view action called to load the code fragment from
+   // the database when requested for viewing
+   public void loadCodeFragment()
+   {
+      this.codeFragment = codeFragmentManager.getCodeFragment(codeFragmentId);
+
+      if (this.codeFragment == null)
+      {
+         throw new EJBException("Could not read entity with given id value");
+      }
+   }
+
+   public CodeFragment getCodeFragment()
+   {
+      return codeFragment;
+   }
+
+   public String getCodeFragmentId()
+   {
+      return codeFragmentId;
+   }
+
+   public void setCodeFragmentId(String codeFragmentId)
+   {
+      this.codeFragmentId = codeFragmentId;
+   }
+
+   public Theme getTheme()
+   {
+      return theme;
+   }
+
+   public void setTheme(Theme theme)
+   {
+      this.theme = theme;
+   }
+
+   public boolean isPrivateFragment()
+   {
+      return privateFragment;
+   }
+
+   public void setPrivateFragment(boolean privateFragment)
+   {
+      this.privateFragment = privateFragment;
+   }
+}

Deleted: examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Paster.java
===================================================================
--- examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Paster.java	2010-06-16 19:15:22 UTC (rev 6458)
+++ examples/trunk/jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/Paster.java	2010-06-16 19:21:32 UTC (rev 6459)
@@ -1,124 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.weld.examples.pastecode.session;
-
-import java.util.List;
-
-import javax.ejb.EJBException;
-import javax.enterprise.inject.Model;
-import javax.enterprise.inject.Produces;
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.jboss.weld.examples.pastecode.model.CodeFragment;
-
- at Model
-public class Paster
-{
-   private CodeFragment code;
-
-   private String codeId;
-
-   private String brush;
-
-   private Theme theme;
-
-   private boolean secured = false;
-
-   @Inject
-   private CodeFragmentManager codeFragmentManager;
-
-   public Paster()
-   {
-      this.code = new CodeFragment();
-      this.theme = Theme.DEFAULT;
-   }
-
-   public String paste()
-   {
-      this.codeId = codeFragmentManager.addCodeFragment(code, secured);
-      return "success";
-   }
-
-   /* used for access from jsf page */
-   @Produces
-   @Named("code")
-   public CodeFragment getPasterCodeInstance()
-   {
-      return this.code;
-   }
-
-   public void loadCode()
-   {
-      this.code = codeFragmentManager.getCodeFragment(codeId);
-
-      if (this.code == null)
-         throw new EJBException("Could not read entity with given id value");
-
-      this.brush = this.code.getLanguage().getBrush();
-   }
-
-   public List<CodeFragment> getCodes()
-   {
-      return codeFragmentManager.getRecentCodeFragments();
-   }
-
-   public String getCodeId()
-   {
-      return codeId;
-   }
-
-   public void setCodeId(String codeId)
-   {
-      this.codeId = codeId;
-   }
-
-   public Theme getTheme()
-   {
-      return theme;
-   }
-   
-   public void setTheme(Theme theme)
-   {
-      this.theme = theme;
-   }
-   
-   public String getBrush()
-   {
-      return brush;
-   }
-
-   public void setBrush(String brush)
-   {
-      this.brush = brush;
-   }
-
-   public boolean isSecured()
-   {
-      return secured;
-   }
-
-   public void setSecured(boolean secured)
-   {
-      this.secured = secured;
-   }
-}

Modified: examples/trunk/jsf/pastecode/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- examples/trunk/jsf/pastecode/src/main/webapp/WEB-INF/faces-config.xml	2010-06-16 19:15:22 UTC (rev 6458)
+++ examples/trunk/jsf/pastecode/src/main/webapp/WEB-INF/faces-config.xml	2010-06-16 19:21:32 UTC (rev 6459)
@@ -8,8 +8,8 @@
    <navigation-rule>
       <from-view-id>/home.xhtml</from-view-id>
       <navigation-case>
-         <from-action>#{paster.paste}</from-action>
-         <to-view-id>/#{paster.codeId}</to-view-id>
+         <from-action>#{pasteWindow.send}</from-action>
+         <to-view-id>/#{pasteWindow.codeFragmentId}</to-view-id>
          <redirect />
       </navigation-case>
    </navigation-rule>

Modified: examples/trunk/jsf/pastecode/src/main/webapp/display.xhtml
===================================================================
--- examples/trunk/jsf/pastecode/src/main/webapp/display.xhtml	2010-06-16 19:15:22 UTC (rev 6458)
+++ examples/trunk/jsf/pastecode/src/main/webapp/display.xhtml	2010-06-16 19:21:32 UTC (rev 6459)
@@ -8,8 +8,10 @@
   <ui:composition template="template.xhtml">
      <ui:define name="viewMetadata">
        <f:metadata>
-         <f:viewParam name="id" value="#{paster.codeId}"/>
-         <f:event type="preRenderView" listener="#{paster.loadCode}"/>
+         <!-- Bind the id to the pasteWindow, this allows us to load the correct fragment -->
+         <f:viewParam name="id" value="#{pasteWindow.codeFragmentId}"/>
+         <!-- Ask for the fragment to be loaded -->
+         <f:event type="preRenderView" listener="#{pasteWindow.loadCodeFragment}"/>
        </f:metadata>      
     </ui:define>    
   
@@ -36,15 +38,15 @@
 
 		   			<h:panelGroup>
 		   				<h:outputLabel for="user" value="User: "/>   		
-						<h:outputText id="user" maxlength="30" size="30" value="#{code.user}"/>
+						<h:outputText id="user" maxlength="30" size="30" value="#{pasteWindow.codeFragment.user}"/>
 		   			</h:panelGroup>
 
 		   			<h:panelGroup>
 		   				<h:outputLabel for="theme" value="Choose theme: "/>   
-		   				<h:selectOneMenu id="theme" value="#{paster.theme}" onchange="chooseStyle(this.value);"> <!-- this.form.submit() -->		
+		   				<h:selectOneMenu id="theme" value="#{pasteWindow.theme}" onchange="chooseStyle(this.value);"> <!-- this.form.submit() -->		
 		   					<f:selectItems value="#{themes}" var="theme" itemLabel="#{theme.name}" itemValue="#{theme.name}" />
 			   			</h:selectOneMenu>
-			   			<a href="download?id=#{code.hash == null ? code.id : code.hash}" style="text-decoration: none;"><input type="button" value="Download file" /></a>
+			   			<a href="download?id=#{pasteWindow.codeFragment.hash == null ? pasteWindow.codeFragment.id : pasteWindow.codeFragment.hash}" style="text-decoration: none;"><input type="button" value="Download file" /></a>
 		   			</h:panelGroup>
 
 		   			<h:panelGroup style="text-align:right;">			   				   			
@@ -56,13 +58,13 @@
 		   		
 		   		<h:outputText value="Pasted code: "/>
 		   		<div id="codearea" style="width:99%; border: 1px solid #7F7F7F; height:450px; overflow:scroll;">			   		
-			   			<pre class="brush: #{paster.brush}">#{code.text}</pre>	
+			   			<pre class="brush: #{pasteWindow.codeFragment.language.brush}">#{pasteWindow.codeFragment.text}</pre>	
 		   		</div>
 		   		
 		   		&nbsp;<br/>
 		   		<h:outputLabel for="note" value="Note: "/>
 		   		<div >		   			 
-		   			<h:outputText id="note" value="#{code.note}"/>		   			
+		   			<h:outputText id="note" value="#{pasteWindow.codeFragment.note}"/>		   			
 		   		</div>
    		</div>
    	</ui:define>

Modified: examples/trunk/jsf/pastecode/src/main/webapp/help.xhtml
===================================================================
--- examples/trunk/jsf/pastecode/src/main/webapp/help.xhtml	2010-06-16 19:15:22 UTC (rev 6458)
+++ examples/trunk/jsf/pastecode/src/main/webapp/help.xhtml	2010-06-16 19:21:32 UTC (rev 6459)
@@ -15,30 +15,31 @@
 	   	<br/>
 	   	<strong>Paste Code:</strong><br/>
 	   	<ul>
-	   	 <li>Enter your nick - This is optional, if it is not entered the code will be listed under "Anonymous" user</li>
-	   	 <li>Choose a language of your code - This way you can define formatting of code after submitting the form</li>
-	   	 <li>Choose if this code is private - When this option is chosen the application will generate a hash value of your code and will provide you with
-	   	 a unique link (something like http://localhost:8080/weld-pastecode/582ad4b5ed409ec8b81c6e33ee8b72377890bc86). Furthemore your code will not be
-	   	 listed in the right panel and cannot even be found through a search capability. </li>
-	   	 <li>Enter your code and a note you would like to send with the code</li>
-	   	 <li>Submit the form and forward the resulting link</li>  
+	   	 <li>Enter your nick - this is optional, if omitted, your paste will be anonymous</li>
+	   	 <li>Choose the language of your code - this allows syntax highlighting</li>
+	   	 <li>Choose if this code is private - when this option is chosen the application will generate a hash value of your code and will provide you with
+	   	 a unique link (something like http://localhost:8080/weld-pastecode/582ad4). Furthemore your code will not be
+	   	 listed in the right panel and cannot be found through the search.</li>
+	   	 <li>Enter your code - you can also add a note</li>
+	   	 <li>Submit the form!</li>  
 	   	</ul>
 	   	
-	   	<strong>Search Code:</strong><br/>
+	   	<strong>Search Pastes:</strong><br/>
 	   	<ul>
-	   		<li>Go to a history page - Now you can see all the posts with pagination</li>
-	   		<li>Enter data for searching - You can combine all the data together.</li>
+	   		<li>Go to a history page - now you can see all the posts with pagination</li>
+	   		<li>You can narrow down the pastes by using the search form</li>
 	   	</ul>
 	   		   	
 	   	<strong>Weld Features Covered:</strong><br/>
 	   	
 	   	<ul>
-	   		<li>Injecting into POJO, EJB (SFSB), Servlet</li>
-	   		<li>Annotations @ApplicationScoped, @Model, @SessionScoped et al.</li>
-	   		<li>Producer named methods</li>
-	   		<li>Decorators - This feature is used to log transactions during which a code larger than 65kB is stored to a database</li>
+	   		<li>Injection into POJO, EJBs and Servlets</li>
+	   		<li>Use of WAR packaging</li>
+	   		<li>Producers</li>
+	   		<li>JPA access</li>
+	   		<li>Decorators</li>
 	   	</ul>
-	   	<br/><br/><strong>Enjoy work with WELD !</strong>
+	   	<br/><br/><strong>Enjoy work with Weld!</strong>
 	   			 
 	</div>
   </ui:define>

Modified: examples/trunk/jsf/pastecode/src/main/webapp/home.xhtml
===================================================================
--- examples/trunk/jsf/pastecode/src/main/webapp/home.xhtml	2010-06-16 19:15:22 UTC (rev 6458)
+++ examples/trunk/jsf/pastecode/src/main/webapp/home.xhtml	2010-06-16 19:21:32 UTC (rev 6459)
@@ -18,28 +18,28 @@
 		   		<h:panelGrid columns="3" style="width: 100%">
 		   			<h:panelGroup>
 		   				<h:outputLabel for="user" value="Your nick: "/>   		
-						<h:inputText id="user" maxlength="30" size="30" value="#{code.user}"/>
+						<h:inputText id="user" maxlength="30" size="30" value="#{pasteWindow.codeFragment.user}"/>
 		   			</h:panelGroup>
 		   			
 		   			<h:panelGroup>
 		   				<h:outputLabel for="language" value="Language: "/>   
-		   				<h:selectOneMenu id="language" value="#{code.language}">		
+		   				<h:selectOneMenu id="language" value="#{pasteWindow.codeFragment.language}">		
 		   					<f:selectItems value="#{languages}" var="language" itemLabel="#{language.name}" itemValue="#{language}" />
 			   			</h:selectOneMenu>
 			   		</h:panelGroup>	
 			   		<h:panelGroup style="text-align:right;">			   				   			
 		   				<h:outputLabel for="secured" value="Private: "/>   
-		   				<h:selectBooleanCheckbox id="secured" value="#{paster.secured}"/>
+		   				<h:selectBooleanCheckbox id="secured" value="#{pasteWindow.privateFragment}"/>
 		   			</h:panelGroup>
 		   		</h:panelGrid>
 		   		<h:outputLabel for="text" value="Code: "/>
-		   		<h:inputTextarea id="text" style="width: 98%" cols="17" rows="18" value="#{code.text}"/>
+		   		<h:inputTextarea id="text" style="width: 98%" cols="17" rows="18" value="#{pasteWindow.codeFragment.text}"/>
 		   		&nbsp;
 		   		<h:outputLabel for="note" value="Note: (optional) "/> 
-		   		<h:inputTextarea style="width: 98%" cols="17" rows="4" id="note" value="#{code.note}"/>
+		   		<h:inputTextarea style="width: 98%" cols="17" rows="4" id="note" value="#{pasteWindow.codeFragment.note}"/>
 		   		<div style="width: 98%; text-align:right;">
 		   			<h:outputLabel for="send" value="Paste code: "/>
-		   			<h:commandButton action="#{paster.paste}" id="send" value="      Send      "/>		   			
+		   			<h:commandButton action="#{pasteWindow.send}" id="send" value="      Send      "/>		   			
 		   		</div>
 	   		
    		</div>

Modified: examples/trunk/jsf/pastecode/src/main/webapp/rightMenuDefault.xhtml
===================================================================
--- examples/trunk/jsf/pastecode/src/main/webapp/rightMenuDefault.xhtml	2010-06-16 19:15:22 UTC (rev 6458)
+++ examples/trunk/jsf/pastecode/src/main/webapp/rightMenuDefault.xhtml	2010-06-16 19:21:32 UTC (rev 6459)
@@ -9,10 +9,10 @@
 			<div class="recentPastes">
 			  <div class="recentPastesHeader">Recent pastes</div>
 			
-			  <ui:repeat value="#{paster.codes}" var="varcode">
+			  <ui:repeat value="#{recentCodeFragments}" var="codeFragment">
 			    <div class="recentPaste">
-          	<h:outputLink id="user" value="#{varcode.id}">#{varcode.user}</h:outputLink>
-          	<span class="recentPasteLang">#{varcode.language}</span><span> | </span>#{varcode.friendlyDate}
+          	<h:outputLink id="user" value="#{codeFragment.id}">#{codeFragment.user}</h:outputLink>
+          	<span class="recentPasteLang">#{codeFragment.language.name}</span><span> | </span>#{codeFragment.friendlyDate}
           </div>		    
 			  </ui:repeat>
 



More information about the weld-commits mailing list