Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recursive call of the templates a parameter being passed through, suddenly changes its value between the calls. #10

Closed
parrt opened this issue May 15, 2012 · 3 comments
Assignees
Labels

Comments

@parrt
Copy link
Member

parrt commented May 15, 2012

"Filkov, Hristo" writes:
I saw that version 4.0.4 is already released and I am glad about it. We are still working with the old version 4.0.3 and I think I found another bug, which appears also in the new 4.0.4 version.

The problem is, that on a recursive call of the templates a parameter being passed through, suddenly changes its value between the calls. In order to demonstrate the bug, I build a little directory. You can find the expected result in a file inside between sources, string templates and classes. The value change happens in particular while the "std_field_text" is being called from the "generic_field". I left the debugging messages in the code for you.

The bug appears with Java 1.5 and 1.6 on WinXp machine.

I looked over the released notes of the new version 4.0.4, but I did not understood, whether the problems I mentioned in my previous e-mails are solved. Both problems had to do with formatting by a renderer. As a memory hook, here both pieces of code that didn't work.

templateUrl() ::= << http://www.google.de?param1=2&param2=5 >> 
templateLink() ::= << <a href="$templateUrl();format="htmlattr"$">Link</a> >>

and

template1(someObject) ::= <<$someObject.someCollection:{element|$template2(element)$}$>>
template2(someElement) ::= <<$someElement;format=?someFormat?$>>

In both cases I had to use a workaround to get the outputs formatted. Could you please tell me, if the current status with these problems has changed in Version 4.0.4.

@ghost ghost assigned parrt May 15, 2012
@parrt
Copy link
Member Author

parrt commented May 15, 2012

Find STRecursionBug.zip in attachments.

@sharwell
Copy link
Member

You are invoking templates with unbound anonymous templates as arguments, with the syntax {...}.

std_field_dropdown(dropdown_field,depends_from) ::= <<
<std_field(dropdown_field,{<std_field_id(dropdown_field.name,[])>},depends_from)>
>>

std_field_selection(selection_field,sel_bt,depends_from) ::= <<
<std_field(selection_field,{<std_field_id(selection_field.name,sel_bt.value)>},depends_from)>
>>

std_field_text(text_field,depend_on) ::= <<
<std_field(text_field,{<std_field_id(text_field.name,[])>},depend_on)>
>>

std_field_textarea(txtarea_field,depends) ::= <<
<std_field(txtarea_field,{<std_field_id(txtarea_field.name,[])>},depends)>
>>

These templates are bound at the time they are rendered, which is a different context from where they are created. What you want to do is force these anonymous templates to bind and render in the current context and pass the evaluated result as the argument, with the syntax ({...}).

std_field_dropdown(dropdown_field,depends_from) ::= <<
<std_field(dropdown_field,({<std_field_id(dropdown_field.name,[])>}),depends_from)>
>>

std_field_selection(selection_field,sel_bt,depends_from) ::= <<
<std_field(selection_field,({<std_field_id(selection_field.name,sel_bt.value)>}),depends_from)>
>>

std_field_text(text_field,depend_on) ::= <<
<std_field(text_field,({<std_field_id(text_field.name,[])>}),depend_on)>
>>

std_field_textarea(txtarea_field,depends) ::= <<
<std_field(txtarea_field,({<std_field_id(txtarea_field.name,[])>}),depends)>
>>

@parrt
Copy link
Member Author

parrt commented Dec 11, 2012

just to be clear

std_field_dropdown(dropdown_field,depends_from) ::= <<
<std_field(dropdown_field,{<std_field_id(dropdown_field.name,[])>},depends_from)>
>>

passes an anonymous template, referencing argument dropdown_field, to another template whose context does not have dropdown_field. ST does dynamic lookup of attributes and does not bind them like closures would in a programming language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants