473,387 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

add remove between two lists with struts??

2
Hi,


I am using struts 1.2
I want to have a jsp page that has :

a list of users(populated from a database) when you click in a user it show two
other lists :
Roles assigned
Roles notassigned

so we can remove and assign roles to the current user

thanks, your help is appreciated.

Kamal.
Oct 10 '08 #1
1 1579
chaarmann
785 Expert 512MB
Rather than having 2 lists with roles assigned or unasigned, you should have only one list for a user with all roles. For each role you should have a boolean marker that marks whether this role is assigned to the user or not.
So to answer your question, you can just assign or unassign a role by just toggling the boolean between true and false.
But don't confuse the internal structure of the data with the view: the view can still show 2 lists.
For printing the first list(assigned roles), you go through the internal list and print all roles where the boolean is true. For printing the second list (unassigned roles) you go through the same list a second time, but print all roles where the boolean is false.

In struts, you can use the <logic:iterator> tag to print each list.

I bet you already have a preferred data structure (three dimensional array, hashmap of users and roles, classes with subclasses etc.)

But in case you don't have more than 64 roles, one thing to mention is a data structure that is quickest and smalles in memory: bitsets.
Expand|Select|Wrap|Line Numbers
  1. public static final long ROLE1=1;
  2. public static final long ROLE2=2;
  3. public static final long ROLE3=4;
  4. public static final long ROLE4=8;
  5. public static final long ROLE5=16;
  6. ...
  7. // set roles
  8. long rightsUser1= ROLE1 | ROLE3; // Only role 1 and 3 are assigned
  9. long rightsUser2= ROLE4; // Only role 4 is assigned
  10. ...
  11. // add roles
  12. rightsUser2 |= ROLE5; // role 5 is now added (assigned), no matter if it was assigned before or not.
  13. ...
  14. // test roles
  15. if ((rightsUser1 & ROLE2)  != 0) out.println("User 1 has role 2 assigned");
  16. ...
  17. // toggle role assignment
  18. rightsUser2 ^= ROLE5;
Oct 10 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Cedric | last post by:
Hello, I'm developping my first Struts application. I've got this error: Cannot find message resources under key org.apache.struts.action.MESSAGE web.xml <servlet>...
4
by: nc | last post by:
My iterator can find my collection when my Action class calls my jsp directly, however when my Action class calls an html file that is set up with IFrames (one of which is loading that same jsp), I...
3
by: Sharon | last post by:
Hi guys , What is the apache struts equivalent in the .net world ? (if any ..) Thank you Sharon
1
by: nithiya sri | last post by:
i am new to struts.I try running struts application in Eclipse with the tomcat plug in .. it shows the following error:; please help me in this... SEVERE: Error loading WebappClassLoader ...
3
by: shanmukhi | last post by:
hi all, i got a problem with struts. iam unable to find it. i have written an action class, form bean class and a jsp page on submitting form, request is going to action class but it is not...
1
by: shrik | last post by:
hi everybody. I have following problem. There are two pages. index.jsp and main.jsp in my application Index.jsp contains logging interface in . It submits password and userid to loginform bean. ...
8
by: ajos | last post by:
hi frnds, the situation is im developing a web application in struts-- my specifications-eclipse3.2.2,struts1.1,tomcat5.5.23 mysql5.0 db. the scenario-i have a jsp page which adds the...
1
by: NamelessNumberheadMan | last post by:
I can't seem to get Struts 2 validations to work. I have been converting from Strust 1 to Struts 2. So far I've refactored all the code (for this particular module) on the back end, rewrote the jsp...
12
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I am a newbie to Struts and JSP...I have been working on the code below for 5 hours now..I googled a lot but couldn't get much help so finally I am here.. Hoping of getting my problem solved. Please...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.