Render Partial Collection

100 views
Skip to first unread message

Nanang Suryadi

unread,
Nov 3, 2013, 11:19:30 PM11/3/13
to acti...@googlegroups.com

Hi There,

Please help me,
<div class="card-list">
       <@render partial="/pages/card_app_produk" collection=products/>
</div>

public void index() {
        String[] produk = {"camelot.jpg", "moderncombat.jpg", "robot.jpg",
                "tesla.png", "letsmego.jpg"};
        view("product", produk);
        view("appl","polier");
        view("clusterTitle", "Kesehatan & ibu janin");
}

I cannot parse list variable products in template

Igor Polevoy

unread,
Nov 3, 2013, 11:30:28 PM11/3/13
to acti...@googlegroups.com
Can you please post error and exception stack trace? 

Igor Polevoy

unread,
Nov 3, 2013, 11:31:01 PM11/3/13
to acti...@googlegroups.com
and also, source of the partial?

Nanang Suryadi

unread,
Nov 3, 2013, 11:42:29 PM11/3/13
to acti...@googlegroups.com
org.javalite.activeweb.ViewException: Failed to render template: '/system/error.ftl', with layout: '/layouts/default_layout'; Expression stack_trace is undefined on line 16, column 3 in system/error.ftl.
    at org.javalite.activeweb.freemarker.FreeMarkerTemplateManager.merge(FreeMarkerTemplateManager.java:123)
    at org.javalite.activeweb.RenderTemplateResponse.doProcess(RenderTemplateResponse.java:82)
    at org.javalite.activeweb.ControllerResponse.process(ControllerResponse.java:64)
    at org.javalite.activeweb.ControllerRunner.renderResponse(ControllerRunner.java:134)
    at org.javalite.activeweb.ControllerRunner.run(ControllerRunner.java:80)
    at org.javalite.activeweb.RequestDispatcher.doFilter(RequestDispatcher.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: freemarker.core.InvalidReferenceException: Expression stack_trace is undefined on line 16, column 3 in system/error.ftl.
    at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)
    at freemarker.core.Expression.getStringValue(Expression.java:118)
    at freemarker.core.Expression.getStringValue(Expression.java:93)
    at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
    at freemarker.core.Environment.visit(Environment.java:221)
    at freemarker.core.MixedContent.accept(MixedContent.java:92)
    at freemarker.core.Environment.visit(Environment.java:221)
    at freemarker.core.Environment.process(Environment.java:199)
    at freemarker.template.Template.process(Template.java:259)
    at org.javalite.activeweb.freemarker.FreeMarkerTemplateManager.merge(FreeMarkerTemplateManager.java:98)
    ... 21 more

please what should i do??
thanks, igor


--
--
You received this message because you are subscribed to the Google
Groups "ActiveWeb Group" group.
To post to this group, send email to acti...@googlegroups.com
To unsubscribe from this group, send email to
activeweb+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/activeweb?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "ActiveWeb Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to activeweb+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Nanang Suryadi
BB.3278B031
T.08815015640
_card_app_produk.ftl
_card_wrapper.ftl

Igor Polevoy

unread,
Nov 4, 2013, 1:08:06 PM11/4/13
to acti...@googlegroups.com
The variable name inside  your partial is not correct. If you iterate a collection inside a partial, then ,you can access a variable from collection using the same name as partial itself

For instance, you call a partial "_carr_app_produk.ftl" like  this: 

 <@render partial="/pages/card_app_produk" collection=products/>

Then you have this code inside the partial:

<img class="cover-image" src="asset/img/${product}"/>

What you need to do is: 

<img class="cover-image" src="asset/img/${carr_app_produk}"/>

Please, read the doc: http://code.google.com/p/activeweb/wiki/Views#Partials_naming_and_location

However, the exception is not what I'd expect, and I will look into that 

thanks,

Nanang Suryadi

unread,
Nov 9, 2013, 6:36:33 AM11/9/13
to acti...@googlegroups.com
oke thank igor, 
the partial template can render now :-)

Mattias coudron

unread,
May 11, 2015, 5:16:18 PM5/11/15
to acti...@googlegroups.com
Hi Igor,

Can i use this to iterate over a collection of objects that have multiple member fields?

Thanks.

Igor Polevoy

unread,
May 11, 2015, 5:32:36 PM5/11/15
to acti...@googlegroups.com, mattias...@gmail.com
Yes, this is totally possible. You can go after members their members, their members, etc. Please have a look at this example: https://github.com/javalite/activeweb-rest
While this is a Web service, the same logic applies to HTML

Tx
Reply all
Reply to author
Forward
0 new messages