access variable passed by java class within @Repeat complains error

51 views
Skip to first unread message

jilen nil

unread,
Apr 25, 2013, 8:05:41 AM4/25/13
to google-s...@googlegroups.com
@Repeat(items=apps, var="app")
<li>
${app.clientId}<a href="$urls[app.clientId]" > auth</a>
</li>


that's my html code.
the $urls is passed by the Java class. 
It complains compile error

Dhanji R. Prasanna

unread,
Apr 25, 2013, 8:49:09 AM4/25/13
to google-s...@googlegroups.com
Try this (make sure the Java class has got getUrls() defined):

${app.clientId}<a href="${urls[app.clientId]}" > 


--
You received this message because you are subscribed to the Google Groups "Google Sitebricks" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-sitebri...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

jilen nil

unread,
Apr 25, 2013, 11:38:40 AM4/25/13
to google-s...@googlegroups.com

I am sorry to make this silly mistake. I have tried 
  1.  ${urls[app.clientId]} 
  2.  ${urls['${app.clientId}']} 
  3.  {$urls[${app.clientId}]}

Look at the simplest case

@At("/")
public class Example {
    private String message = "Hello";
    private List<String> users = Arrays.asList("jilen");
    private final Map<String, String> userMap = new HashMap<String, String>();
    @Get
    public void get() {
        userMap.put("jilen", "foo");
    }
    public List<String> getUsers() {
        return users;
    }
    public void setUsers(List<String> users) {
        this.users = users;
    }
    public Map<String, String> getUserMap() {
        return userMap;
    }
    public String getMessage() {
        return message;
    }
    public void setMessage(String message) {
        this.message = message;
    }
}


<html>
<body>
<p>${message} from Sitebricks!</p>
@Repeat(items=users, var="user")
<div>${userMap}</div>

</body>
</html>

It will not compile.

But this html (access outside of @Repeat) works fine
<html>
<body>
<p>${message} from Sitebricks!</p>
@Repeat(items=users, var="user")
<div></div>
${userMap}
</body>
</html> 

jilen nil

unread,
Apr 25, 2013, 12:03:28 PM4/25/13
to google-s...@googlegroups.com
I think I find the reason. The @Repeat is a widget. It has no property expect for items and var. 
So variables defined in Page class is not accessible.

Dhanji R. Prasanna

unread,
Apr 25, 2013, 11:05:01 PM4/25/13
to google-s...@googlegroups.com
Ahh inside a repeat you need to use: 
__page.userMap

Because main var is now 'user'

jilen nil

unread,
Apr 26, 2013, 3:38:47 AM4/26/13
to google-s...@googlegroups.com
Thank you very much!!!  This really helps. 
To unsubscribe from this group and stop receiving emails from it, send an email to google-sitebricks+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages