struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Muralidhar Yaragalla <java.yaraga...@gmail.com>
Subject problem in validation with struts 2.3.1
Date Mon, 18 Mar 2013 19:35:23 GMT
Hi I have deployed struts blank war file and developed some action classes.
I have written some validator.xml files for action classes. but they are
not working. I am not sure why this is happening. kindly help me.

The following is my action class:-



package com.ymd.ums.lv.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.ymd.ums.lv.dto.VotingTopicDto;
import com.ymd.ums.lv.service.LiveVoteService;
import com.ymd.ums.lv.service.LiveVoteServiceImpl;


public class VotingTopicAction extends ActionSupport{


    private static final long serialVersionUID = 2362068800627791615L;
    private LiveVoteService liveVoteService=new LiveVoteServiceImpl();

    private VotingTopicDto votingTopic;

    public String execute() throws Exception{
        liveVoteService.saveVotingTopicData(votingTopic);
        votingTopic.setStatus("successful");
        HttpServletRequest request = ServletActionContext.getRequest();
        request.setAttribute("votingTopic", votingTopic);
        return SUCCESS;
    }

    /**
     * @return the votingTopic
     */
    public VotingTopicDto getVotingTopic() {
        return votingTopic;
    }

    /**
     * @param votingTopic the votingTopic to set
     */
    public void setVotingTopic(VotingTopicDto votingTopic) {
        this.votingTopic = votingTopic;
    }

}



__________________________________________________
//The following is my VotingTopicAction-validation.xml
___________________________________________________

<!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.2//EN" "
http://struts.apache.org/dtds/xwork-validator-1.0.2.dtd">
<validators>
    <field name="votingTopic.votingTopic">
        <field-validator type="requiredstring">
            <param name="trim">true</param>
            <message>You must enter a value for bar.</message>
        </field-validator>
    </field>
    <field name="votingTopic.options">
        <field-validator type="required">
            <message>You must enter a value for bar.12</message>
        </field-validator>
    </field>
</validators>

_____________________________________________________________
//The following is my struts.xml file
____________________________________________________________

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

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

    <package name="default" namespace="/" extends="struts-default">

        <default-action-ref name="index" />

        <global-results>
            <result name="error">/error.jsp</result>
        </global-results>

        <global-exception-mappings>
            <exception-mapping exception="java.lang.Exception"
result="error"/>
        </global-exception-mappings>

        <action name="createVotingTopic"
class="com.ymd.ums.lv.action.VotingTopicAction" method="execute">
               <result name="success">/jsp/lv/voteTopic.jsp</result>
               <result name="input">/jsp/lv/voteTopic.jsp</result>
          </action>
    </package>

</struts>

_______________________________________________________________________________
//Struts blank does not contain any validators.xml but i picked it up from
another war and placed in classes folder.
The folowing is the file.
_____________________________________________________________________________________-

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC
        "-//Apache Struts//XWork Validator Config 1.0//EN"
        "http://struts.apache.org/dtds/xwork-validator-config-1.0.dtd">
<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="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"/>
</validators>
______________________________________________________________________________

I dont have struts.config or any other files. This is all i have. why
server side validations are not happening? kindly help.


-- 
Thanks And Regards,
*Muralidhar Yaragalla.
*

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message