views:

520

answers:

1

Hi, This is my first post to ask a question on stack overflow and my issue is that when I don't see a client side validation error message when I don't enter any values for that field even when it is configured as required. The page is reloaded and goes to the result page and client validation fails. I am not sure what I am doing wrong. Any advice would be greatly appreciated. My scenario is given below:

I have a simple form where I have a pull down menu called selection criterion. A value must be selected. If a value is not selected, then the page should reload with configured error message. My input form action_item_search.jsp is given below:

<%@ taglib prefix="s" uri="/struts-tags" %>
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
    <html xmlns="http://www.w3.org/1999/xhtml"&gt;
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Action Item Search</title>
    </head>
    <body>
    <s:actionerror/>
    <s:fielderror />
    <s:form action="action_item_search" validate="true">
      <s:select label="Search Criterion" name="searchCriterion"
          list="#{'': 'Select One', 'creatorName':'creator name', 
           assignedTo':'assigned to'}" required="true" />             
      <s:submit name="search" value="Search"></s:submit>
    </s:form>
    </body>

I have add validators.xml in my WEB-INF/classes directory of exploded war file as given below:

<!DOCTYPE validators PUBLIC
    "-//OpenSymphony Group//XWork Validator Config 1.0//EN"
    "http://www.opensymphony.com/xwork/xwork-validator-config-1.0.dtd"&gt;
 <validators>
<validator name="required"   
        class="com.opensymphony.xwork2.validator.validators.RequiredFieldValidator"/>
<validator name="requiredstring" 
        class="com.opensymphony.xwork2.validator.validators.RequiredStringValidator"/>
<validator name="int" 
        class="com.opensymphony.xwork2.validator.validators.IntRangeFieldValidator"/>
<validator name="long" 
        class="com.opensymphony.xwork2.validator.validators.LongRangeFieldValidator"/>
<validator name="short" 
        class="com.opensymphony.xwork2.validator.validators.ShortRangeFieldValidator"/>
<validator name="double" 
       class="com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator"/>
<validator name="date"  
       class="com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator"/>
<validator name="expression" 
       class="com.opensymphony.xwork2.validator.validators.ExpressionValidator"/>
<validator name="fieldexpression" 
       class="com.opensymphony.xwork2.validator.validators.FieldExpressionValidator"/>
<validator name="email" 
       class="com.opensymphony.xwork2.validator.validators.EmailValidator"/>
<validator name="url"            
       class="com.opensymphony.xwork2.validator.validators.URLValidator"/>
<validator name="visitor"           
       class="com.opensymphony.xwork2.validator.validators.VisitorFieldValidator"/>
<validator name="conversion" 
   class="com.opensymphony.xwork2.validator.validators.ConversionErrorFieldValidator"/>
<validator name="stringlength" 
      class="com.opensymphony.xwork2.validator.validators.StringLengthFieldValidator"/>
<validator name="regex"  
      class="com.opensymphony.xwork2.validator.validators.RegexFieldValidator"/>
<validator name="conditionalvisitor" 
class="com.opensymphony.xwork2.validator.validators.ConditionalVisitorFieldValidator"/>
</validators>

ActionItemTrackingAction-findByCriteria-validation.xml in WEB-INF/classes directory is given below:

<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
   "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"&gt;

<validators>
<field name="searchCriterion" >
  <field-validator type="required">
     <message>You must enter a search criterion.</message>
  </field-validator>
 </field>
</validators>

My struts mapping xml:

<struts>

<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />

<!-- <include file="example.xml"/> -->
 <package name="action-item" extends="struts-default">
      <action name = "action_item_search_input">
      <result name = "success">/action-item-search.jsp</result>
    </action>
    <action name="action_item_search" class="gov.nasa.spacebook.ActionItemTrackingAction" method="fetchByCriteria">
       <result name = "success">/action-item-result.jsp</result>
       <result name = "input">/action-item-search.jsp</result>
       <result name = "error">/action-item-search.jsp</result>
    </action>
 </package>
 </struts>

My action class

public class ActionItemTrackingAction extends ActionSupport {
   private List<ActionItem> actionItems;
   public List<ActionItemTracking> getActionItems() {
  return actionItems;
   }
   public void setActionItems(List<ActionItemTracking> actionItems) {
  this.actionItems = actionItems;
   }

   private String searchCriterion;
   public String getSearchCriterion() {
    return searchCriterion;
}
public void setSearchCriterion(final String criterion) {
    this.searchCriterion = criterion;
}

    public String fetchByCriteria() throws Exception {
        final ActionItemTrackingService service = 
        new ActionItemTrackingService();
    this.actionItems = service.getByField(this.actionItem);
    return super.execute();
}
}
A: 

Hi, I have the same issue when I do not have internet connection on my development machine.

Once internet connection to my development machine is established, I recompile and run the application and the validation works. Seems like the validators.xml requires internet.

Iceman
I can still reproduce this issue without or without internet connectivity.
Kartik