Problem is when I try to validate fields through struts validation. It dosent work .... I can see error message on tomcat.
I post my code here,
Register.jsp
<s:form action="insertdata">
<s:textfield name="username" key="label.uname" required="true"/>
<s:password name="password" key="label.pass" required="true"/>
<s:password name="cpassword" key="label.cpass" required="true"/>
<s:textfield name="emailid" key="label.mail" required="true"/>
<s:textfield name="mobileno" key="label.mobileno" required="true"/>
<s:datetimepicker name="dob" key="label.dob" displayFormat="MM/dd/yy" required="true"/>
<s:submit value="Register"/>
</s:form>
struts.xml
<action name="insertdata" class="com.curd.action.InsertAction">
<result name="success">RegisterSuccessful.jsp</result>
<result name="error">NotRegister.jsp</result>
</action>
InsertAction.java(Action Class)
public class InsertAction {
private String username,password,cpassword,emailid;
private int mobileno;
private Date dob;
DAO dao=new DAO();
public String execute(){
return "success";
else
return "error";
}
InsertAction-validation.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators
PUBLIC '-//OpenSymphony Group//XWork Validator 1.0.2//EN'
'http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd'>
<validators>
<field name="username">
<field-validator type="requiredstring">
<message>username is required</message>
</field-validator>
</field>
<field name="password">
<field-validator type="requiredstring">
<message>Password is required</message>
</field-validator>
</field>
<field name="cpassword">
<field-validator type="requiredstring">
<message>confirm password is required</message>
</field-validator>
</field>
<field name="emailid">
<field-validator type="requiredstring">
<message>Email ID is required</message>
</field-validator>
<field-validator type="mail">
<message>Enter Valid Email id eg.john#gmail.com</message>
</field-validator>
</field>
<field name="mobileno">
<field-validator type="stringLength">
<param minLength="10"/>
<message>Mobile No Must be ${minLength} Digit..</message>
</field-validator>
</field>
<field name="dob">
<field-validator type="date">
<param name="min">2000/01/1</param>
<param name="max">2013/09/1</param>
<message>Year should be With in ${min} and ${max}</message>
</field-validator>
</field>
</validators>
Exception
SEVERE: Validation error for username:username is required Aug 17, 2013 10:43:38 PM com.opensymphony.xwork2.validator.DelegatingValidatorContext$LoggingValidationAware addFieldError
SEVERE: Validation error for password:Password is required Aug 17, 2013 10:43:38 PM com.opensymphony.xwork2.validator.DelegatingValidatorContext$LoggingValidationAware addFieldError
SEVERE: Validation error for cpassword:confirm password is required Aug 17, 2013 10:48:29 PM com.opensymphony.xwork2.util.DomHelper$StartHandler error SEVERE: Attribute "name" is required and must be specified for element type "param".at (null:30:25)org.xml.sax.SAXParseException;systemId:file:///E:/Language%20SW/KRISHSOFT/eclipse/com/curd/action/InsertAction-validation.xml; lineNumber: 30; columnNumber: 25;Attribute "name" is required and must be specified for element type "param".
Not indenting code and XML is a horrible idea; it's impossible to think about.
The error message:
SEVERE: Attribute "name" is required and must be specified for element type "param".
So. Do you have any <param> elements around line 30?
<param minLength="10"></param>
Oh look, there's no name attribute for that <param> element.
Also, your execute() method is suspicious, and it's not clear if you have public setters for your action properties.
Related
How to set default value in Job_id in this form with xml and don't need to set in the python file?
<record id="form_student_stu" model="ir.ui.view">
<field name="name">Student Info</field>
<field name="model">youth_and_scholarship.youth_and_scholarship</field>
<field name="arch" type="xml">
<form string="Job Form" version="9.0">
<div class="widget_box">
<div class="widget_title"><h5>Student Information</h5></div>
<div>
<group col="1">
<field name="image" widget="image" class="oe_avatar oe_left" nolabel="1"/>
<field name="Job_id" invisible="1"/>
</group>
<group>
<field name="Kname" placeholder="First Name and Last Name..." string="Name in Khmer" style="width:40%%"/>
<field name="Ename" placeholder="First Name and last Name..." string="Name in Latin" style="width:40%%"/>
<field name="Gender" string="Gender" style="width:40%%"/>
<field name="DOB" string="Date of birth"/>
<field name="Job_work" string="Accupation" style="width:40%%"/>
</group>
</div>
</div>
</form>
</field>
</record>
You can use some context specifying an XML ID (External ID). You can add the default value to the action which calls the view like this:
<record id="youth_and_scholarship_youth_and_scholarship_action" model="ir.actions.act_window">
<field name="name">Student Info</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">youth_and_scholarship.youth_and_scholarship</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{'default_job_id': ref('xml_id')}</field>
</record>
If you open the view from a field, from a many2one for example, you can add the context to that field:
<field name="field_name" context="{'default_job_id': ref('xml_id')}" />
If haven't set the XML ID of the record you can get the ID by Python code and return an action window with the context:
job_id = self.get_job_id()
return {
'name': 'Student Info',
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'youth_and_scholarship.youth_and_scholarship',
'context': {'default_job_id': job_id }
}
NOTES:
The key always has to be: default_ + field_name: database_id
You can see all the XML IDs here: Settings > Technical > Sequences & Identifiers > External Identifiers > Complete ID
i am trying to add a custom message and compile quickfixj and am running into an issue where last few fields that i've added are not being picked up (they all have field number > 93000 if it matters)
code generation is ok but compilation fails, i am sure i am missing something obvious, searched for similar issues reported by others but didn't find any, can someone please help
#
public static class NoAccounts extends Group {
static final long serialVersionUID = 20050617;
private static final int[] ORDER = {1, 51006, 90002, 90003, 51005, 90001, 93000, , , , , , , 0};
#
Here is what i've added
<message name="GetAccountsRsp" msgtype="UsE" msgcat="app">
<field name="RequestId" required="Y"/>
<field name="ResponseStatus" required="N"/>
<field name="ErrorMessage" required="N"/>
<component name="AccountGrp" required="N"/>
<field name="Bookmark" required="N"/>
<field name="LastFragment" required="Y"/>
</message>
<component name="AccountGrp">
<group name="NoAccounts" required="N">
<field name="Account" required="N"/>
<field name="RiskNodeID" required="N"/>
<field name="Name" required="N"/>
<field name="AutomaticMoveAccountId" required="N"/>
<field name="Owner" required="N"/>
<field name="JSCCAccountType" required="N"/>
<component name="AccountExtension" required="N"/>
</group>
</component>
<component name="AccountExtension">
<field name="JpxAccountType" required="N"/>
<field name="IsOmnibus" required="N"/>
<field name="IsGross" required="N"/>
<field name="ClientId" required="N"/>
<field name="TradingMemberId" required="N"/>
<field name="ClearingMemberId" required="N"/>
<field name="IsConcentration" required="N"/>
</component>
<field number="50007" name="Bookmark" type="STRING"/>
<field number="50025" name="RequestId" type="STRING"/>
<field number="51005" name="Owner" type="STRING"/>
<field number="51006" name="RiskNodeID" type="STRING"/>
<field number="51009" description="ClearingMemberId" type="STRING" />
<field number="51011" description="TradingMemberId" type="STRING" />
<field number="51015" name="ResponseStatus" type="STRING">
<value enum="0" description="ACCEPTED" />
<value enum="1" description="REJECTED" />
</field>
<field number="51016" name="ErrorMessage" type="STRING"/>
<field number="51019" name="NoAccounts" type="NUMINGROUP"/>
<field number="90001" name="JSCCAccountType" type="STRING">
<value enum="1" description="DEFAULT_CLEARING_HOUSE" />
<value enum="2" description="CLEARING_HOUSE" />
<value enum="3" description="NORMAL" />
<value enum="4" description="CONCENTRATION" />
</field>
<field number="90002" name="Name" type="STRING"/>
<field number="90003" name="AutomaticMoveAccountId" type="STRING"/>
<field number="93000" name="JpxAccountType" type="STRING">
<value enum="1" description="HOUSE_ACCOUNT_TYPE" />
<value enum="2" description="AFFILIATE_ACCOUNT_TYPE" />
<value enum="3" description="CLIENT_ACCOUNT_TYPE" />
</field>
<field number="93001" description="IsOmnibus" type="BOOLEAN">
<value enum="N" description="FALSE"/>
<value enum="Y" description="TRUE"/>
</field>
<field number="93002" description="IsGross" type="BOOLEAN">
<value enum="N" description="FALSE"/>
<value enum="Y" description="TRUE"/>
</field>
<field number="93003" description="ClientId" type="STRING" />
<field number="93015" description="IsConcentration" type="BOOLEAN">
<value enum="N" description="FALSE"/>
<value enum="Y" description="TRUE"/>
</field>
<field number="96005" name="ContractPeriod" type="INT"/>
please ignore, stupid error, I've added 'description' attribute instead of 'name' attribute to the new fields I've added, when I include in group/component source is generated without these causing an issue during compilation. lesson learned - double check dictionary to avoid issues during recompilation
I got possible fields from my server:
<iq xmlns="jabber:client" from="vjud.company.com" to="testuser#company.com/iPhone" id="search1" type="result"><query xmlns="jabber:iq:search">
<instructions>You need an x:data capable client to search</instructions>
<x xmlns="jabber:x:data" type="form">
<title>Search users in vjud.company.com</title>
<instructions>Fill in the form to search for any matching Jabber User (Add * to the end of field to match substring)
</instructions>
<field type="text-single" label="User" var="user"/>
<field type="text-single" label="Full Name" var="fn"/>
<field type="text-single" label="Name" var="first"/>
<field type="text-single" label="Middle Name" var="middle"/>
<field type="text-single" label="Family Name" var="last"/>
<field type="text-single" label="Nickname" var="nick"/>
<field type="text-single" label="Birthday" var="bday"/>
<field type="text-single" label="Country" var="ctry"/>
<field type="text-single" label="City" var="locality"/>
<field type="text-single" label="Email" var="email"/>
<field type="text-single" label="Organization Name" var="orgname"/>
<field type="text-single" label="Organization Unit" var="orgunit"/>
</x>
</query>
</iq>
Suppose I want to search a user with JID admin#company.com
Composed request wil look like this:
XMPPIQ *iq2 = [[XMPPIQ alloc] init];
[iq2 addAttributeWithName:#"type" stringValue:#"set"];
[iq2 addAttributeWithName:#"from" stringValue:#"testuser#company.com"];
[iq2 addAttributeWithName:#"to" stringValue:#"vjud.company.com"];
[iq2 addAttributeWithName:#"id" stringValue:#"search1"];
XMPPElement *query2 = [XMPPElement elementWithName:#"query"];
[query2 setXmlns:#"jabber:iq:search"];
XMPPElement *user = [XMPPElement elementWithName:#"user"];
[user setStringValue:#"admin"];
[iq2 addChild:query2];
[query addChild:user];
The error stanza:
<iq xmlns="jabber:client" from="vjud.company.com" to="testuser#company.com/iPhone" type="error" id="search1">
<query xmlns="jabber:iq:search"/>
<error code="400" type="modify">
<bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
</error>
</iq>
So, basically there are 2 questions:
Why there is no </query> element in response?
Is it the actual reason of the error?
-The server's response should look like this-
Big thanks to #legoscia user, in case request was composed right, you will get something like this(notice <item> element):
<iq xmlns="jabber:client" from="vjud.company.com" to="testuser#company.com/iPhone" id="search1" type="result»>
<query xmlns="jabber:iq:search"><x xmlns="jabber:x:data" type="result»>
<title>Search Results for vjud.company.com</title>
<reported>
<field type="text-single" label="Jabber ID" var="jid»/>
<field type="text-single" label="Full Name" var="fn»/>
<field type="text-single" label="Name" var="first»/>
<field type="text-single" label="Middle Name" var="middle»/>
<field type="text-single" label="Family Name" var="last"/><field type="text-single" label="Nickname" var="nick»/>
<field type="text-single" label="Birthday" var="bday»/>
<field type="text-single" label="Country" var="ctry»/>
<field type="text-single" label="City" var="locality»/>
<field type="text-single" label="Email" var="email»/>
<field type="text-single" label="Organization Name" var="orgname"/><field type="text-single" label="Organization Unit" var="orgunit»/>
</reported>
<item>
<field var="jid»>
<value>admin#company.com</value>
</field>
<field var="fn"><value/></field>
<field var="last"><value/></field>
<field var="first"><value/></field>
<field var="middle"><value/></field>
<field var="nick"><value/></field>
<field var="bday"><value/></field>
<field var="ctry"><value/></field>
<field var="locality"><value/></field>
<field var="email"><value/></field>
<field var="orgname"><value/></field>
<field var="orgunit"><value/></field></item>
</x>
</query>
</iq>
If there is no matches,you will just receive <reported> element with lots of fields. You may want to have look at this as well.
This search service doesn't support "plain" XEP-0055 search fields, but requires you to submit the x:data form returned in the response to the "get" request; see XEP-0004.
You can tell this by the fact that the result doesn't contain any suggested search fields as children of the query element (see example 2 of XEP-0055), and also the <instructions/> element says so. This means that you need to look at the <x xmlns="jabber:x:data" type="form"> element and submit it.
Thus, you need to send something like:
<iq type='set'
from='juliet#capulet.com/balcony'
to='characters.shakespeare.lit'
id='search4'
xml:lang='en'>
<query xmlns='jabber:iq:search'>
<x xmlns='jabber:x:data' type='submit'>
<field var='user'>
<value>admin</value>
</field>
</x>
</query>
</iq>
(This is example 8 from XEP-0055, modified to search for the user with username "admin".)
I'm trying to validate a form using the Struts2 validator tool but it doesn't seem to work since, apparently, the xml validator is never acknowledged.
Here is my code:
struts.xml:
<interceptors>
<interceptor name="login_interceptor" class="org.apache.struts.gesprod.produccion.BLLogin">
</interceptor>
<interceptor-stack name="login_stack">
<interceptor-ref name="login_interceptor" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="login_stack"></default-interceptor-ref>
<global-results>
<result name="input">/errores/error_input.jsp</result>
<result name="error_sql">/errores/error_sql.jsp</result>
<result name="no_logged">/login.jsp</result>
</global-results>
...
<action name="login" class="org.apache.struts.gesprod.produccion.BLUsuario" method="loginUsuario">
<result name="success" type="redirect">/welcome.jsp</result>
<result name="incorrecto_login">/login.jsp</result>
<result name="input">/login.jsp</result>
</action>
login.jsp:
<div id="login">
<s:fielderror />
<s:form id="login_form" action="login" validate="true">
<s:hidden name="intento_log" value="true" />
<s:textfield name="usuario.username_usuario" label="Usuario"/>
<s:password name="usuario.password_usuario" label="Password"/>
<s:submit value="Ingresar"/>
</s:form>
</div>
And the xml validator, placed in the same package as the Action class.
BLUsuario-login-validation.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="usuario.username_usuario">
<field-validator type="requiredstring">
<message>Show error!</message>
</field-validator>
</field>
</validators>
Can somebody help and notice if there's something wrong with my code?
I think that the problem is in the name of the xml validator. You have to rename the validator with login-validation.xml. The name that you can put to your xml validator files are:
Validation rules can be specified:
Per Action class: in a file named ActionName-validation.xml
Per Action alias: in a file named ActionName-alias-validation.xml
Inheritance hierarchy and interfaces implemented by Action class: XWork searches up the inheritance tree of the action to find default validations for parent classes of the Action and interfaces implemented
You can see more here:
http://struts.apache.org/2.0.12/docs/validation.html#Validation-DefiningValidationRules
P.D: You said that "the "input" result is never returned even if the fields are wrong". The input result is returned if there are any field error (unless you specify other thing).
How to achieve parameterized message in struts2.
in actioname-validation.xml i have
<field name="family.familyName">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message key="common.required">
<argo key="common.family" />
</message>
</field-validator>
</field>
resource file i have,
common.required = {0} is required.
common.family = Family
some thing like this i tried. how to achive this?
This article explains how to do what you want. The gist of it is that you'd define your validation rule as follows:
<field name="family.familyName">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message key="common.required"/>
</field-validator>
</field>
And then in your .properties file, you'd have the following:
common.required = ${getText(fieldName)} is required.
family.familyName = Family
It gives me, what i expected
<field name="family.familyName">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>
${getText("requiredstring", {getText("common.family")})}
</message>
</field-validator>
</field>
Application Resources,
requiredstring = {0} is required.
common.family = Family
It might be also resolved as follows
<field name="family.familyName">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message key="common.required">
<param name="1">getText('common.family')</param>
</message>
</field-validator>
</field>