John,
The #foreach with a List class works fine. The following method of setting
up a default value for a Role where no selection currently exists fixed my
problem. I use this technique all over the place because it is so
convienient.
In my pull tool
public List getAllRoles() throws Exception
{
Criteria crit = new Criteria();
List
roles=org.apache.turbine.om.security.peer.RolePeer.doSelect(crit);
return roles;
}
Then in my template I have:
## Set up entries in the roleType drop-down
#set ( $userRoles = $entitylist.getAllRoles() )
#if (!$selectedRole && ($userRoles.size()>0) )
#set ( $selectedRole=$userRoles.get(0) )
#end
So if $selectedRole exists in the Context from a previous look at this
screen all is fine, if I have not been to the screen before then it selects
a value for me. I also use the $userRoles in a #foreach to populate a
'select' on the same screen, thus:
#rwLabelCell ("Role")
<td width="$ui.screenWidgetWidth" >
<select name="selectedRoleType">
#foreach ($role in $userRoles)
#if ($role.getName() ==
$selectedRole.getName())
<option
selected>$!role.getName()</option>
#else
<option>$!role.getName()</option>
#end
#end
</select>
</td>
Being fairly new to Java I was a bit unsure about what methods I could use
with a [] in VTL so that lead me to use a List class.
David
-----Original Message-----
From: jmcnally [mailto:jmcnally]On Behalf Of John McNally
Sent: 02 November 2001 16:48
To: Turbine Users List
Subject: Re: More struggles with TurbineSecurity framework
Try creating the List as an ArrayList and copying the elements into it
using a loop. I assume this will work as you say you are not having
problems with other List types.
Also does a #foreach using the List created by Arrays.asList work? I am
using this function and have not noticed a problem, but off the top of
my head i do not know that i ever call size() from a template on the
resulting list.
If the problem appears to be in the object created by Arrays.asList, I
would mention it on the velocity list. Not sure whether this would be a
problem with velocity, but it could save some other users the trouble of
getting the same error.
john mcnally
David Wynter wrote:
>
> Hello,
>
> I have posted 4 times previously to this list and only once got a response
> and that was a friend I was working on a project with. So I must be doing
> something completely off the wall to get no help from the people on the
list
> who 'know'.
>
> After spending hours trying different methods of saving a User with a Role
> and Group I achieved that (my last post). Now I wish to update the Role in
> the same screen. I use a pull tool for all entitylist population on
screen.
> One of the methods is
>
> /**
> * Get all role from the turbine table
> */
> public List getAllRoles() throws Exception
> {
> Role[] roles=TurbineSecurity.getAllRoles().getRolesArray();
> return Arrays.asList(roles);
> }
>
> I also tried
>
> /**
> * Get all role from the turbine table
> */
> public List getAllRoles() throws Exception
> {
> Criteria crit = new Criteria();
> Role[] roles=TurbineSecurity.getRoles(crit).getRolesArray();
> return Arrays.asList(roles);
> }
>
> In the template I have:
>
> ## Set up entries in the roleType drop-down
> #set ( $userRoles = $entitylist.getAllRoles() )
> #if (!$selectedRole && ($userRoles.size()>0))
> #set ( $selectedRole=$userRoles.get(0) )
> #end
>
> I note that I get this exception when ever I access this template.
>
> [java] ASTMethod.execute() : exception invoking method 'size' in
class
> java
> .util.Arrays$ArrayList : java.lang.IllegalAccessException
>
> If I put $selectedRole.getName() in the BODY of the HTML it never has a
> value displayed. I also tried
> putting $userRoles.size() in the BODY of the HTML and it never displays
> either. These are the roles I expect to see
>
> +---------+---------------+------------+
> | ROLE_ID | ROLE_NAME | OBJECTDATA |
> +---------+---------------+------------+
> | 1 | turbine_root | NULL |
> | 100 | Administrator | NULL |
> | 101 | Message User | NULL |
> +---------+---------------+------------+
>
> I have no problems with non TurbineSecurity related entities. Any idea
about
> what is going on here?
>
> Thanks
>
> David Wynter
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>