Hello,
I don't know what exactly you are doing, whre you are calling the validation
condition.
But still i have a copule of alternative for you, just try. Hope your
problem will be solved. Because i had same problem and i solved that by
applying this teh.
Solution:
Step1. Your action mapping and form bean looking ok.
<action path="/Search" name="searchForm" type="
com.actions.SearchAction" input="home.jsp" validate="true">
<forward name="success" path="
displaysearchresults.jsp"/>
<forward name="error" path="home.jsp"/>
</action>
> > Struts config DynaActionForm:
> > <form-bean name="searchForm" type="
> org.apache.struts.action.DynaActionForm">
> > <form-property name="searchString" type="java.lang.String
> "></form-property>
Step2: is this the page called(home.jsp)if then
Just use it i have modified your code inside the jsp page.
> > jsp:
> > <html:form action="/Search">
> >
> > <input type="text" name="searchString" size="30" >
<html:errors/>
> > <input type="submit" name="Submit" value="Go">
> > </html:form>
Step 3:
Create an instance of your DynaActionForm in the SearchAction Class
like example:
DynaActionForm dform=(DynaActionForm)form;
Step4:
your condition checking appearing wrong, because you cann't directly access
the text field defined in the form. So i am suggesting two ways to do this:
String search=dform.getString("searchString");
or
Note: to use bellow method write this statement at the top of your action
class(SearchAction) that is:
import org.apache.commons.beanutils.BeanUtils; then follow step bellow
String search=(String)PropertyUtils.getSimpleProperty(form,"searchString");
Step5:
if(search.equals("kill")){
ActionMessages errors=new ActionMessages();
errors.add("searchString", new ActionMessage( "errors.required",
"searchString"));
}
if(!errors.isEmpty()){
saveErrors(request,errors);
}
return mapping.findForward("error");
/*
1. if(dform.get())
> >
> > if(searchString.equals("kill")){
> > ActionErrors errors = new ActionErrors();
> > errors.add("errors", new ActionError("errors", "errors"));
> > saveErrors(request, errors);
> >
> > return mapping.findForward("error");
*/
I think now you will able to see your error message in your home page when
the searchString field match with the string "kill".
Note: Make sure your program can able to access your
MessageResources.properties file. So the message string for "errors.required"
will be retrieved frorm MessagesResources and it will display on the home.jsp
page.
If still you have problem, then let me know by some more details like action
class, enviromnet you are using so i will try to help you out.
Thanks,
Debendra.
---------------------------------
Yahoo! Autos. Looking for a sweet ride? Get pricing, reviews, & more on new
and used cars.