Author: musachy Date: Mon Jun 11 12:36:57 2007 New Revision: 546231 URL: http://svn.apache.org/viewvc?view=rev&rev=546231 Log: WW-1848 Showcase, create an interactive OGNL demo
Added: struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/jsp_3.jsp struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/jsp_4.jsp Modified: struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/example-action.jsp struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/index.jsp struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/ognl_9.jsp Modified: struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/example-action.jsp URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/example-action.jsp?view=diff&rev=546231&r1=546230&r2=546231 ============================================================================== --- struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/example-action.jsp (original) +++ struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/example-action.jsp Mon Jun 11 12:36:57 2007 @@ -5,41 +5,41 @@ response.setDateHeader ("Expires", 0); //prevents caching at the proxy server %> <pre style="font-style: normal;"> -package org.apache.struts2.showcase.action; +<span class="kw">package</span> org.apache.struts2.showcase.action; -import java.util.Arrays; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +<span class="kw">import</span> java.util.Arrays; +<span class="kw">import</span> java.util.Date; +<span class="kw">import</span> java.util.HashMap; +<span class="kw">import</span> java.util.List; +<span class="kw">import</span> java.util.Map; -import com.opensymphony.xwork2.ActionSupport; +<span class="kw">import</span> com.opensymphony.xwork2.ActionSupport; -public class ExampleAction extends ActionSupport { - public static final String CONSTANT = "Struts Rocks!"; +<span class="kw">public class</span> ExampleAction <span class="kw">extends</span> ActionSupport { + <span class="kw">public static final</span> String CONSTANT = "Struts Rocks!"; - public static Date getCurrentDate() { + <span class="kw">public static</span> Date getCurrentDate() { return new Date(); } - public String getName() { + <span class="kw">public</span> String getName() { return "John Galt"; } - public String[] getBands() { + <span class="kw">public</span> String[] getBands() { return new String[] { "Pink Floyd", "Metallica", "Guns & Roses" }; } - public List<String> getMovies() { + <span class="kw">public</span> List<String> getMovies() { return Arrays.asList("Lord of the Rings", "Matrix"); } - public Book getBook() { - return new Book("Iliad", "Homer"); + <span class="kw">public</span> Book getBook() { + <span class="kw">return</span> new Book("Iliad", "Homer"); } - public Map<String, Book> getBooks() { - Map<String, Book> books = new HashMap<String, Book>(); + <span class="kw">public</span> Map<String, Book> getBooks() { + Map<String, Book> books = new HashMap<String, Book>(); books.put("Iliad", new Book("Iliad", "Homer")); books.put("The Republic", new Book("The Replublic", "Plato")); books.put("Thus Spake Zarathustra", new Book("Thus Spake Zarathustra", @@ -48,28 +48,28 @@ } } -class Book { - private String title; - private String author; +<span class="kw">class</span> Book { + <span class="kw">private</span> String title; + <span class="kw">private</span> String author; - public Book(String title, String author) { + <span class="kw">public</span> Book(String title, String author) { this.title = title; this.author = author; } - public String getTitle() { - return title; + <span class="kw">public</span> String getTitle() { + <span class="kw">return</span> title; } - public void setTitle(String title) { + <span class="kw">public void</span> setTitle(String title) { this.title = title; } - public String getAuthor() { + <span class="kw">public</span> String getAuthor() { return author; } - public void setAuthor(String author) { + <span class="kw">public void</span> setAuthor(String author) { this.author = author; } } Modified: struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/index.jsp URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/index.jsp?view=diff&rev=546231&r1=546230&r2=546231 ============================================================================== --- struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/index.jsp (original) +++ struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/index.jsp Mon Jun 11 12:36:57 2007 @@ -19,7 +19,7 @@ var ognlBase = "${ognlBase}"; var jspBase = "${jspBase}"; var ognlCount = 10; - var jspCount = 3; + var jspCount = 5; dojo.addOnLoad(function() { var classSrc = dojo.byId("classSrc"); @@ -33,6 +33,7 @@ }); function startOgnl() { + selectOGNLTab(); index = -1; runningOgnl = true; change(1); @@ -72,6 +73,10 @@ function selectJSPTab() { dojo.widget.byId("mainTabContainer").selectTab("jspTab"); } + + function selectOGNLTab() { + dojo.widget.byId("mainTabContainer").selectTab("ognlTab"); + } function change(delta) { index+=delta; @@ -170,6 +175,10 @@ pre { font-family:Verdana,Geneva,Arial,Helvetica,sans-serif; font-style: italic; + } + span.kw { + color: rgb(127, 0, 85); + font-weight: bold;; } </style> </head> Added: struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/jsp_3.jsp URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/jsp_3.jsp?view=auto&rev=546231 ============================================================================== --- struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/jsp_3.jsp (added) +++ struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/jsp_3.jsp Mon Jun 11 12:36:57 2007 @@ -0,0 +1,65 @@ +<% + request.setAttribute("decorator", "none"); + response.setHeader("Cache-Control","no-cache"); //HTTP 1.1 + response.setHeader("Pragma","no-cache"); //HTTP 1.0 + response.setDateHeader ("Expires", 0); //prevents caching at the proxy server +%> +<p> + <b><i>set</i> tag</b> +</p> +<p> + The <i>set</i> tag sets the variable with the name specified in the <i>name</i> attribute to + the value specified in the <i>value</i> attribute in the scope + entered in the <i>scope</i> attribute. The available scopes are: + <ul> + <li>application - application scope according to servlet spec</li> + <li>session - session scope according to servlet spec</li> + <li>request - request scope according to servlet spec</li> + <li>page - page scope according to servlet sepc</li> + <li>action - the value will be set in the request scope and Struts' action context</li> + + </ul> +</p> +<p> + This example sets <i>favouriteBand</i> in the request scope to the first element of the <i>bands</i> property: +</p> +<p> + <pre id="example0"> + <s:set name="favouriteBand" value="bands[0]" /> + <s:property value="#favouriteBand" /> + </pre> +</p> +<p> + <a href="#" onclick="execJSP('example0')">Do it for me</a> +</p> +<p> + <b><i>url</i> tag</b> +</p> +<p> + The <i>url</i> tag is used to build urls (who would have guessed!). To build an url mapping to + an action, set the <i>namespace</i> and <i>action</i> attributes. The url will be stored under + the name specified in the <i>id</i> attribute. <b>url tag uses the <i>id</i> attribute while + the <i>set</i> tag uses name</b>. To specify a value (no action lookup), just use the <i>value</i> + attribute. <i>param</i> tags can be nested inside the <i>url</i> tag to add parameters to the url. +</p> +<p> + First link creates a url that maps to an action, second one creates a url to google, passing one parameter: +</p> +<p> + <pre id="example1"> + <s:url id="evalAction" namespace="/nodecorate" action="jspEval" /> + <s:a href="%{#evalAction}" >Eval</s:a> + + <s:url id="google" value="http://www.google.com" > + <s:param name="q" value="%{'Struts 2'}" /> + </s:url> + <s:a href="%{#google}" >Eval</s:a> + </pre> +</p> +<p> + <a href="#" onclick="execJSP('example1')">Do it for me</a> +</p> +<p> + <a href="#" onclick="window.open('http://struts.apache.org/2.x/docs/set.html')">[More on the <i>set</i> tag]</a> + <a href="#" onclick="window.open('http://struts.apache.org/2.x/docs/url.html')">[More on the <i>url</i> tag]</a> +</p> \ No newline at end of file Added: struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/jsp_4.jsp URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/jsp_4.jsp?view=auto&rev=546231 ============================================================================== --- struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/jsp_4.jsp (added) +++ struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/jsp_4.jsp Mon Jun 11 12:36:57 2007 @@ -0,0 +1,16 @@ +<% + request.setAttribute("decorator", "none"); + response.setHeader("Cache-Control","no-cache"); //HTTP 1.1 + response.setHeader("Pragma","no-cache"); //HTTP 1.0 + response.setDateHeader ("Expires", 0); //prevents caching at the proxy server +%> +<p> + <b>More on JSP tags</b> +</p> +<p> + Struts 2 provides many more tags which you can learn about + <a href="#" onclick="window.open('http://cwiki.apache.org/confluence/display/WW/Tag+Reference')">here</a> +</p> +<br/> +You can keep playing with the JSP console or +<a href="#" onclick="startOgnl()">Start OGNL Interactive Demo</a> \ No newline at end of file Modified: struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/ognl_9.jsp URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/ognl_9.jsp?view=diff&rev=546231&r1=546230&r2=546231 ============================================================================== --- struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/ognl_9.jsp (original) +++ struts/struts2/trunk/apps/showcase/src/main/webapp/interactive/ognl_9.jsp Mon Jun 11 12:36:57 2007 @@ -14,4 +14,5 @@ <p> To learn more see the <a href="#" onclick="window.open('http://www.ognl.org/2.6.9/Documentation/html/LanguageGuide/index.html')">[OGNL Documentation]</a> </p> +You can keep playing with the OGNL console or <a href="#" onclick="startJSP()">Start JSP Interactive Demo</a>