First of all are you using tdk 2.1?
I've managed to get Intake to work fine using the approach you outline
below.
In the HTML I have the following:
#set ( $detailGroup = $intake.CompanyDetails.Default )
#if ( !$detailGroup.ContactName.isValid() )
<tr>
<td colspan="5" class="errorMessage">
$detailGroup.ContactName.Message
</td>
</tr>
#end
This uses the following XML group:
<group name="CompanyDetails" key="details">
<field name="Name" key="name" type="String">
<rule name="required" value="true">Please enter a company name</rule>
</field>
<field name="ContactName" key="contactname" type="String">
<rule name="required" value="true">Please enter a contact name</rule>
</field>
<field name="ContactEmail" key="contactemail" type="String">
<rule name="required" value="true">Please enter an email address</rule>
<rule name="mask" value=".+@.+\..+">Please enter a valid email
address</rule>
</field>
<field name="ContactPhone" key="contactphone" type="String">
<rule name="required" value="true">Please enter a contact phone
number</rule>
</field>
<field name="ContactFax" key="contactfax" type="String"/>
</group>
And this works like a charm.
If you are still having problems reply with your complete code/XML/HTML
attached and I will review it to see if I can work out the problem.
With regard to what's the difference between
<required-message></required-message> and
<rule name="required" value="true"></rule>:
<required-message> is only used when you specify a field as required in your
Java code (see the examples). <rule name="required" value="true"> is a newer
version that was only added recently and works automatically when the form
is validated and does not require you to respecify the required fields in
your code. Personally I think <required-message> should probably be removed.
James
-----Original Message-----
From: Guido Sohne [mailto:[EMAIL PROTECTED]]
Sent: 08 June 2001 02:14
To: [EMAIL PROTECTED]
Subject: intake - messages not appearing
In a screen file containing the velocity code below :-
#set ( $departmentGroup = $intake.Department.Default )
#if ( !$departmentGroup.RowID.isValid() )
$departmentGroup.RowID.Message<br>
#end
Dept. ID <input name= "$departmentGroup.RowID.Key"
value="$!departmentGroup.RowID" size="25" type="text">
the value $departmentGroup.RowID.Message is always blank.
$departmentGroup.RowID.getValidator() does not work, it only
returns the string "$departmentGroup.RowID.getValidator". I
tried this when testing to see if $departmentGroup.RowID was
a Field object.
I've tried the screen with different values that fail / pass the rules
determining validity and output pass / fail to turbine.log. I'm
certain my validation rules are correct but I can't figure out
how to get the messages on validation pertaining to the rule
being violated from the project-inputs.xml file.
Here's the group in project-inputs.xml (TurbineProperties
knows about this file and Intake is parsing it with no problems)
<input-data basePackage="com.softghana.pettycash">
<group name="Department" key="department" mapToObject="om.Department">
<field name="RowID" key="rowid" type="NumberKey">
<rule name="mask" value="^$|[0-9]+">Invalid Object ID. Call
SOFT.</rule>
<rule name="required" value="true">Invalid Object ID. Call
SOFT.</rule>
<required-message>Object ID must either be a number or
blank.</required-message>
</field>
<field name="Name" key="name" type="String">
<rule name="minLength" value="1">Please enter a department
name.</rule>
<rule name="maxLength" value="50">Department name cannot be longer
than 50 characters</rule>
<rule name="required" value="true">A department name is
required.</rule>
<required-message>You need to give a name to this
department.</required-message>
</field>
</group>
</input-data>
I tried creating rules like
<rule name="required" value="true">Message when required</rule>
tried changing
<field name="RowID" key="rowid" type="NumberKey">
to
<field name="RowID" key="rowid" type="NumberKey"
validator="NumberKeyValidator">
after looking at the intake code but to no avail.
XmltoAppData.java shows that the messages are being parsed ok as below:-
public void characters(char[] mesgArray, int start, int length)
{
String cdata = new String(mesgArray, start, length).trim();
if ( "rule".equals(currElement) && cdata.length() > 0)
{
currRule.setMessage(cdata);
}
if ( "required-message".equals(currElement) && cdata.length() > 0)
{
currField.setIfRequiredMessage(cdata);
}
}
now fields get flagged as valid / invalid by their assigned validator inside
the
Field.validate(ParameterParser pp) method
try
{
validator.assertValidity(s);
}
catch (ValidationException ve)
{
setMessage(ve.getMessage());
}
So how does one go about showing messages when input data violates the
constraints
specified in project-input.xml ? Everything seems fine - I must be missing
something.
Also what's the difference between <required-message></required-message> and
<rule name="required" value="true"></rule> ?
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]