You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Andrea Sponziello <an...@unile.it> on 2004/10/21 10:49:30 UTC

macro does not load first time

Hi all,

I have a problem in using macros in a web application (I use Struts, 
Velocity 1.4 and
Tomcat 5 as container).

When the application Starts/Restarts macros are shown as simple
text and are not processed, for example I see:

#showMyForm()

instead of the form rendered by this macro. If  I do a simple refresh of
the page the macro seems loading and is correctly rendered.

I made searches in the archives but, due to some problem, I can't read 
old mails
referring to this problem as I posted a few days ago
(subject was: "problems searching user-list archive").

Can someone help me? Is this a bug or I misconfigured some option?

Tanks for your time,

Andrea

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


Re: macro does not load first time

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Andrea,

> When the application Starts/Restarts macros are shown as simple
> text and are not processed, for example I see:
> 
> #showMyForm()
> 
> instead of the form rendered by this macro. If  I do a simple refresh of
> the page the macro seems loading and is correctly rendered.
Where are you defining your macro?  You might be calling it before it is
loaded.

Check out the "Can I register Velocimacros via #parse() ?" section of
    http://jakarta.apache.org/velocity/user-guide.html#Velocimacro%20Miscellany

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai <sh...@gmail.com>


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


Re: macro does not load first time

Posted by Andrea Sponziello <an...@unile.it>.
Tanks Shinobu,

it is exactly what I need and it works perfectly!

(I think that Velocity is a winner technology and I can't go back
to jsp no more!)

Good work,

Andrea

Shinobu Kawai wrote:

>Hi Andrea,
>
>  
>
>>The User Manual says:
>>
>>"simply use the |velocimacro.library| facility to have Velocity load
>>your VMs at startup"
>>
>>My problem is that I need to use MANY files with macro declarations.
>>This is important for
>>me because many developers produce macros to obtain more readable files
>>and is good for
>>them storing their macros in different files (one file for each
>>developer/module for example).
>>It is very difficult to share a single "macro-declarations file" in a
>>multi-developer environment.
>>    
>>
>You can set multiple velocimacro files by separating each with a comma.
>    velocimacro.library = VM_Andrea_library.vm, VM_Shinobu_library.vm
>If you don't want the line to get long, you can continue to a new line
>with a backslash.
>    velocimacro.library = \
>        andrea/VM_Andrea_library.vm, \
>        shinobu/VM_Shinobu_library.vm
>If you don't want the velocity.properties file to get big, you can
>extract the property with the "include" property.
>  velocity.properties:
>    include = velocimacro.properties
>
>  velocimacro.properties:
>    velocimacro.library = \
>        andrea/VM_Andrea_library.vm, \
>        shinobu/VM_Shinobu_library.vm
>For details, refer to commons-Collections ExtendedProperties
>    http://jakarta.apache.org/commons/collections/apidocs/org/apache/commons/collections/ExtendedProperties.html
>
>Best regards,
>-- Shinobu Kawai
>
>  
>


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


Re: macro does not load first time

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Andrea,

> The User Manual says:
> 
> "simply use the |velocimacro.library| facility to have Velocity load
> your VMs at startup"
> 
> My problem is that I need to use MANY files with macro declarations.
> This is important for
> me because many developers produce macros to obtain more readable files
> and is good for
> them storing their macros in different files (one file for each
> developer/module for example).
> It is very difficult to share a single "macro-declarations file" in a
> multi-developer environment.
You can set multiple velocimacro files by separating each with a comma.
    velocimacro.library = VM_Andrea_library.vm, VM_Shinobu_library.vm
If you don't want the line to get long, you can continue to a new line
with a backslash.
    velocimacro.library = \
        andrea/VM_Andrea_library.vm, \
        shinobu/VM_Shinobu_library.vm
If you don't want the velocity.properties file to get big, you can
extract the property with the "include" property.
  velocity.properties:
    include = velocimacro.properties

  velocimacro.properties:
    velocimacro.library = \
        andrea/VM_Andrea_library.vm, \
        shinobu/VM_Shinobu_library.vm
