# Controller.jpf Sample

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

## Sample Location

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

BEA_HOME/weblogic81/samples/workshop/SamplesApp/WebApp/struts/validation/basic/

## Sample Source Code

`001 package struts.validation.basic; 002 003 import com.bea.wlw.netui.pageflow.*; 004 import org.apache.struts.action.*; 005 import javax.servlet.http.*; 006 007 008 /** 009 * @jpf:controller nested="true" 010 * @jpf:message-resources resources="validation.basic.Messages" 011 * @jpf:view-properties view-properties:: 012 * <!-- This data is auto-generated. Hand-editing this section is not recommended. --> 013 * <view-properties> 014 * <pageflow-object id="pageflow:/validation/basic/Controller.jpf"/> 015 * <pageflow-object id="action:begin.do"> 016 * <property value="80" name="x"/> 017 * <property value="80" name="y"/> 018 * </pageflow-object> 019 * <pageflow-object id="action:submitForm.do#validation.basic.Controller.Form"> 020 * <property value="220" name="x"/> 021 * <property value="220" name="y"/> 022 * </pageflow-object> 023 * <pageflow-object id="action:exit.do"> 024 * <property value="340" name="x"/> 025 * <property value="80" name="y"/> 026 * </pageflow-object> 027 * <pageflow-object id="action-call:@page:formPage.jsp@#@action:submitForm.do#validation.basic.Controller.Form@"> 028 * <property value="220,220,220,220" name="elbowsX"/> 029 * <property value="124,150,150,176" name="elbowsY"/> 030 * <property value="South_1" name="fromPort"/> 031 * <property value="North_1" name="toPort"/> 032 * </pageflow-object> 033 * <pageflow-object id="action-call:@page:formPage.jsp@#@action:exit.do@"> 034 * <property value="256,280,280,304" name="elbowsX"/> 035 * <property value="72,72,72,72" name="elbowsY"/> 036 * <property value="East_1" name="fromPort"/> 037 * <property value="West_1" name="toPort"/> 038 * </pageflow-object> 039 * <pageflow-object id="page:formPage.jsp"> 040 * <property value="220" name="x"/> 041 * <property value="80" name="y"/> 042 * </pageflow-object> 043 * <pageflow-object id="action-call:@page:success.jsp@#@action:begin.do@"> 044 * <property value="80,80,80,80" name="elbowsX"/> 045 * <property value="176,150,150,124" name="elbowsY"/> 046 * <property value="North_1" name="fromPort"/> 047 * <property value="South_1" name="toPort"/> 048 * </pageflow-object> 049 * <pageflow-object id="page:success.jsp"> 050 * <property value="80" name="x"/> 051 * <property value="220" name="y"/> 052 * </pageflow-object> 053 * <pageflow-object id="forward:path#formPage#formPage.jsp#@action:begin.do@"> 054 * <property value="116,150,150,184" name="elbowsX"/> 055 * <property value="72,72,72,72" name="elbowsY"/> 056 * <property value="East_1" name="fromPort"/> 057 * <property value="West_1" name="toPort"/> 058 * <property value="formPage" name="label"/> 059 * </pageflow-object> 060 * <pageflow-object id="forward:path#success#success.jsp#@action:submitForm.do#validation.basic.Controller.Form@"> 061 * <property value="184,150,150,116" name="elbowsX"/> 062 * <property value="212,212,212,212" name="elbowsY"/> 063 * <property value="West_1" name="fromPort"/> 064 * <property value="East_1" name="toPort"/> 065 * <property value="success" name="label"/> 066 * </pageflow-object> 067 * <pageflow-object id="return-to:@forward:return-to#failure#currentPage#@action:submitForm.do#validation.basic.Controller.Form@@"> 068 * <property value="340" name="x"/> 069 * <property value="220" name="y"/> 070 * </pageflow-object> 071 * <pageflow-object id="forward:return-to#failure#currentPage#@action:submitForm.do#validation.basic.Controller.Form@"> 072 * <property value="256,280,280,304" name="elbowsX"/> 073 * <property value="212,212,212,212" name="elbowsY"/> 074 * <property value="East_1" name="fromPort"/> 075 * <property value="West_1" name="toPort"/> 076 * <property value="failure" name="label"/> 077 * </pageflow-object> 078 * <pageflow-object id="exit:begin"> 079 * <property value="480" name="x"/> 080 * <property value="140" name="y"/> 081 * </pageflow-object> 082 * <pageflow-object id="forward:return-action#previousPageFlowBegin#begin#@action:exit.do@"> 083 * <property value="376,410,410,444" name="elbowsX"/> 084 * <property value="72,72,132,132" name="elbowsY"/> 085 * <property value="East_1" name="fromPort"/> 086 * <property value="West_1" name="toPort"/> 087 * <property value="previousPageFlowBegin" name="label"/> 088 * </pageflow-object> 089 * <pageflow-object id="formbeanprop:validation.basic.Controller.Form#email#java.lang.String"/> 090 * <pageflow-object id="formbeanprop:validation.basic.Controller.Form#zipCode#java.lang.String"/> 091 * <pageflow-object id="formbean:validation.basic.Controller.Form"/> 092 * </view-properties> 093 * :: 094 * 095 */ 096 public class Controller extends PageFlowController 097 { 098 /** 099 * @jpf:action 100 * @jpf:forward name="formPage" path="formPage.jsp" 101 */ 102 public Forward begin() 103 { 104 return new Forward( "formPage" ); 105 } 106 107 /** 108 * @jpf:action 109 * @jpf:forward name="success" path="success.jsp" 110 * @jpf:validation-error-forward name="failure" return-to="currentPage" 111 */ 112 public Forward submitForm( Form form ) 113 { 114 return new Forward( "success" ); 115 } 116 117 118 /** 119 * @jpf:action 120 * @jpf:forward name="previousPageFlowBegin" return-action="begin" 121 */ 122 public Forward exit() 123 { 124 return new Forward( "previousPageFlowBegin" ); 125 } 126 127 /** 128 * This form bean does validation manually. 129 */ 130 public static class Form extends FormData 131 { 132 private String _email; 133 private String _zipCode; 134 135 public String getEmail() 136 { 137 return _email; 138 } 139 140 public void setEmail( String email ) 141 { 142 _email = email; 143 } 144 145 public String getZipCode() 146 { 147 return _zipCode; 148 } 149 150 public void setZipCode( String zipCode ) 151 { 152 _zipCode = zipCode; 153 } 154 155 public ActionErrors validate( ActionMapping mapping, HttpServletRequest request ) 156 { 157 ActionErrors errs = new ActionErrors(); 158 159 int at = _email.indexOf( '@' ); 160 int dot = _email.lastIndexOf( '.' ); 161 162 if ( at == -1 || at == 0 || dot == -1 || at > dot ) 163 { 164 errs.add( "email", new ActionError( "badEmail" ) ); 165 } 166 167 if ( _zipCode.length() != 5 ) 168 { 169 errs.add( "zipCode", new ActionError( "badZip", new Integer( 5 ) ) ); 170 } 171 172 return errs; 173 } 174 } 175 }`