You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by dizzi <D....@sh.cvut.cz> on 2007/04/05 01:48:34 UTC
Velocity counters and obj access
Hello,
I have 2 questions
1.
Is there way how to use 2 velocity counters in 2 nested loops?
(i didnt test it but my colleague had problem with that)
2.
I have this object (below), why I cant access to rok, mesic and den
arrays without defining getters (ive tried to make them public too) like
this
#foreach($rok in $datum.rok)
$rok
#end
even with getters defined, i cant access to members of inner class
#foreach($den in $datum.den)
$den
#end
this works fine, but when i try
$den.svatek or $den.isSvatek()
velocity complain that $den.svatek/isSvatek() cannot be resolved.
thx d.
Datum dtime = new Datum();
request.setAttribute("datum", dtime);
public class Datum {
class Den {
public boolean svatek=false;
public boolean vikend=false;
public String den=null;
@Override
public String toString() {
return den;
}
public Den(int den) {
this.den=Integer.toString(den);
}
public String getDen() {
return den;
}
public boolean isSvatek() {
return svatek;
}
public boolean isVikend() {
return vikend;
}
}
String[] rok=new String[3];
String[] mesic=new String[12];
Den[] den;
public Den[] getDen() {
return den;
}
public String[] getMesic() {
return mesic;
}
public String[] getRok() {
return rok;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: Velocity counters and obj access
Posted by dizzi <D....@sh.cvut.cz>.
that public keyword was the problem
thank you nathan
d.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: Velocity counters and obj access
Posted by Nathan Bubna <nb...@gmail.com>.
On 4/4/07, dizzi <D....@sh.cvut.cz> wrote:
> Hello,
> I have 2 questions
>
> 1.
> Is there way how to use 2 velocity counters in 2 nested loops?
> (i didnt test it but my colleague had problem with that)
not sure quite what you mean, but i suspect that you can't do that.
you can always define as many of your own counters as you want though:
#set( $anotherCounter = 0 )
#foreach( $foo in $foos )
#set( $anotherCounter = $anotherCounter + 1 )
....
#end
> 2.
> I have this object (below), why I cant access to rok, mesic and den
> arrays without defining getters (ive tried to make them public too) like
> this
>
> #foreach($rok in $datum.rok)
> $rok
> #end
Velocity doesn't provide access to class members, only to public
methods in public classes.
> even with getters defined, i cant access to members of inner class
> #foreach($den in $datum.den)
> $den
> #end
> this works fine, but when i try
>
> $den.svatek or $den.isSvatek()
>
> velocity complain that $den.svatek/isSvatek() cannot be resolved.
that's because the Den class isn't declared public. Velocity will
only provide access to public methods on public classes.
> thx d.
>
>
> Datum dtime = new Datum();
> request.setAttribute("datum", dtime);
>
>
>
> public class Datum {
>
> class Den {
> public boolean svatek=false;
> public boolean vikend=false;
> public String den=null;
> @Override
> public String toString() {
> return den;
> }
> public Den(int den) {
> this.den=Integer.toString(den);
> }
> public String getDen() {
> return den;
> }
> public boolean isSvatek() {
> return svatek;
> }
> public boolean isVikend() {
> return vikend;
> }
> }
>
> String[] rok=new String[3];
> String[] mesic=new String[12];
> Den[] den;
>
> public Den[] getDen() {
> return den;
> }
> public String[] getMesic() {
> return mesic;
> }
> public String[] getRok() {
> return rok;
> }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org