You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Scott Eade <se...@backstagetech.com.au> on 2001/06/22 05:20:04 UTC

intake problems

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)
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);

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"></input><input type="hidden" name="subject" value="2"></input>
</form>






---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Torque problems

Posted by zahid <za...@hotmail.com>.
i have a follwoing problem when start torque.bat

java.lang.SecurityException: sealing violation
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:234)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:120)
        at
javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:92)
        at
org.apache.tools.ant.ProjectHelper.getParserFactory(ProjectHelper.java:676)
        at org.apache.tools.ant.ProjectHelper.parse(ProjectHelper.java:104)
        at
org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:85)
        at org.apache.tools.ant.Main.runBuild(Main.java:403)
        at org.apache.tools.ant.Main.main(Main.java:149)

Total time: 1 second
sealing violation



---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: intake problems

Posted by John McNally <jm...@collab.net>.
Sorry,

The OMTool is not in a working state.  The piece that is missing is a
torque generated Factory to instantiate the BO's.  I had something close
on my hd, but never found a use for it, so it did not get finished. 
Intake contains a pull tool for an example as well as the ui tool.  I
will take a look at OMTool within the next few days and see if it is
worth finishing or if I should remove it.

John McNally

Scott Eade wrote:
> 
> John McNally - Did you miss my query below concerning
> OMTool usage?  I was hoping you might be able to help
> me along just a little bit more.
> 
> Thanks in advance,
> 
> Scott
> 
> ----- Original Message -----
> From: "Scott Eade" <se...@backstagetech.com.au>
> To: <tu...@jakarta.apache.org>
> Sent: Saturday, June 23, 2001 9:29 PM
> Subject: Re: intake problems
> 
> > From: "Scott Eade" <se...@backstagetech.com.au>
> > > I think I now have enough knowledge to go away and build
> > > my application.  Well almost, I think I need to read a bit more
> > > about the pull model before I jump in there.
> >
> > Okay John.  From the Javadoc it looks like you are the best
> > person for my follow up question on pull - specifically OMTool.
> > Responses from anyone else are of course welcome.
> >
> > Reading the Javadoc it looks like instead of having a Form
> > action I should instead be able to do this:
> >
> >     #set ( $entry = $om.get("Subject", $data.getParameters().get("subjectid")) )
> >
> > Which I could then map to intake as I did before.
> >
> > Later I could still use an action (SaveForm.vm in my running
> > example) to save the Subject back to the database.
> >
> > The invocation of get() above however results in a null pointer
> > exception.  Am I doing something wrong with OMTool?
> > I can imagine needing to initialise it first and perhaps obtain an
> > instance of OMTool from a pool, but I am a little unsure.
> >
> > Also, I am looking at this as a way to use pull rather than actions.
> > Is it conceivable that a pull tool might be used to update the
> > database as well (sort of more like push)?
> >
> > Thanks,
> >
> > Scott
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: intake problems

Posted by Scott Eade <se...@backstagetech.com.au>.
John McNally - Did you miss my query below concerning 
OMTool usage?  I was hoping you might be able to help 
me along just a little bit more.

Thanks in advance,

Scott

----- Original Message ----- 
From: "Scott Eade" <se...@backstagetech.com.au>
To: <tu...@jakarta.apache.org>
Sent: Saturday, June 23, 2001 9:29 PM
Subject: Re: intake problems


> From: "Scott Eade" <se...@backstagetech.com.au>
> > I think I now have enough knowledge to go away and build
> > my application.  Well almost, I think I need to read a bit more
> > about the pull model before I jump in there.
> 
> Okay John.  From the Javadoc it looks like you are the best
> person for my follow up question on pull - specifically OMTool.
> Responses from anyone else are of course welcome.
> 
> Reading the Javadoc it looks like instead of having a Form 
> action I should instead be able to do this:
> 
>     #set ( $entry = $om.get("Subject", $data.getParameters().get("subjectid")) )
> 
> Which I could then map to intake as I did before.
> 
> Later I could still use an action (SaveForm.vm in my running 
> example) to save the Subject back to the database.
> 
> The invocation of get() above however results in a null pointer 
> exception.  Am I doing something wrong with OMTool?
> I can imagine needing to initialise it first and perhaps obtain an
> instance of OMTool from a pool, but I am a little unsure.
> 
> Also, I am looking at this as a way to use pull rather than actions.
> Is it conceivable that a pull tool might be used to update the 
> database as well (sort of more like push)?
> 
> Thanks,
> 
> Scott



