I have been referring to the quickfixj documentation which states, one can retrieve the repeating groups as given here: https://www.quickfixj.org/usermanual/2.3.0/usage/repeating_groups.html. But
the given approach is not working in the acceptor, though it is able to extract the repeating groups, when parsed in the sender itself. On trying to fetch the repeating groups, it gives the fails with the Exception : "Method threw, Quickfix.FieldNotFoundException". Kindly suggest on the same.
// FIX50SP2.modified.xml for adding custom message
<!--In the message declaration section--->
<value enum="CZ" description="MYSAMPLEMESSAGE"/>
enter code here
<!--In the message definition section--->
<message name="MySampleMessage" msgtype="CZ" msgcat="app">
<field name="EntitlementRepId" required="Y"/>
<component name="EntitlementUpdateGrp" required="Y"/>
<field name="Text" required="N"/>
</message>
<!--In the component definition section--->
<component name="EntitlementUpdateGrp">
<group name="NoPartyEntitlements" required="Y">
<field name="ListUpdateAction" required="Y"/>
</group>
</component>
<!--In the field declaration section--->
<field number="1771" name="EntitlementRepId" type="STRING"/>
<field number="1772" name="NoPartyEntitlements" type="NUMINGROUP"/>
public class Acceptor extends MessageCracker implements Application{
public void onMessage(MySampleMessage message,SessionID sessionId)throws Exception
{
MySampleMessage.NoPartEntitlements noPartyEntitlements=new MySampleMessage.NoPartEntitlements();
ListUpdateAction listUpdateAction=new ListUpdateAction();
message.getGroup(1,noPartyEntitlements);//FieldNotFound Exception is thrown
}
#override
public void fromApp(Message message,SessionID sessionId)throws Exception
{
crack(message,sessionId);
}
}
Related
I want to use a custom datetime attribute to track, when an item entered a given state for the first time (serverdefault:clock).
To avoid later manipulation, this custom field at the same time should be set to readonly for everyone.
It seems however that in all combinations I come up with the "readonly" takes precedence and immediat es ly blocks the "serverdefault" that seems to be executed with the rights of the user iniziating tha transition.
For e.g. "created date" however the behavior seems possible for the system itself ...
Is there a way to achieve the same behavior for custom fields?
You can define your field like this:
<FIELD name="Custom Date" refname="My.CustomDate" type="DateTime">
<WHENNOTCHANGED field="System.State">
<READONLY />
</WHENNOTCHANGED>
</FIELD>
and then add this XML to the TRANSITION node for the given state:
<TRANSITION from="Resolved" to="Closed">
<FIELDS>
<FIELD refname="My.CustomDate">
<SERVERDEFAULT from="clock" />
</FIELD>
</FIELDS>
</TRANSITION>
Is possible to make this conditional expression validation?:
(invitation.id==null and (newText==null or newText.isEmpty()))
I've tried several ways, several times, but don't achieve it.
This version is working, but on server-side, and ignore if invitation.id is null or empty... any ideas???:
<field name="newText">
<field-validator type="fieldexpression">
<param name="expression">!(invitation.id eq null and (newText eq null or newText.empty))</param>
<message>${getText("validation.required")}</message>
</field-validator>
</field>
http://struts.apache.org/release/2.2.x/docs/fieldexpression-validator.html
what is wrong with the expression?? Thanks!
Your problem is that you are trying to validate another field (invitation.id) into the newText Field Validator (i don't think it's possible, but I'm not sure).
However, you could split it into two validators, raising the message corrispondent to the failure case, that is more correct imho;
<field name="invitation.id">
<field-validator type="required">
<message>${getText("validation.invitation.id.required")}</message>
</field-validator>
</field>
<field name="newText">
<field-validator type="fieldexpression">
<param name="expression">
<![CDATA[
newText != null && !newText.trim().empty())
]]>
</param>
<message>${getText("validation.newText.required")}</message>
</field-validator>
</field>
, if you need to trim it, otherwise it could become simply
<field name="invitation.id">
<field-validator type="required">
<message>${getText("validation.invitation.id.required")}</message>
</field-validator>
</field>
<field name="newText">
<field-validator type="requiredString">
<message>${getText("validation.newText.required")}</message>
</field-validator>
</field>
Note that required is for every non-text fields, while requiredString is for text fields only.
Expression Validator is very powerful, but it should be used for more complex purposes:
for example, if you want to validate a Date against another one dynamically read (through a Getter) from your Action; lets say you've previously chosen a User, and you need to validate a date from the page against the user Start and End Validity interval; but you want to pass the validation too if the date is not inserted, because it is already handled by the required validator (so you won't raise two messages):
<field name="inputDate">
<field-validator type="required">
<message><![CDATA[ Input Date is mandatory ]]></message>
</field-validator>
<field-validator type="fieldexpression">
<param name="expression">
<![CDATA[
inputDate==null ||
(inputDate >= chosenUser.startValidity
&&
inputDate <= chosenUser.EndValidity
)
]]>
</param>
<message>
<![CDATA[Input Date must be included in the User Validity interval
(from ${chosenUser.startValidity} to ${chosenUser.endValidity} )
]]>
</message>
</field-validator>
</field>
where chosenUser is an User object from your Action (public User getChosenUser())
and startValidity and endValidity are properties of the User object (public Date getEndValidity()).
And as you can see, the dynamic read can be performed in messages too... this is how powerful expression validator is ;)
First of all expression is not a valid parameter. If you really want to validate on client side, try to use java-script or jquery for validation. But you have to validate inputs on server - side also because sometimes user could disable the javascript .So in that case you can use struts2 - validation.
for detailed explanation refer http://viralpatel.net/blogs/struts2-validation-framework-tutorial-example/
Ok, finally I used client-side validation width jquery emulating struts2.
I don't like this for compatibility reasons, please if there is a way to do it in a standard way, I'll apreciate any help.
Removing struts validation:
<!--<field name="newText">
<field-validator type="fieldexpression">
<param name="expression">!((invitation.id==null or invitation.id.empty) and (newText==null or newText.empty))</param>
<message>${getText("validation.required")}</message>
</field-validator>
</field>-->
Adding js/jquery code:
function mySubmit() {
if ((invitationId==null || invitationId<0) && $("#text").val().trim()=='') {
var trStrutsFieldError='<tr errorfor="text">'+
'<td colspan="2" align="center" valign="top"><span class="errorMessage">'+strValidationRequired+'</span></td>'+
'</tr>';
$(trStrutsFieldError).insertBefore($("#text").parent().parent());
return false;
}
return true;
}
$(document).ready(function(){
$("form").submit(function(event) {
$.each($("form").find("span.errorMessage"), function() { /* <tr errorfor="title"><td colspan="2" align="center"><span classname="errorMessage" class="errorMessage">Campo requerido */
return false;
});
if ($(mySubmit).exists()) {
if (!mySubmit())
return false;
}
return true;
});
});
I am trying to do validation on a Map using struts 2.
When I click on the submit button, the error message will always appear even though I have inserted a value into the textbox.
Is there anyway for it to work?
Any help will be much appreciated.
The following is my file
In my new.jsp
<s:textfield name="myObject.myMap['name']" key="name" ></s:textfield>
In the validaton.xml
<validators>
<field name="myObject.myMap['name']">
<field-validator type="requiredstring">
<message key="errors.required"/>
</field-validator>
</field>
</validators>
I have the following Java class defined in src/java
package org.davisworld.trip;
public class AirportHbm {
private long id;
private String name;
private String iata;
private String state;
private String lat;
private String lng;
// getters/setters defined
}
I have the hbm.cfg.xml file defined as follows in conf/hibernate:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<mapping resource="AirportHbm.hbm.xml"/>
</session-factory>
</hibernate-configuration>
I have the AirportHbm.hbm.xml file configured as follows in conf/hibernate:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.davisworld.trip.AirportHbm" table="usgs_airports">
<id name="id" column="airport_id">
<generator class="native"/>
</id>
<property name="name" type="java.lang.String">
<column name="airport_name" not-null="true" />
</property>
<property name="iata" type="java.lang.String">
<column name="locid" not-null="true" />
</property>
<property name="state" />
<property name="lat" column="latitude" />
<property name="lng" column="longitude" />
</class>
</hibernate-mapping>
And lastly, I have an AirportHbmConstraints.groovy file in the src/java folder:
package org.davisworld.trip
class AirportHbmConstraints {
static constraints = {
name()
iata(maxSize:3)
state(maxSize:2)
lat()
lng()
}
}
When I try to run the app, I get this error when Spring is initializing the web app context:
Caused by: java.lang.ClassCastException: org.davisworld.trip.AirportHbmConstraints cannot be cast to groovy.lang.Script
The tutorial I was following originally said that the AirportHbmConstraints.groovy file shouldn't have a class; it should just be a script:
package org.davisworld.trip
static constraints = {
name()
iata(maxSize:3)
state(maxSize:2)
lat()
lng()
}
But when I do that, STS gives me a compiler error:
Groovy:Modifier 'static' not allowed here.
Anyone know what I'm doing wrong? What is the correct way to apply constraints in Groovy to a Java domain class?
Many thanks,
Vito
When using constraints scripts with a Hibernate domain you do not use a class declaration or the static modifier as explained in section 15.3 Adding Constraints of the Grails documentation.
The correct constraint script would be:
constraints = {
iata maxSize: 3
state maxSize: 2
}
Note that fields without a constraint and the parentheses on the field declaration are optional.
I have one form containing one checkbox(not checkbox list)and one textfield.
If the checkbox is cheked then no need to enter the value for textfield.
If the check box is not checked then I need to validate the textfield has mandatory.
How can I do using expression validator.Is this Possible in struts2.0.11.
Let me know
Thanks in advance
Use fieldexpression validator. Example :
SomeAction.java
private SomeObject object; // with getter & setter
private boolean doNotCheck; // with setter
input.jsp
<s:textfield name="object.field" />
<s:checkbox name="doNotCheck" />
<s:fielderror fieldName="object.field" />
SomeAction.validation.xml
<validators>
<field name="object.field">
<field-validator type="fieldexpression">
<param name="expression">
<![CDATA[ isDoNotCheck() ? true : (object.field != null && !object.field.isEmpty()) ]]>
<!-- OR -->
<!-- isDoNotCheck() ? true : !object.field.isEmpty() -->
</param>
<message>This is a mandatory field</message>
</field-validator>
</field>
</validators>
You can implement validate() method in your action class and add the validation code in it.
For details, please read the docs.
http://struts.apache.org/2.x/docs/form-validation.html
Another option is xml validation.
http://struts.apache.org/2.x/docs/validation.html