This question can have different answers because everyone would do it his own way. But I guess a good discussion could help me find mine.
First I will explain the scenario that I am trying to execute. Please be patient, its gonna be long (even though I have tried to keep it short). And since I am not very experienced please be kind.
I need to control access of users to various pages and functionality of the web app I am building. The web pages are grouped into various modules. And each module has different type of access options. For example, module 1 can have only read & write access options but module 2 can have read, write, modify & delete access options. I have my database built up as I need, I just need help in building up the front end for controlling it.
I have something like the following in my mind (All the variables and lists are set in an action class that was called before displaying this page):
<s:form id="form1" name="form1" action="savePermissions">
<s:select name="module" label="Select Module" list="moduleList" onchange="dojo.event.topic.publish('getPermissions');"/>
<table>
<s:iterator id="iter" value="emplList" var="emplVar">
<tr>
<td><s:textfield name="empl" value="%{<s:property value='emplName'/>}" readonly="true"/></td>
<td><s:select name="perm" value="%{<s:property value='permission'}" list="perList"/></td>
</tr>
</s:iterator>
</table>
<s:submit value="save"/>
</s:form>
Here when a module is selected from 1st drop down, a list of users and corresponding access options is listed. Now I should be able to select access option for each user and then communicate to action class with these values so that I can update the database.
But here I have 2 problems:
1.) The employee text fields do not get populated with the values.
2.) In the action class, that will be called when this form is submitted, how can I make sure that I get correct values corresponding to correct username. I mean that if ‘read’ is selected for ‘user1’ and ‘view’ for ‘user2’ on the jsp page, I should get the same in the action class.
Please advise.
Thanks!!
If something is unclear please comment.
EDIT
public class getPermissions1Action extends ActionSupport {
private List<String> moduleList;
public List<String> getModuleList() {
return moduleList;
}
public void setModuleList() {
this.moduleList = Arrays.asList("module1","module2","module3");
}
private empl emplVar;
private List<empl> emplList;
public List<empl> getEmplList() {
return emplList;
}
public void setEmplList(List<empl> emplList) {
this.emplList = emplList;
}
public empl getEmplVar() {
return emplVar;
}
public void setEmplVar(empl emplVar) {
this.emplVar = emplVar;
}
private List<String> perList;
public List<String> getPerList() {
return perList;
}
public void setPerList() {
this.perList = Arrays.asList("enter","view","edit","delete","nothing");
}
public getPermissions1Action() {
}
@Override
public String execute(){
empl var = new empl();
List<empl> empl = new ArrayList<empl>();
try{
for(int i=0;i<3;i++){
var.setEmplName("name");
var.setSelPer("view");
empl.add(var);
}
}catch(Exception e){
System.out.println(e.getMessage());
}
setEmplList(empl);
setModuleList();
setPerList();
return SUCCESS;
}
}
empl class:
public class empl {
private String emplName;
private String selPer;
public String getEmplName() {
return emplName;
}
public void setEmplName(String emplName) {
this.emplName = emplName;
}
public String getSelPer() {
return selPer;
}
public void setSelPer(String selPer) {
this.selPer = selPer;
}
}
you need to tell/show what
iteris composed of in your action class? or are you expecting that moment you select some value in your firstselectcomponent it should fill the value of iterator and the fields should come up with the corresponding iterator values?if this is the case than i am afraid it will not work as you need some short of
ajaxfunctionality like either you need to refresh that area and update its contents or you need to parse that data from yourajaxcall and need to fill the respected fields.Regarding second part.What if you need to provide more than one permission to a user,in that case though you can enable multiple select option but i would prefer a list of check-boxes in front of each user and i can select as per my options/choice.
Personaly, for providing role based access to an application i will choose some other way around e.g Spring security which has been developed taking in account all such type of use cases.
Here is working copy for you.
when iterator will iterate over the
emplListit will place the object in your caseemplon top of value stack and we can directly access its propertiesFYI:Class name should always be start from capital letter as per naming convention
And in Action class there are lot is problems
Action name
getPermissions1Actionshould always start with capital letter (GetPermissions1Action) though get/set should be used for methods and not for class nameand i am not sure why you defining Action Constructor