To answer my own question - No, you don't get it. The behaviour you are
after is already built into the group class.
You just use $intake.InvoiceLine.mapto( bean ).
The bean is asked for its query key, which by default returns the primary
key, then if the group exists, it is retrieved, and will deliver its
existing values when asked, otherwise a new one is created, in which case
the beans properties are delivered.
So the correct code is :-
#foreach ( $line in $invoice.getLines() )
#set $lineGroup = $intake.InvoiceLine.mapto( $line )
#textfield ( $LineGroup.ProdCode.Key $LineGroup.ProdCode )
#showError ( $LineGroup.ProdCode.isValid()
$LineGroup.ProdCode.getMessage() )
...etc
#end
However in my screen, I want a new empty line at the end of the table so I
add :-
#set ( $newLineGroup = $intake.InvoiceLine.Default )
#textfield ( $newLineGroup.ProdCode.Key $newLineGroup.ProdCode )
#showError ( $newLineGroup.ProdCode.isValid()
$newLineGroup.ProdCode.getMessage() )
...etc
This allows the user to add a new Invoice line, and it work fine,
mostly!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Sometimes, the line gets data in it from previous requests
AAAAAAAGGGGGGGHHHHHHH!!!!!!!!!!!!!
This happens even when I have been to another non-intake page inbetween.
When I do a browser refresh, the phantom data disappears.
I have put a bit of debug in IntakeTool.PullHelper.getDefault, and the data
is coming from there, not the browser, or something.
This same effect occasionaly turns up in the action also, when the user has
not added any data to the new line.
There is a clue here though - doing getValue( "ProdCode" ) returns 'abc',
but when you setProprties( aBean ) 'abc' is not set in the bean!!!!
I assume this is to do with pooling of objects, and failing to fully
reinitialize them on reuse???
Any help would be greatly welcomed - I really have put in the hours on this,
and I have read all the how to's, and searched the archives, and read the
source code....
Neil
----- Original Message -----
From: "Neil Stevens" <[EMAIL PROTECTED]>
To: "Turbine Users List" <[EMAIL PROTECTED]>
Sent: Saturday, November 16, 2002 12:49 AM
Subject: is it possible to distinguish new and old Groups in intake?
> I am doing my first project with Turbine, and Intake is giving me hell,
but
> I think I get it now, but anyway judge for yourself from this question :-
>
> If I am displaying an invoice and invoice lines on a single page, and
> allowing enterable fields throughout, I may do something like :-
>
> #foreach ( $line in $invoice.getLines() )
> #set $lineGroup = $intake.get( "InvoiceLine", $line.lineNo )
>
> #if ( !$redisplay )
> $lineGroup.init($line)
> #end
>
> #textfield ( $LineGroup.ProdCode.Key $LineGroup.ProdCode )
> #showError ( $LineGroup.ProdCode.isValid()
> $LineGroup.ProdCode.getMessage() )
> ...etc
> #end
>
>
> I only set $redisplay in the preceding action (if there has been one) if
> validation fails, so they see their data unchanged. On the first visit to
> the screen the groups are all initialized, as redisplay is not there.
>
> But I would really like to get rid of 'redisplay' and put:-
>
> #if ( !$lineGroup.isInitialized() )
>
> this would tell me if the group had been constructed from parameters or
just
> plucked from the pool or whatever.
> .
> This has the advantage that if a new invoice line has been added by user
B,
> whilst user A was slowly entering some invalid data, then the new line
would
> appear and be displayed correctly
> together with the invalid lines, and their error messages.
>
> Is it possible to perform such as test?
>
> I thought of maybe writing a macro that first tried an $intake.get(
> "InvoiceLine", $line.lineNo, false ) and if the result was null, then set
a
> flag and then $intake.get( "InvoiceLine", $line.lineNo, true ) to return
> the group. Maybe I could pass in the name of the flag to the macro ....?
>
> Anyway, any advice would be much appreciated.
>
> N
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>