Some comments inline:
Scott Eade wrote:
>
> I'm having a hell of a time getting intake to work in my application.
>
> It looks like the intake information included in the tdk 2.1
> documentation is a little out of date - the intake.xml examples
> use a syntax that will not validate against intake.dtd.
>
> Even looking at Scarab I don't quite get it.
>
> Jon, or anyone else that has managed to get intake working, I
> would appreciate it if you can have a look at the code included
> below to see if you can spot where I am going wrong.
>
> With the setup detailed below, intake enforces a mask rule
> on the url field, but:
> a) it doesn't seem to enforce any of the other rules, including
> minLength, required and required-message (I'm trying all of
> the methods available)
The minLength rule was broken, it is fixed in the HEAD.
The required rule should work. I would concentrate efforts here, though
I do not have any specific advise on why it is broken for you.
The required-message rule needs some clarification in the docs, but it
only provides a way to keep the messages in a central location. It does
not force the field to be required. It is useful if the field is not
always required, so in an Action you would have
field.setRequired(conditional)
if (intake.isAllValid())
...
and if the conditional=true and the field did not have a value and you
have the template set up to show an error message
<font color=red>$field.Message</font>
would show the message specified in <required-message>
If the field is always going to be required you are better off using
<rule name=required value=true>This field is required</rule>
style as you do not need to include the additional code in Action(s).
> b) when an error does come back, the form data is reset
> to what it was before any changes were made, I need it
> to show the edited data so that the messages make sense.
> c) When all rules do pass, the data is not being written
> to the database. In fact, it seems that the data is not even
> making it to the action (my debug statements produce no
> output). I must be missing a mapping somewhere, but I
> am unsure where and how.
> d) While intake.isAllValid() appears to be working,
> group.isAllValid() does not. Is this a bug or is it a
> side-effect of the presumably missing mapping?
>
> Here is an outline of what I have (a minor variation only to
> newapp):
>
> 1. The appropriate lines in TR.properties to configure intake.
>
> 2. intake.xml thus (this validates):
>
> <?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
> <!DOCTYPE input-data SYSTEM
> "http://jakarta.apache.org/turbine/dtd/intake.dtd">
>
> <input-data basePackage="com.backstagetech.cmes.">
>
> <group name="Subject" key="subject" mapToObject="om.Subject">
>
> <field name="SubjectId" key="subjectid" type="NumberKey"/>
>
> <field name="Title" key="t" type="String">
> <rule name="minLenght" value="1">Please enter a title</rule>
> </field>
>
> <field name="Author" key="a" type="String">
> <required-message>Please enter an author</required-message>
> </field>
>
> <field name="Department" key="d" type="String" mapToProperty="Dept">
> <rule name="required" value="true">Please enter a department</rule>
> </field>
>
> <field name="Url" key="u" type="String">
> <rule name="mask" value="^$|http://.+">Please enter a valid url (should begin
>"http://")</rule>
> <required-message>Please enter a url</required-message>
> </field>
>
> <field name="Body" key="b" type="String">
> <required-message>Please enter a body</required-message>
> </field>
>
> </group>
>
> </input-data>
>
> 3. An action that retrieves a database record into the context
> as "entry" (Login.java, modified slightly to use class Subject
> rather than Rdf - for all intents and purposes these are exactly
> the same)
>
> 4. A screen template that includes:
>
> #set ( $action =
>$link.setPage("Form.vm").setAction("SaveForm").addPathInfo("nextTemplate",
>"Index.vm") )
> <form method="post" action="$action">
>
> #set ( $group = $intake.Subject.mapTo($entry) )
>
> <div align="left">
> <table bgcolor="#ffffff" cellpadding="5">
> <tr>
> #if ( !$group.Title.isValid() )
> $group.Title.Message<br>
> #end
> #formCell ("Title" "$group.Title.Key" $!group.Title)
> </tr>
> <tr>
> #if ( !$group.Author.isValid() )
> $group.Author.Message<br>
> #end
> #formCell ("Author" "$group.Author.Key" $!group.Author)
> </tr>
> <tr>
> #if ( !$group.Department.isValid() )
> $group.Department.Message<br>
> #end
> #formCell ("Department" "$group.Department.Key" $!group.Department)
> </tr>
> <tr>
> #if ( !$group.Url.isValid() )
> $group.Url.Message<br>
> #end
> #formCell ("Url" "$group.Url.Key" $!group.Url)
> </tr>
> <tr>
> #if ( !$group.Body.isValid() )
> $group.Body.Message<br>
> #end
> #formCell ("Body" "$group.Body.Key" $!group.Body)
> </tr>
> </table>
>
> <input type="hidden" name="subjectid" value="$group.SubjectId"/>
> <input type="submit" name="eventSubmit_doInsert" value="Insert"/>
> <input type="submit" name="eventSubmit_doUpdate" value="Update"/>
> <input type="submit" name="eventSubmit_doDelete" value="Delete"/>
> </div>
> $intake.declareGroups()
> </form>
>
> 5. An action SaveForm.java (a variation of SQL.java)
> that includes (excuse my use of the error log, I don't
> seem to be able to get debug logging to work):
>
> public void doUpdate(RunData data, Context context)
> throws Exception
> {
> IntakeTool intake = (IntakeTool)context.get("intake");
>
> // Note: There appears to be a bug in that intake says the group is valid
> // when it is not. Use intake.isAllValid() as a workaround.
> Group group = intake.get("Subject", IntakeTool.DEFAULT_KEY);
I am a bit confused by your use of the Default_Key. It is also showing
up in your html shown at the end, but I see no mention of it in your
sample template above. I would use
group = intake.get("Subject", entry.getQueryKey());
where entry would be the same object (or representing the same object,
as in having the same PrimaryKey) You appear to be using a new Subject
even to represent an object that is already saved in the database. I
don't recommend this, but it could be made to work.
The DEFAULT_KEY is meant to be used in cases where the fields do not map
to any object and instead of making up a key, a default one is
provided. There is nothing special about it as a key.
>
> org.apache.turbine.util.Log.error("SaveForm: intake.isAllValid: " +
>intake.isAllValid());
> org.apache.turbine.util.Log.error("SaveForm: group.isAllValid: " +
>group.isAllValid());
>
> org.apache.turbine.util.Log.error("SaveForm: titleValue is: " +
>group.get("Title").toString());
> org.apache.turbine.util.Log.error("SaveForm: titleValue is: " +
>group.get("Department").toString());
> org.apache.turbine.util.Log.error("SaveForm: titleValue is: " +
>group.get("Url").toString());
>
> // check to see if the fields are valid
> if ( intake.isAllValid() )
> {
> Subject entry = new Subject();
> group.setProperties(entry);
>
> //data.getParameters().setProperties(entry);
> entry.setModified(true);
> entry.setNew(false);
> entry.save();
>
> String template = data.getParameters()
> .getString("nextTemplate", "Index.vm");
> setTemplate(data, template);
> }
> }
>
> 6. In case it is relevant, here is the generated html (note
> that the error message above the Url row is outside a cell
> and is thus thrown to the top of the table):
>
> <form method="post"
>
>action="http://localhost:8080/cmes/servlet/cmes/template/Form.vm/action/SaveForm/nexttemplate/Index.vm">
>
> <div align="left">
> <table bgcolor="#ffffff" cellpadding="5">
> <tr>
>
> <td bgcolor="#b3cc99">
> <b>
> <font face="verdana,geneva,helvetica">
> Title
> </font>
> </b>
> </td>
> <td bgcolor="#b3bb99">
> <font face="verdana,geneva,helvetica">
> <input type="text" size="30" name="subject2t" value="b">
> </font>
> </td>
> </tr>
> <tr>
> <td bgcolor="#b3cc99">
> <b>
> <font face="verdana,geneva,helvetica">
> Author
> </font>
> </b>
> </td>
> <td bgcolor="#b3bb99">
> <font face="verdana,geneva,helvetica">
> <input type="text" size="30" name="subject2a" value="b">
> </font>
> </td>
> </tr>
> <tr>
> <td bgcolor="#b3cc99">
> <b>
> <font face="verdana,geneva,helvetica">
> Department
> </font>
> </b>
> </td>
> <td bgcolor="#b3bb99">
> <font face="verdana,geneva,helvetica">
> <input type="text" size="30" name="subject2d" value="b">
> </font>
> </td>
> </tr>
> <tr>
> Please enter a valid url (should begin "http://")<br>
> <td bgcolor="#b3cc99">
> <b>
> <font face="verdana,geneva,helvetica">
> Url
> </font>
> </b>
> </td>
> <td bgcolor="#b3bb99">
> <font face="verdana,geneva,helvetica">
> <input type="text" size="30" name="subject2u" value="b">
> </font>
> </td>
> </tr>
> <tr>
> <td bgcolor="#b3cc99">
> <b>
> <font face="verdana,geneva,helvetica">
> Body
> </font>
> </b>
> </td>
> <td bgcolor="#b3bb99">
> <font face="verdana,geneva,helvetica">
> <input type="text" size="30" name="subject2b" value="">
> </font>
> </td>
> </tr>
> </table>
>
> <input type="hidden" name="subjectid" value="2"/>
> <input type="submit" name="eventSubmit_doInsert" value="Insert"/>
> <input type="submit" name="eventSubmit_doUpdate" value="Update"/>
> <input type="submit" name="eventSubmit_doDelete" value="Delete"/>
> </div>
> <input type="hidden" name="intake-grp" value="subject"></input>
> <input type="hidden" name="subject" value="_0">
not sure where the above line comes from as I did not see the
DEFAULT_KEY mentioned in your template, is it?
</input><input type="hidden" name="subject" value="2"></input>
> </form>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
john mcnally
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]