For details, refer to commons-Collections ExtendedProperties
    http://jakarta.apache.org/commons/collections/apidocs/org/apache/commons/collections/ExtendedProperties.html

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.com>

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


Re: macro does not load first time

Posted by Andrea Sponziello <an...@unile.it>.
Hi,

I read also the mail of Shinobu.

I've a file like this:

---- login.vm ---------------
#parse("login_macros.vm")

#errors()
#showLoginForm()
-----------------------------

and in "login_macros.vm" (the file parsed) is defined "showLoginForm()".
This doesn't work.
I see "#showLoginForm()" instead of the rendered form.
#errors() is defined in VM_global_library and works well (is correctly 
rendered).

The problem is, I think, that I'm using #parse directive to include a 
file that contains macro
declarations. But as I understood reading the User Manual, #parse loads 
the macros but
they will be probabily available only next time that "login.vm" will be 
called...

The User Manual says:

"simply use the |velocimacro.library| facility to have Velocity load 
your VMs at startup"

My problem is that I need to use MANY files with macro declarations. 
This is important for
me because many developers produce macros to obtain more readable files 
and is good for
them storing their macros in different files (one file for each 
developer/module for example).
It is very difficult to share a single "macro-declarations file" in a 
multi-developer environment.

Using, for example, many #parse directives into VM_global_library.vm to 
include, at startup,
external macro files doesn't work. If it works can solve my problems. 
Naturally, the best is
that each developer can store his "macro_declarations files" into a 
folder and include (#parse)
it in every place he needs to use a macro (without modifyng a central 
macro file, and this is
the way #parse directive works in my first analysis of the Velocity 
Framework)...

I also read about this property:

file.resource.loader.path = templates

I put my "macro_declarations files" inside this folder but nothing...

Again, tanks for your time

Andrea

...
Terry Steichen wrote:

>If you put your macro at the beginning of your Velocity template, it will run the first time.  The issue has to do with the sequence of processing, and has been around a long time.
>
>  ----- Original Message ----- 
>  From: Andrea Sponziello 
>  To: Velocity Users List 
>  Sent: Thursday, October 21, 2004 4:49 AM
>  Subject: macro does not load first time
>
>
>  Hi all,
>
>  I have a problem in using macros in a web application (I use Struts, 
>  Velocity 1.4 and
>  Tomcat 5 as container).
>
>  When the application Starts/Restarts macros are shown as simple
>  text and are not processed, for example I see:
>
>  #showMyForm()
>
>  instead of the form rendered by this macro. If  I do a simple refresh of
>  the page the macro seems loading and is correctly rendered.
>
>  I made searches in the archives but, due to some problem, I can't read 
>  old mails
>  referring to this problem as I posted a few days ago
>  (subject was: "problems searching user-list archive").
>
>  Can someone help me? Is this a bug or I misconfigured some option?
>
>  Tanks for your time,
>
>  Andrea
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>  For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>  
>


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


Re: macro does not load first time

Posted by Terry Steichen <te...@net-frame.com>.
If you put your macro at the beginning of your Velocity template, it will run the first time.  The issue has to do with the sequence of processing, and has been around a long time.

  ----- Original Message ----- 
  From: Andrea Sponziello 
  To: Velocity Users List 
  Sent: Thursday, October 21, 2004 4:49 AM
  Subject: macro does not load first time


  Hi all,

  I have a problem in using macros in a web application (I use Struts, 
  Velocity 1.4 and
  Tomcat 5 as container).

  When the application Starts/Restarts macros are shown as simple
  text and are not processed, for example I see:

  #showMyForm()

  instead of the form rendered by this macro. If  I do a simple refresh of
  the page the macro seems loading and is correctly rendered.

  I made searches in the archives but, due to some problem, I can't read 
  old mails
  referring to this problem as I posted a few days ago
  (subject was: "problems searching user-list archive").

  Can someone help me? Is this a bug or I misconfigured some option?

  Tanks for your time,

  Andrea

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