---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: intake problems

Posted by Scott Eade <se...@backstagetech.com.au>.
From: "Scott Eade" <se...@backstagetech.com.au>
> I think I now have enough knowledge to go away and build
> my application.  Well almost, I think I need to read a bit more
> about the pull model before I jump in there.

Okay John.  From the Javadoc it looks like you are the best
person for my follow up question on pull - specifically OMTool.
Responses from anyone else are of course welcome.

Reading the Javadoc it looks like instead of having a Form 
action I should instead be able to do this:

    #set ( $entry = $om.get("Subject", $data.getParameters().get("subjectid")) )

Which I could then map to intake as I did before.

Later I could still use an action (SaveForm.vm in my running 
example) to save the Subject back to the database.

The invocation of get() above however results in a null pointer 
exception.  Am I doing something wrong with OMTool?
I can imagine needing to initialise it first and perhaps obtain an
instance of OMTool from a pool, but I am a little unsure.

Also, I am looking at this as a way to use pull rather than actions.
Is it conceivable that a pull tool might be used to update the 
database as well (sort of more like push)?

Thanks,

Scott




---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: intake problems

Posted by Scott Eade <se...@backstagetech.com.au>.
> The logging properties have undergone changes recently, but the general
> idea is that in the TR.props logging properties there are some
> properties that end in (or contain) "level" which is set to ERROR or
> INFO or DEBUG, etc.  Make sure the appropriate one is set to DEBUG.

Excellent - I have this working now and am very pleased with the
functionality offered.

> > My last outstanding problem is that when a validation
> > error is picked up by intake and the form is redisplayed,
> > $entry is no longer in the context and thus the form is
> > displayed with no fields filled in.  I'm sure I had this
> > working at one point, but I can't seem to repeat it.
> > Can you spot my hopefully obvious mistake?
> > 
> 
> I do not understand why $entry would be in the context the first time
> Login.vm is displayed but not the next time.  Login.class's methods will
> be invoked in the exact same way every time.  But you are instantiating
> a new Subject each time, I am not sure how it would contain the data you
> want.  But the form fields should be showing the entered form text the
> second time anyway so what is in $entry should not matter, except that
> it have the same QueryKey.

I have managed to figure out what is causing $entry to be empty the
second time.  The link on Index.vm that goes to Form.vm includes:

    .addPathInfo("subjectid", $entry.SubjectId)

which provides the key to the Form action.  When a validation
error occurred on Form.vm, this parameter was not available and 
so $entry ends up being empty.  If I add the same parameter to 
the link that Form.vm submits to (which is itself, as required by
intake) the correct data is retrieved each time by the Form action.

I was half way through writing a whole bunch of stuff complaining
that the form is being reset each time a validation error is 
encountered, but in fact it is not!  What intake is doing is resetting 
the "required" fields that I have deleted in order to cause validation
errors.  If I change other fields so that they are still valid, the 
changes are retained.  This is pretty good - if the user deletes a
required entry, intake restores the original value automagically.
I am half inclined to point out an apparent inconsistency in that 
other rules (well at least mask) retain the edited value, but this
too is I think desirable.

I am very pleased to finally have intake working on my form.
Every day I work out how to use another piece of turbine and 
every day I am more impressed.

I think I now have enough knowledge to go away and build
my application.  Well almost, I think I need to read a bit more
about the pull model before I jump in there.

Thanks very much John for your time and patience in helping
me with this problem.

Cheers,

Scott








---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: intake problems

