# MazeController.jpf Sample

This topic inludes the source code for the MazeController.jpf Sample.

## Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/SamplesApp/WebApp/handlingData/traditional_vs_pageFlow_webApp/pageFlow_webApp/

## Sample Source Code

`001 package handlingData.traditional_vs_pageFlow_webApp.pageFlow_webApp; 002 import com.bea.wlw.netui.pageflow.FormData; 003 import com.bea.wlw.netui.pageflow.Forward; 004 import com.bea.wlw.netui.pageflow.PageFlowController; 005 import java.io.IOException; 006 import java.text.DecimalFormat; 007 import weblogic.jws.proxies.MazeGeneratorSoap; 008 import weblogic.jws.proxies.MazeGenerator_Impl; 009 010 /** 011 * @jpf:controller 012 * @jpf:view-properties view-properties:: 013 * <!-- This data is auto-generated. Hand-editing this section is not recommended. --> 014 * <view-properties> 015 * <pageflow-object id="pageflow:/handlingData/traditional_vs_pageFlow_webApp/pageFlow_webApp/mazeController.jpf"/> 016 * <pageflow-object id="action:begin.do"> 017 * <property value="40" name="x"/> 018 * <property value="280" name="y"/> 019 * </pageflow-object> 020 * <pageflow-object id="action:printRandomMaze.do#handlingData.traditional_vs_pageFlow_webApp.pageFlow_webApp.mazeController.MazeForm"> 021 * <property value="380" name="x"/> 022 * <property value="400" name="y"/> 023 * </pageflow-object> 024 * <pageflow-object id="action:getRandomMaze.do#handlingData.traditional_vs_pageFlow_webApp.pageFlow_webApp.mazeController.MazeForm"> 025 * <property value="380" name="x"/> 026 * <property value="180" name="y"/> 027 * </pageflow-object> 028 * <pageflow-object id="action-call:@page:specifyMaze.jsp@#@action:printRandomMaze.do#handlingData.traditional_vs_pageFlow_webApp.pageFlow_webApp.mazeController.MazeForm@"> 029 * <property value="256,300,300,344" name="elbowsX"/> 030 * <property value="272,272,392,392" name="elbowsY"/> 031 * <property value="East_1" name="fromPort"/> 032 * <property value="West_1" name="toPort"/> 033 * </pageflow-object> 034 * <pageflow-object id="action-call:@page:specifyMaze.jsp@#@action:getRandomMaze.do#handlingData.traditional_vs_pageFlow_webApp.pageFlow_webApp.mazeController.MazeForm@"> 035 * <property value="256,300,300,344" name="elbowsX"/> 036 * <property value="272,272,172,172" name="elbowsY"/> 037 * <property value="East_1" name="fromPort"/> 038 * <property value="West_1" name="toPort"/> 039 * </pageflow-object> 040 * <pageflow-object id="page:specifyMaze.jsp"> 041 * <property value="220" name="x"/> 042 * <property value="280" name="y"/> 043 * </pageflow-object> 044 * <pageflow-object id="page:mazeDisplay.jsp"> 045 * <property value="540" name="x"/> 046 * <property value="300" name="y"/> 047 * </pageflow-object> 048 * <pageflow-object id="page:errorpage.jsp"> 049 * <property value="660" name="x"/> 050 * <property value="120" name="y"/> 051 * </pageflow-object> 052 * <pageflow-object id="forward:path#success#specifyMaze.jsp#@action:begin.do@"> 053 * <property value="76,130,130,184" name="elbowsX"/> 054 * <property value="272,272,272,272" name="elbowsY"/> 055 * <property value="East_1" name="fromPort"/> 056 * <property value="West_1" name="toPort"/> 057 * <property value="success" name="label"/> 058 * </pageflow-object> 059 * <pageflow-object id="forward:path#success#mazeDisplay.jsp#@action:printRandomMaze.do#handlingData.traditional_vs_pageFlow_webApp.pageFlow_webApp.mazeController.MazeForm@"> 060 * <property value="416,460,460,504" name="elbowsX"/> 061 * <property value="392,392,303,303" name="elbowsY"/> 062 * <property value="East_1" name="fromPort"/> 063 * <property value="West_2" name="toPort"/> 064 * <property value="success" name="label"/> 065 * </pageflow-object> 066 * <pageflow-object id="forward:path#success#mazeDisplay.jsp#@action:getRandomMaze.do#handlingData.traditional_vs_pageFlow_webApp.pageFlow_webApp.mazeController.MazeForm@"> 067 * <property value="416,460,460,504" name="elbowsX"/> 068 * <property value="183,183,292,292" name="elbowsY"/> 069 * <property value="East_2" name="fromPort"/> 070 * <property value="West_1" name="toPort"/> 071 * <property value="success" name="label"/> 072 * </pageflow-object> 073 * <pageflow-object id="formbeanprop:handlingData.traditional_vs_pageFlow_webApp.pageFlow_webApp.mazeController.MazeForm#cols#java.lang.String"/> 074 * <pageflow-object id="formbeanprop:handlingData.traditional_vs_pageFlow_webApp.pageFlow_webApp.mazeController.MazeForm#rows#java.lang.String"/> 075 * <pageflow-object id="formbean:handlingData.traditional_vs_pageFlow_webApp.pageFlow_webApp.mazeController.MazeForm"/> 076 * </view-properties> 077 * :: 078 */ 079 public class mazeController extends PageFlowController 080 { 081 082 /** 083 * @jpf:action 084 * @jpf:forward name="success" path="specifyMaze.jsp" 085 */ 086 protected Forward begin() 087 { 088 return new Forward("success"); 089 } 090 091 /** 092 * @jpf:action 093 * @jpf:forward name="success" path="mazeDisplay.jsp" 094 */ 095 protected Forward printRandomMaze(MazeForm form) 096 throws Exception 097 { 098 099 /* 100 * If the user invokes printRandomMaze, we just call soapProxy.printRandomMaze 101 * and pass the output directly to the JSP. 102 */ 103 MazeGenerator_Impl proxy = new MazeGenerator_Impl("http://localhost:7001/WebServices/proxy/mazegen/MazeGenerator.jws?WSDL"); 104 MazeGeneratorSoap soapProxy = proxy.getMazeGeneratorSoap(); 105 106 int rows, cols; 107 try { 108 rows = Integer.parseInt( form.getRows() ); 109 } 110 catch (NumberFormatException ex) { 111 String msg = "Number of rows must be a valid integer (entered value: '" + 112 form.getRows() + "')"; 113 throw(new NumberFormatException(msg)); 114 } 115 try { 116 cols = Integer.parseInt( form.getCols() ); 117 } 118 catch (NumberFormatException ex) { 119 String msg = "Number of columns must be a valid integer (entered value: '" + 120 form.getCols() + "')"; 121 throw(new NumberFormatException(msg)); 122 } 123 124 // Pass the results on the "request" object. 125 getRequest().setAttribute("message", "<p>You invoked the <b>MazeGenerator</b> web service's <b>printRandomMaze</b>method. This is the response:</p>"); 126 getRequest().setAttribute("mazeResult", soapProxy.printRandomMaze(rows, cols) ); 127 128 return new Forward("success"); 129 } 130 131 /** 132 * @jpf:action 133 * @jpf:forward name="success" path="mazeDisplay.jsp" 134 */ 135 protected Forward getRandomMaze(MazeForm form) 136 throws Exception 137 { 138 /* 139 * If the user invokes getRandomMaze, call soapProxy.getRandomMaze and then convert 140 * the output into images that draw the maze. For each cell of the maze, there are 141 * 16 possible configurations of walls. The configuration is encoded in the value 142 * returned from getRandomMaze for that cell. The encoding is defined in 143 * MazeGenerator.jws; each cell is a 4 bit field with a bit each for left, top, right 144 * and bottom walls. 145 * 146 * Prepared images for each cell configuration are stored in the images directory. 147 */ 148 MazeGenerator_Impl proxy = new MazeGenerator_Impl("http://localhost:7001/WebServices/proxy/mazegen/MazeGenerator.jws?WSDL"); 149 MazeGeneratorSoap soapProxy = proxy.getMazeGeneratorSoap(); 150 151 int r, c; 152 int rows, cols; 153 try { 154 rows = Integer.parseInt( form.getRows() ); 155 } 156 catch (NumberFormatException ex) { 157 String msg = "Number of rows must be a valid integer (entered value: '" + 158 form.getRows() + "')"; 159 throw(new NumberFormatException(msg)); 160 } 161 try { 162 cols = Integer.parseInt( form.getCols() ); 163 } 164 catch (NumberFormatException ex) { 165 String msg = "Number of columns must be a valid integer (entered value: '" + 166 form.getCols() + "')"; 167 throw(new NumberFormatException(msg)); 168 } 169 170 /* 171 * call getRandomMaze and get back an array of ints containing the configuration 172 * encoding for each cell in the maze. 173 */ 174 int [] rooms = soapProxy.getRandomMaze(rows,cols); 175 DecimalFormat formatter = new DecimalFormat("00"); 176 177 /* 178 * Loop over the cells, specifying the appropriate image for each maze cell based in 179 * the cell encoding. The maze returned from getRandomMaze contains the bottom row 180 * first, but * we must output the top row first - so invert the rows loop. 181 */ 182 String output = "<br>"; 183 for(r = rows-1; r >=0; r--) 184 { 185 for(c = 0; c < cols; c++) 186 { 187 String image_name = new String("stone_raw_" + formatter.format(rooms[r * cols + c]) + ".gif"); 188 output += "<img src=\"/WebApp/resources/images/mazeImages/" + image_name + "\">"; 189 } 190 output += "<br>"; 191 } 192 193 // Pass the results on the "request" object. 194 getRequest().setAttribute("message", "You invoked the <b>MazeGenerator</b> web service's <b>getRandomMaze</b> method. This is the response:"); 195 getRequest().setAttribute("mazeResult", output ); 196 197 return new Forward("success"); 198 } 199 200 public static class MazeForm extends FormData 201 { 202 private String rows; 203 204 private String cols; 205 206 public void setCols(String cols) 207 { 208 this.cols = cols; 209 } 210 211 public String getCols() 212 { 213 return this.cols; 214 } 215 216 public void setRows(String rows) 217 { 218 this.rows = rows; 219 } 220 221 public String getRows() 222 { 223 return this.rows; 224 } 225 } 226 }`