Hi,

This is wha I done in my code .
I have messageproperty also.
Code is as follow


my code is as follows 

struts-config.xml

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts
Configuration 1.1//EN" 
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd";> 
<struts-config> 
        <!-- =========================== DynaActionForms
========================== --> 
        <form-beans> 
                <form-bean name="kForm"
type="org.apache.struts.validator.DynaValidatorForm" > 
                        <form-property name="ID" type="java.lang.Integer"/> 
                        <form-property name="kDescription"
type="java.lang.String"/> 
                        <form-property name="title"
type="java.lang.String"/> 
                                </form-bean> 
        </form-beans> 
        
        
        <action-mappings type="org.apache.struts.action.ActionMapping"> 

                        <action name="kForm" 
                        path="/kAdd" 
                        type="com.riskMngmnt.presentation.k.KDispatchAction" 
                        scope="request" 
                        validate="true" 
                        input="k.add"> 
                       <forward name="add" path="k.add"/> 
                       <forward name="view" path="k.view"/> 
                       </action> 
                        
                              
  
    <message-resources  parameter="/WEB-INF/MessageResourcesK.properties"
null="false"/> 
        
<!--  Validator plugin --> 
<plug-in className="org.apache.struts.validator.ValidatorPlugIn"> 
<set-property property="pathnames" 
           
value="/WEB-INF/validator-k-rules.xml,/WEB-INF/validation-k.xml"/> 
            
</plug-in> 

</struts-config> 


My messageresource.properties


# Error messages for Validator framework validations 
#-- validation errors 
errors.invalid={0} is invalid. 
errors.maxlength={0} can not be greater than {1} characters. 
errors.minlength={0} can not be less than {1} characters. 
errors.range={0} is not in the range {1} through {2}. 
errors.required={0} is required. 
errors.byte={0} must be an byte. 
errors.date={0} is not a date. 
errors.double={0} must be an double. 
errors.float={0} must be an float. 
errors.integer={0} must be an integer. 
errors.long={0} must be an long. 
errors.short={0} must be an short. 
errors.creditcard={0} is not a valid credit card number. 
errors.email={0} is an invalid e-mail address. 

#--diplay names 
prompt.title = Title 
prompt.kDescription = KDescription 


validation-k.xml

<?xml version="1.0" encoding="UTF-8"?> 

<!DOCTYPE form-validation 
PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules
Configuration 1.1.3//EN" 
          "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd";> 


<form-validation> 
        <formset> 
                <form name="kForm"> 
                                
                            <field  property="title" 
                                    depends="required"> 
                            <arg0   key="prompt.title" /> 
                            </field> 
                
                            <field  property="kDescription" 
depends="required"> 
                            <arg0  key="prompt.kDescription" ></arg0> 
                      </field> 
                      
                </form> 
        </formset> 
</form-validation> 


my KForm.java


import javax.servlet.http.HttpServletRequest; 

import org.apache.struts.action.ActionErrors; 

import org.apache.struts.action.ActionMapping; 
import org.apache.struts.action.ActionMessage; 
import org.apache.struts.validator.ValidatorForm; 


public class KForm extends ValidatorForm { 

  private String title; 
  private String kDescription; 
  
  public void setTitle(String title) 
  { 
    this.title=title; 
  } 

  public String getTitle() 
  { 
    return title; 
  } 
.... 
. 
. 
.. 
  
  public void reset(ActionMapping mapping, HttpServletRequest request) { 
          
             this.title=null; 
                this.kDescription=null; 
            } 

            /** 
             * Reset all properties to their default values. 
             * 
             * @param mapping The mapping used to select this instance 
             * @param request The servlet request we are processing 
           * @return errors 
             */ 
          public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request ) 
          { 
                  
                  
                  
                  System.out.println("validate in  in kForm.java"); 
              ActionErrors errors = new ActionErrors(); 
              
              System.out.println("k form validate method"); 

              if( getTitle() == null || getTitle().length() < 1 ) 
              { 
                   errors.add("title",new ActionMessage("errors.required")); 
              } 

             if( getKDescription() == null || getKDescription().length() < 1
) 
             { 
                errors.add("kDescription",new
ActionMessage("errors.required")); 
             } 
              return errors; 
          } 

        } 


in main jsp 

<html:html locale="true"> 
  <body> 
    <form  action="<%=path %>/k.do?method=save" method="post" name="kForm" > 
---- 
<p> 
<html:errors/> 
</p> 
 <input type="button" value="Submit As Draft" onclick="return
validateKForm(this);"/><br></td> 
                  <td valign="top"> 


Regards
Swapna
:confused::confused:






Antonio Petrelli-3 wrote:
> 
> 2008/5/19 Sapan <[EMAIL PROTECTED]>:
>>  ???en_US.errors.required??????en_US.errors.required???
> 
> Sorry, I think I got it.
> It seems that you have not defined the "errors.required" property in
> your "messageresources.properties", so the <html:errors> tag gets
> confused and prints that stuff.
> 
> Antonio
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Jsp-struts-tp17326992p17349007.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to