----- Original Message -----
Sent: Saturday, August 04, 2001 8:55
PM
Subject: infinite loop
hi all,
In continuation to my post
yesterday,
The following is my code. The flow is fine till
Forwarding to Success and then instead of displaying, it starts again >from
the begining.
If i remove the if condition in validate method
then it displays the form with errors which is fine.
am i doing something wrong????
thanks,
rama.
Mappings:
<!-- FIP User Profile Page bean
-->
<form-bean
name="addUser"
type="com.niku.cm.action.AddUser"/>
<!-- FIP User Profile Page
-->
<action
path="/adduser"
name="addUser"
validate="true"
input="/adduser.jsp"
type="com.niku.cm.action.AddUserAction">
<forward
name="success"
path="/adduser.cm"/>
</action>
adduser.jsp:
<html:errors />
<html:form action="/adduser?action=save"
focus="fullname">
<table width="55%" border="0"
cellspacing="1">
<tr>
<td
class="fieldname" width="16%">Full
Name*
</td>
<td class="field"
width="16%"><html:text styleClass="noborder" property="fullname"
/>
</td></tr>
<tr><td class="fieldname"
width="19%">Phone*
</td>
<td
class="field" width="16%"><html:text styleClass="noborder"
property="phone"/>
</td></tr>
<tr><td
class="fieldname"
width="19%">Email*
</td>
<td
class="field" width="16%"><html:text styleClass="noborder"
property="email"/>
</td></tr>
</table>
<p
align=center><html:submit /> <html:reset
/></p>
</html:form>
AddUser.java
(FormBean)
private String
action = "create";
private
String fullname = null;
private
String phone = null;
private
String email = "";
private String result = "false";
public String getAction()
{ return (this.action); }
public void setAction(String
action) { this.action =
action; }
public String getFullname()
{return (this.fullname); }
public void setFullname(String
_fullname) {this.fullname =
_fullname;}
public String
getPhone() {return (this.phone);}
public void setPhone(String
_phone) {this.phone = _phone;}
public
String getEmail() {return (this.email); }
public void
setEmail(String _email) {this.email = _email;}
public ActionErrors
validate(ActionMapping
mapping,
HttpServletRequest request) {
if((action.equals("create")) ||(action.equals("get"))) return
null;
ActionErrors errors =
new ActionErrors();
if
((fullname == null) || (fullname.length() <
1))
errors.add("fullname",
new
ActionError("error.fullname.required"));
if ((phone == null) || (phone.length() <
1))
errors.add("phone",
new
ActionError("error.phone.required"));
if ((email == null) || (email.length() <
1))
errors.add("email",
new
ActionError("error.email.required"));
return errors;
}
AddUserAction.java (action
class)
public final class AddUserAction extends Action
{
public ActionForward
perform(ActionMapping mapping,
ActionForm
form,
HttpServletRequest
request,
HttpServletResponse
response)
throws IOException, ServletException
{
file://get
the application resources
MessageResources messages =
getResources();
file://get the
session
HttpSession session =
request.getSession();
file://get
the action
String action =
request.getParameter("action");
System.out.println("AddUserAction
: Action is "+action);
file://if action is null set it to
default
if (action == null)
action = "create";
if (servlet.getDebug()
>= 1)
servlet.log("AddUserAction: Processing " + action +"
action");
file://if form is null then create new
instance
if (form == null)
{
if
(servlet.getDebug() >=
1)
servlet.log(" Creating new AddUserForm bean under key "+
mapping.getAttribute());
form = new
AddUser();
if
("request".equals(mapping.getScope()))
request.setAttribute(mapping.getAttribute(),
form);
else
session.setAttribute(mapping.getAttribute(),
form);
}
AddUser addform = (AddUser)
form;
if(action.equals("create"))
{
/*
do nothing
*/
}
// Forward control to the server page
if
(servlet.getDebug() >=
1)
servlet.log(" Forwarding to success");
return
(mapping.findForward("success"));
}
}