Posted by John McNally <jm...@collab.net>.
Scott Eade wrote:
> 
> So, Login.java retrieves the data to populate a Subject
> object and places this in the Velocity context thus:
> 
>     Subject subject = (Subject) SubjectPeer.doSelect(criteria).elementAt(0);
>     context.put("entry", subject);
> 
> > >
> > > 4. A screen template that includes:
> > >
> 
> In my screen template I need to map from $entry to
> intake thus:
> 
>     #set ( $group = $intake.Subject.mapTo($entry) )
> 
> This maps the values from $entry to intake with the key
> set to the value returned by $entry.getQueryKey() (at
> least this is what it appears to be doing).  $entry and the
> subject group in intake both include a SubjectId, as
> does the form (I have included these myself).  It is also
> included in the form a second time as "subject" (the key
> of the group) by virtue of $intake.declareGroups() at
> the bottom of the form.
> 
> In theory I can use the Default key thus:
> 
>     #set ( $group = $intake.Subject.Default )
> 
> I would do this when there was no entry to begin with
> and I just wanted to validate a form against an intake group.
> Is this correct?
> 

That sounds like you understand it.

> Incidentally, how does the mapToObject attribute of <group>
> in the intake xml file relate to this?  The documentation seems
> to say that if I omit this attribute then intake can retrieve the
> values directly.  This sounds like a desirable thing to be able
> to control, but I don't quite get it.
> 

If the Subject group did not map to any object so that mapToObject="",
then you would supply a key or use the Default.  In such a case you
would not use mapTo or setProperties, etc.  The fields would not be
prepopulated the first time the form is shown.  When you set a
mapToObject on a group it is expected that you will be supplying objects
of that type to back the group, so that the form can be prepopulated
with data and the object can be updated with the form data.


> > > 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):
> 
> <off-topic>
> Any idea why:
> 
>     org.apache.turbine.util.Log.debug("text to go to the debug log");
> 
> doesn't work out of the box?  Do I have to change something in
> TR.properties to get the debug messages to be produced?
> </off-topic>
> 

The logging properties have undergone changes recently, but the general
idea is that in the TR.props logging properties there are some
properties that end in (or contain) "level" which is set to ERROR or
INFO or DEBUG, etc.  Make sure the appropriate one is set to DEBUG.


> > 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.
> 
> That makes sense.  I now have:
> 
>     Group group = intake.get("Subject", data.getParameters().getString("subject"));
> 
> I am assuming that the "subject" (really the group key) field is added
> to the form to allow for this.  As I am now using the correct key to
> retrieve the intake group, isValidAll() on the group now works.

The hidden fields added at the end of the form are added for intake's
internal use.  They allow intake to construct the keys it needs to look
for as opposed to searching all the input and parsing the keys to
extract information.  It is more efficient.  Though there is no reason
you can not make use of the data.

> I can also go:
> 
>     Subject entry = new Subject();
>     group.setProperties(entry);
> 
> to give me a Subject object that I can then update in the database:
> 
>     entry.setModified(true);
>     entry.setNew(false);
>     entry.save();
> 
> > > 6. In case it is relevant, here is the generated html
> 
> The bottom of the generated form is now:
> 
>     <input type="hidden" name="subject2s" 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="2"></input>
> </form>
> 
> I include this to show the subject2s field (which is the
> SubjectId I included in the intake xml file and the form
> as well as the subject field which is the one generated by
> $intake.declareGroups() .
> 
> My last outstanding problem is that when a validation
> error is picked up by intake and the form is redisplayed,
> $entry is no longer in the context and thus the form is
> displayed with no fields filled in.  I'm sure I had this
> working at one point, but I can't seem to repeat it.
> Can you spot my hopefully obvious mistake?
> 

I do not understand why $entry would be in the context the first time
Login.vm is displayed but not the next time.  Login.class's methods will
be invoked in the exact same way every time.  But you are instantiating
a new Subject each time, I am not sure how it would contain the data you
want.  But the form fields should be showing the entered form text the
second time anyway so what is in $entry should not matter, except that
it have the same QueryKey.

john mcnally

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: intake problems

Posted by Rafal Krzewski <Ra...@e-point.pl>.
Scott Eade wrote:
> <off-topic>
> I have seen "HEAD" mentioned a few times over the last couple
> of days.  I've looked through the mail archive but I can't find a
> brief explanation of what people mean when they talk about
> it.  Is this the top of the CVS tree that will form the basis of
> some future version of torque?  It's talked about as if it
> pertains to some specific set of features.  Would you mind
> providing a small explanation for a newbee like me (or
> point me to where I can find this).
> </off-topic>

HEAD is a symbolic tag that the CVS uses to mark the tip (the newest
version) on the trunk (the main branch) of the version tree.

In other words, HEAD is the current/unstable/development version.

Rafal

--
mgr inz. Rafal Krzewski
Senior Internet Developer
mailto:Rafal.Krzewski@e-point.pl
+48 22 8534830 http://e-point.pl

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: intake problems

Posted by Scott Eade <se...@backstagetech.com.au>.
Thanks for the reply John - it helped a lot.  I still have one outstanding
problem and a few other questions if I can trouble you to read the
comments I have added below.

> 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).

Thanks for this info - very helpful.

<off-topic>
I have seen "HEAD" mentioned a few times over the last couple
of days.  I've looked through the mail archive but I can't find a 
brief explanation of what people mean when they talk about
it.  Is this the top of the CVS tree that will form the basis of 
some future version of torque?  It's talked about as if it 
pertains to some specific set of features.  Would you mind
providing a small explanation for a newbee like me (or
point me to where I can find this).
</off-topic>

> > 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)

>From what you are saying, the crux of my problem is that 
my mappings are out of wack.

>From your previous response I think I grasp things a little
better, but not quite as far as I need to make it work :-)

So, Login.java retrieves the data to populate a Subject 
object and places this in the Velocity context thus:

    Subject subject = (Subject) SubjectPeer.doSelect(criteria).elementAt(0);
    context.put("entry", subject);

> > 
> > 4. A screen template that includes:
> > 

In my screen template I need to map from $entry to
intake thus:

    #set ( $group = $intake.Subject.mapTo($entry) )

This maps the values from $entry to intake with the key
set to the value returned by $entry.getQueryKey() (at
least this is what it appears to be doing).  $entry and the
subject group in intake both include a SubjectId, as
does the form (I have included these myself).  It is also
included in the form a second time as "subject" (the key
of the group) by virtue of $intake.declareGroups() at
the bottom of the form.

In theory I can use the Default key thus:

    #set ( $group = $intake.Subject.Default )

I would do this when there was no entry to begin with
and I just wanted to validate a form against an intake group.
Is this correct?

Incidentally, how does the mapToObject attribute of <group>
in the intake xml file relate to this?  The documentation seems
to say that if I omit this attribute then intake can retrieve the
values directly.  This sounds like a desirable thing to be able
to control, but I don't quite get it.

> > 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):

<off-topic>
Any idea why:

    org.apache.turbine.util.Log.debug("text to go to the debug log");

doesn't work out of the box?  Do I have to change something in 
TR.properties to get the debug messages to be produced?
</off-topic>

> 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.

That makes sense.  I now have:

    Group group = intake.get("Subject", data.getParameters().getString("subject"));

I am assuming that the "subject" (really the group key) field is added 
to the form to allow for this.  As I am now using the correct key to
retrieve the intake group, isValidAll() on the group now works.
I can also go:

    Subject entry = new Subject();
    group.setProperties(entry);

to give me a Subject object that I can then update in the database:

    entry.setModified(true);
    entry.setNew(false);
    entry.save();
 
> > 6. In case it is relevant, here is the generated html

The bottom of the generated form is now:

    <input type="hidden" name="subject2s" 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="2"></input>
</form>

I include this to show the subject2s field (which is the
SubjectId I included in the intake xml file and the form
as well as the subject field which is the one generated by
$intake.declareGroups() .

My last outstanding problem is that when a validation
error is picked up by intake and the form is redisplayed, 
$entry is no longer in the context and thus the form is 
displayed with no fields filled in.  I'm sure I had this 
working at one point, but I can't seem to repeat it.
Can you spot my hopefully obvious mistake?

> 
> john mcnally
> 
Thanks again,

Scott


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: intake problems

Posted by John McNally <jm...@collab.net>.
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: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org


john mcnally

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org