JSP Code
<rich:pickList id="pickListId" valueChangeListener="#{rolePermissionsBean.selectionChanged}" label="source List" title="pickList"
immediate="true"
value="#{rolePermissionsBean.selectedModuleList}" showButtonsLabel="false" listsHeight="150; width:239px;">
<a4j:support event="picklistChanged" ajaxSingle="true" actionListener="#{rolePermissionsBean.listChanged}" >
</a4j:support>
<f:selectItems value="#{rolePermissionsBean.sourceModuleList}"/>
</rich:pickList>
Description Here,
1 : <rich:pickList id="pickListId" valueChangeListener="#{rolePermissionsBean.selectionChanged}"
value change listener will called when there is change in the pick list in left and right panel.
2 : value="#{rolePermissionsBean.selectedModuleList}" this indicate the pre selection of data in right panel
3 : <f:selectItems value="#{rolePermissionsBean.sourceModuleList}"/> this indicates the Source list at left panel which can be move to right side .
4: <a4j:support event="picklistChanged" ajaxSingle="true" actionListener="#{rolePermissionsBean.listChanged}" > event to be called on selection.
5: Most important the Source and target (left and right)should be single list u should not define two list.
Backing Bean
private List<Object> selectedModuleList;
private List<ModuleVO> masterModuleList;
private List<RoleVO> masterRoleList;
private Map<Integer, ModuleVO> masterServiceMap;
private Map<Integer, RoleVO> masterRoleMap;
private AdminManager adminManager;
private List<SelectItem> sourceModuleList;
private int roleId = 0;
private List<SelectItem> roleNameList;
private String infoMessages;
private String infoMessageImg="display:none";
/**
* Get the infoMessages.
*
* @return the infoMessages
*/
public String getInfoMessages() {
return infoMessages;
}
/**
* Set the infoMessages to infoMessages.
*
* @param infoMessages the infoMessages to set
*/
public void setInfoMessages(String infoMessages) {
this.infoMessages = infoMessages;
}
/**
* Get the infoMessageImg.
*
* @return the infoMessageImg
*/
public String getInfoMessageImg() {
return infoMessageImg;
}
/**
* Set the infoMessageImg to infoMessageImg.
*
* @param infoMessageImg the infoMessageImg to set
*/
public void setInfoMessageImg(String infoMessageImg) {
this.infoMessageImg = infoMessageImg;
}
/**
* Get the roleNameList.
*
* @return the roleNameList
*/
public List<SelectItem> getRoleNameList() {
//initRoles();
return roleNameList;
}
/**
* Set the roleNameList to roleNameList.
*
* @param roleNameList the roleNameList to set
*/
public void setRoleNameList(List<SelectItem> roleNameList) {
this.roleNameList = roleNameList;
}
/**
* Get the masterServiceMap.
*
* @return the masterServiceMap
*/
public Map<Integer, ModuleVO> getMasterServiceMap() {
return masterServiceMap;
}
/**
* Set the masterServiceMap to masterServiceMap.
*
* @param masterServiceMap the masterServiceMap to set
*/
public void setMasterServiceMap(Map<Integer, ModuleVO> masterServiceMap) {
this.masterServiceMap = masterServiceMap;
}
/**
* Get the masterRoleMap.
*
* @return the masterRoleMap
*/
public Map<Integer, RoleVO> getMasterRoleMap() {
return masterRoleMap;
}
/**
* Set the masterRoleMap to masterRoleMap.
*
* @param masterRoleMap the masterRoleMap to set
*/
public void setMasterRoleMap(Map<Integer, RoleVO> masterRoleMap) {
this.masterRoleMap = masterRoleMap;
}
@PostConstruct
public void initSourceModule() {
try {
System.out.println("Start initSourceService");
ArgumentVO argumentVO = new ArgumentVO();
argumentVO.setAll(true);
masterModuleList = adminManager.getModuleList(argumentVO);
if (masterModuleList != null && masterModuleList.size() > 0) {
masterServiceMap = new HashMap<Integer,ModuleVO>();
sourceModuleList = new ArrayList<SelectItem>();
for (ModuleVO modulesVO : masterModuleList) {
masterServiceMap.put(modulesVO.getId(), modulesVO);
SelectItem sItem = new SelectItem(modulesVO.getId(), modulesVO.getName());
sourceModuleList.add(sItem);
}
}
System.out.println("End initSourceService");
} catch (Exception exception) {
exception.printStackTrace();
}
}
@PostConstruct
public void initRoles() {
try {
HttpSessionUtils httpSessionUtils = new HttpSessionUtils();
int branchId = (Integer)httpSessionUtils.
getAttribute(ApplicationConstants.USER_BRANCH_ID);
ArgumentVO argumentVO = new ArgumentVO();
argumentVO.setAll(false);
//argumentVO.setBranchId(branchId);
SelectItem selectItem = null;
masterRoleList = adminManager.getRoleList(argumentVO);
roleNameList = new ArrayList<SelectItem>();
if(CommonUtils.isValidObject(masterRoleList)){
masterRoleMap = new HashMap<Integer, RoleVO>();
System.out.println("Size of roles "+masterRoleList.size());
for (RoleVO role : masterRoleList) {
selectItem = new SelectItem();
selectItem.setLabel(""+role.getId());
selectItem.setValue(role.getName());
roleNameList.add(selectItem);
masterRoleMap.put(role.getId(), role);
}
} else{
System.out.println("No roles are exist");
}
System.out.println("ENd of initRoles ");
} catch (Exception exception) {
exception.printStackTrace();
}
}
@PostConstruct
public void initTargetModules() {
try {
System.out.println("Role Id in initTargetModules:" + this.roleId);
RoleVO roleVO = masterRoleMap.get(roleId);
if (roleVO != null && roleVO.getModuleIdList() != null
&& roleVO.getModuleIdList().size() > 0) {
selectedModuleList = new ArrayList<Object>();
for (Integer moduleId : roleVO.getModuleIdList()) {
System.out.println("Selected Module :"
+ moduleId);
selectedModuleList.add(moduleId);
}
System.out.println("selected Module List size is:>>>>>>"+selectedModuleList.size());
} else {
selectedModuleList = new ArrayList<Object>();
System.out.println("No data selected!");
}
System.out.println("End of initTargetModules");
} catch (Exception exception) {
exception.printStackTrace();
}
}
private String selectedInfo;
/**
* Get the selectedInfo.
*
* @return the selectedInfo
*/
public String getSelectedInfo() {
return selectedInfo;
}
/**
* Set the selectedInfo to selectedInfo.
*
* @param selectedInfo the selectedInfo to set
*/
public void setSelectedInfo(String selectedInfo) {
this.selectedInfo = selectedInfo;
}
public void selectionChanged(ValueChangeEvent evt){
try {
System.out.println("Calling Selection Changed Listener");
System.out.println("New value is:"+evt.getNewValue());
System.out.println("Old value is:"+evt.getOldValue());
Object newObj = evt.getNewValue();
if (newObj instanceof List) {
System.out.println("List Object");
List list = (List)newObj;
if (list != null && list.size() > 0) {/*
System.out.println("Size of List:" + list.size());
System.out.println("contents :" + list);
for (Object object : list) {
System.out.println("obj : " + object);
System.out.println("hash code: " + object.hashCode());
if (object instanceof ServicesVO) {
ServicesVO ss= (ServicesVO)object;
System.out.println("Service :" + ss.getName());
} else if (object instanceof Integer) {
System.out.println("Integer vo");
} else if (object instanceof String){
String st = (String)object;
System.out.println("String value: "+st);
} else {
System.out.println("Not object");
}
}
*/} else {
System.out.println("List is null!");
}
}
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Get the sourceModuleList.
*
* @return the sourceModuleList
*/
public List<SelectItem> getSourceModuleList() {
return sourceModuleList;
}
/**
* Set the sourceModuleList to sourceModuleList.
*
* @param sourceModuleList the sourceModuleList to set
*/
public void setSourceModuleList(List<SelectItem> sourceModuleList) {
this.sourceModuleList = sourceModuleList;
}
/**
* Get the selectedModuleList.
*
* @return the selectedModuleList
*/
public List<Object> getSelectedModuleList() {
return selectedModuleList;
}
/**
* Set the selectedModuleList to selectedModuleList.
*
* @param selectedModuleList the selectedModuleList to set
*/
public void setSelectedModuleList(List<Object> selectedModuleList) {
this.selectedModuleList = selectedModuleList;
}
/**
* Get the masterModuleList.
*
* @return the masterModuleList
*/
public List<ModuleVO> getMasterModuleList() {
return masterModuleList;
}
/**
* Set the masterModuleList to masterModuleList.
*
* @param masterModuleList the masterModuleList to set
*/
public void setMasterModuleList(List<ModuleVO> masterModuleList) {
this.masterModuleList = masterModuleList;
}
/**
* Get the masterRoleList.
*
* @return the masterRoleList
*/
public List<RoleVO> getMasterRoleList() {
return masterRoleList;
}
/**
* Set the masterRoleList to masterRoleList.
*
* @param masterRoleList the masterRoleList to set
*/
public void setMasterRoleList(List<RoleVO> masterRoleList) {
this.masterRoleList = masterRoleList;
}
/**
* Get the adminManager.
*
* @return the adminManager
*/
public AdminManager getAdminManager() {
return adminManager;
}
/**
* Set the adminManager to adminManager.
*
* @param adminManager the adminManager to set
*/
public void setAdminManager(AdminManager adminManager) {
this.adminManager = adminManager;
}
/**
* Method to capture the valueChange Event for counters
* @param event
* An instance of <tt>javax.faces.event.ValueChangeEvent</tt>
*/
public void valueChangeListener(javax.faces.event.ValueChangeEvent event){
System.out.println("Inside of value change evnet interface");
try {
System.out.println("valueChangeListener():");
//String counterIdStr = (String) event.getNewValue();
int roleId = 0;
UIComboBox comboBox = (UIComboBox)event.getComponent();
if ( (event.getComponent().getId().equalsIgnoreCase("roleComboId")
) && CommonUtils.isValidObject(comboBox.getValue()) ) {
roleId = Integer.parseInt(getValue(roleNameList,
""+comboBox.getValue()));
}
System.out.println("Role ID : " + roleId);
selectedModuleList = null;
sourceModuleList = null;
this.roleId = roleId;
initTargetModules();
initSourceModule();
}catch(Exception ex){
ex.printStackTrace();
}
}
public void actionListener(ActionEvent event){
System.out.println("Inside of action Listener event");
try {
}catch(Exception ex){
ex.printStackTrace();
}
}
public void listChanged(ActionEvent actionEvent) {
try {
System.out.println("List changes Listener event");
int sid = 0;
HtmlPickList pickList = (HtmlPickList)actionEvent.getComponent();
if ( (actionEvent.getComponent().getId().equalsIgnoreCase("pickListId")
) && CommonUtils.isValidObject(pickList.getValue()) ) {
sid = Integer.parseInt(getValue(sourceModuleList,
""+pickList.getValue()));
}
System.out.println("pickList Item ID : " + sid);
// actionEvent.get
} catch (Exception exception) {
exception.printStackTrace();
}
}
public String getValue(List<SelectItem> itemlist,String label){
String id ="";
try{
if ( CommonUtils.isValidObject(itemlist)
&& StringUtils.isValidString(label)
&& itemlist.size() >0 ){
if(CommonUtils.isValidObject(itemlist)){
for(SelectItem item : itemlist){
if(item.getValue().equals(label)){
id = item.getLabel();
break;
}
}
}
}
}catch(Exception ex){
ex.printStackTrace();
}
return id;
}
public boolean saveSelectedRoleModuleList() {
RoleVO roleVO = null;
List<Integer> moduleIdArray = null;
boolean isAddEdit = false;
try {
System.out.println(" Inside saveSelectedRoleModuleList");
if (this.roleId > 0) {
roleVO = masterRoleMap.get(this.roleId);
roleVO.setModuleIdList(null);
roleVO.setModuleList(null);
if (CommonUtils.isValidObject(selectedModuleList) && selectedModuleList.size()>0 ) {
moduleIdArray = new ArrayList<Integer>();
//int count = 0;
System.out.println("Size of Selected Module:" + selectedModuleList.size());
for (Object modulesVO : selectedModuleList) {
System.out.println("Final ID :" + modulesVO);
moduleIdArray.add(Integer.parseInt(modulesVO.toString()));
}
} else {
System.out.println("selected Role Module list is null");
}
roleVO.setModuleIdList(moduleIdArray);
isAddEdit = adminManager.saveOrUpdateRoles(roleVO);
MessageProperties properties = MessageProperties.getInstance();
if(isAddEdit) {
infoMessages = properties.getValueByKey(
MessageConstants.ADMIN_ROLEPERMISSION_ADD_SUCCESS);
infoMessageImg = "../images/successicon.png";
} else {
infoMessages = properties.getValueByKey(
MessageConstants.ADMIN_ROLEPERMISSION_ADD_FAILURE);
infoMessageImg = "../images/erroricon.png";
}
}
//sourceServiceList.clear();
this.roleId = 0;
initRoles();
initTargetModules();
initSourceModule();
FacesContext.getCurrentInstance().getExternalContext()
.redirect(URLConstants.MANAGE_ROLE_PERMISSION_PAGE);
} catch (ServiceException exception) {
exception.printStackTrace();
} catch (Exception e) {
// TODO: handle exception
}
return isAddEdit;
}
Where : adminManager Object is to get the Data list for Module and Role List from database.
<rich:pickList id="pickListId" valueChangeListener="#{rolePermissionsBean.selectionChanged}" label="source List" title="pickList"
immediate="true"
value="#{rolePermissionsBean.selectedModuleList}" showButtonsLabel="false" listsHeight="150; width:239px;">
<a4j:support event="picklistChanged" ajaxSingle="true" actionListener="#{rolePermissionsBean.listChanged}" >
</a4j:support>
<f:selectItems value="#{rolePermissionsBean.sourceModuleList}"/>
</rich:pickList>
Description Here,
1 : <rich:pickList id="pickListId" valueChangeListener="#{rolePermissionsBean.selectionChanged}"
value change listener will called when there is change in the pick list in left and right panel.
2 : value="#{rolePermissionsBean.selectedModuleList}" this indicate the pre selection of data in right panel
3 : <f:selectItems value="#{rolePermissionsBean.sourceModuleList}"/> this indicates the Source list at left panel which can be move to right side .
4: <a4j:support event="picklistChanged" ajaxSingle="true" actionListener="#{rolePermissionsBean.listChanged}" > event to be called on selection.
5: Most important the Source and target (left and right)should be single list u should not define two list.
Backing Bean
private List<Object> selectedModuleList;
private List<ModuleVO> masterModuleList;
private List<RoleVO> masterRoleList;
private Map<Integer, ModuleVO> masterServiceMap;
private Map<Integer, RoleVO> masterRoleMap;
private AdminManager adminManager;
private List<SelectItem> sourceModuleList;
private int roleId = 0;
private List<SelectItem> roleNameList;
private String infoMessages;
private String infoMessageImg="display:none";
/**
* Get the infoMessages.
*
* @return the infoMessages
*/
public String getInfoMessages() {
return infoMessages;
}
/**
* Set the infoMessages to infoMessages.
*
* @param infoMessages the infoMessages to set
*/
public void setInfoMessages(String infoMessages) {
this.infoMessages = infoMessages;
}
/**
* Get the infoMessageImg.
*
* @return the infoMessageImg
*/
public String getInfoMessageImg() {
return infoMessageImg;
}
/**
* Set the infoMessageImg to infoMessageImg.
*
* @param infoMessageImg the infoMessageImg to set
*/
public void setInfoMessageImg(String infoMessageImg) {
this.infoMessageImg = infoMessageImg;
}
/**
* Get the roleNameList.
*
* @return the roleNameList
*/
public List<SelectItem> getRoleNameList() {
//initRoles();
return roleNameList;
}
/**
* Set the roleNameList to roleNameList.
*
* @param roleNameList the roleNameList to set
*/
public void setRoleNameList(List<SelectItem> roleNameList) {
this.roleNameList = roleNameList;
}
/**
* Get the masterServiceMap.
*
* @return the masterServiceMap
*/
public Map<Integer, ModuleVO> getMasterServiceMap() {
return masterServiceMap;
}
/**
* Set the masterServiceMap to masterServiceMap.
*
* @param masterServiceMap the masterServiceMap to set
*/
public void setMasterServiceMap(Map<Integer, ModuleVO> masterServiceMap) {
this.masterServiceMap = masterServiceMap;
}
/**
* Get the masterRoleMap.
*
* @return the masterRoleMap
*/
public Map<Integer, RoleVO> getMasterRoleMap() {
return masterRoleMap;
}
/**
* Set the masterRoleMap to masterRoleMap.
*
* @param masterRoleMap the masterRoleMap to set
*/
public void setMasterRoleMap(Map<Integer, RoleVO> masterRoleMap) {
this.masterRoleMap = masterRoleMap;
}
@PostConstruct
public void initSourceModule() {
try {
System.out.println("Start initSourceService");
ArgumentVO argumentVO = new ArgumentVO();
argumentVO.setAll(true);
masterModuleList = adminManager.getModuleList(argumentVO);
if (masterModuleList != null && masterModuleList.size() > 0) {
masterServiceMap = new HashMap<Integer,ModuleVO>();
sourceModuleList = new ArrayList<SelectItem>();
for (ModuleVO modulesVO : masterModuleList) {
masterServiceMap.put(modulesVO.getId(), modulesVO);
SelectItem sItem = new SelectItem(modulesVO.getId(), modulesVO.getName());
sourceModuleList.add(sItem);
}
}
System.out.println("End initSourceService");
} catch (Exception exception) {
exception.printStackTrace();
}
}
@PostConstruct
public void initRoles() {
try {
HttpSessionUtils httpSessionUtils = new HttpSessionUtils();
int branchId = (Integer)httpSessionUtils.
getAttribute(ApplicationConstants.USER_BRANCH_ID);
ArgumentVO argumentVO = new ArgumentVO();
argumentVO.setAll(false);
//argumentVO.setBranchId(branchId);
SelectItem selectItem = null;
masterRoleList = adminManager.getRoleList(argumentVO);
roleNameList = new ArrayList<SelectItem>();
if(CommonUtils.isValidObject(masterRoleList)){
masterRoleMap = new HashMap<Integer, RoleVO>();
System.out.println("Size of roles "+masterRoleList.size());
for (RoleVO role : masterRoleList) {
selectItem = new SelectItem();
selectItem.setLabel(""+role.getId());
selectItem.setValue(role.getName());
roleNameList.add(selectItem);
masterRoleMap.put(role.getId(), role);
}
} else{
System.out.println("No roles are exist");
}
System.out.println("ENd of initRoles ");
} catch (Exception exception) {
exception.printStackTrace();
}
}
@PostConstruct
public void initTargetModules() {
try {
System.out.println("Role Id in initTargetModules:" + this.roleId);
RoleVO roleVO = masterRoleMap.get(roleId);
if (roleVO != null && roleVO.getModuleIdList() != null
&& roleVO.getModuleIdList().size() > 0) {
selectedModuleList = new ArrayList<Object>();
for (Integer moduleId : roleVO.getModuleIdList()) {
System.out.println("Selected Module :"
+ moduleId);
selectedModuleList.add(moduleId);
}
System.out.println("selected Module List size is:>>>>>>"+selectedModuleList.size());
} else {
selectedModuleList = new ArrayList<Object>();
System.out.println("No data selected!");
}
System.out.println("End of initTargetModules");
} catch (Exception exception) {
exception.printStackTrace();
}
}
private String selectedInfo;
/**
* Get the selectedInfo.
*
* @return the selectedInfo
*/
public String getSelectedInfo() {
return selectedInfo;
}
/**
* Set the selectedInfo to selectedInfo.
*
* @param selectedInfo the selectedInfo to set
*/
public void setSelectedInfo(String selectedInfo) {
this.selectedInfo = selectedInfo;
}
public void selectionChanged(ValueChangeEvent evt){
try {
System.out.println("Calling Selection Changed Listener");
System.out.println("New value is:"+evt.getNewValue());
System.out.println("Old value is:"+evt.getOldValue());
Object newObj = evt.getNewValue();
if (newObj instanceof List) {
System.out.println("List Object");
List list = (List)newObj;
if (list != null && list.size() > 0) {/*
System.out.println("Size of List:" + list.size());
System.out.println("contents :" + list);
for (Object object : list) {
System.out.println("obj : " + object);
System.out.println("hash code: " + object.hashCode());
if (object instanceof ServicesVO) {
ServicesVO ss= (ServicesVO)object;
System.out.println("Service :" + ss.getName());
} else if (object instanceof Integer) {
System.out.println("Integer vo");
} else if (object instanceof String){
String st = (String)object;
System.out.println("String value: "+st);
} else {
System.out.println("Not object");
}
}
*/} else {
System.out.println("List is null!");
}
}
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Get the sourceModuleList.
*
* @return the sourceModuleList
*/
public List<SelectItem> getSourceModuleList() {
return sourceModuleList;
}
/**
* Set the sourceModuleList to sourceModuleList.
*
* @param sourceModuleList the sourceModuleList to set
*/
public void setSourceModuleList(List<SelectItem> sourceModuleList) {
this.sourceModuleList = sourceModuleList;
}
/**
* Get the selectedModuleList.
*
* @return the selectedModuleList
*/
public List<Object> getSelectedModuleList() {
return selectedModuleList;
}
/**
* Set the selectedModuleList to selectedModuleList.
*
* @param selectedModuleList the selectedModuleList to set
*/
public void setSelectedModuleList(List<Object> selectedModuleList) {
this.selectedModuleList = selectedModuleList;
}
/**
* Get the masterModuleList.
*
* @return the masterModuleList
*/
public List<ModuleVO> getMasterModuleList() {
return masterModuleList;
}
/**
* Set the masterModuleList to masterModuleList.
*
* @param masterModuleList the masterModuleList to set
*/
public void setMasterModuleList(List<ModuleVO> masterModuleList) {
this.masterModuleList = masterModuleList;
}
/**
* Get the masterRoleList.
*
* @return the masterRoleList
*/
public List<RoleVO> getMasterRoleList() {
return masterRoleList;
}
/**
* Set the masterRoleList to masterRoleList.
*
* @param masterRoleList the masterRoleList to set
*/
public void setMasterRoleList(List<RoleVO> masterRoleList) {
this.masterRoleList = masterRoleList;
}
/**
* Get the adminManager.
*
* @return the adminManager
*/
public AdminManager getAdminManager() {
return adminManager;
}
/**
* Set the adminManager to adminManager.
*
* @param adminManager the adminManager to set
*/
public void setAdminManager(AdminManager adminManager) {
this.adminManager = adminManager;
}
/**
* Method to capture the valueChange Event for counters
* @param event
* An instance of <tt>javax.faces.event.ValueChangeEvent</tt>
*/
public void valueChangeListener(javax.faces.event.ValueChangeEvent event){
System.out.println("Inside of value change evnet interface");
try {
System.out.println("valueChangeListener():");
//String counterIdStr = (String) event.getNewValue();
int roleId = 0;
UIComboBox comboBox = (UIComboBox)event.getComponent();
if ( (event.getComponent().getId().equalsIgnoreCase("roleComboId")
) && CommonUtils.isValidObject(comboBox.getValue()) ) {
roleId = Integer.parseInt(getValue(roleNameList,
""+comboBox.getValue()));
}
System.out.println("Role ID : " + roleId);
selectedModuleList = null;
sourceModuleList = null;
this.roleId = roleId;
initTargetModules();
initSourceModule();
}catch(Exception ex){
ex.printStackTrace();
}
}
public void actionListener(ActionEvent event){
System.out.println("Inside of action Listener event");
try {
}catch(Exception ex){
ex.printStackTrace();
}
}
public void listChanged(ActionEvent actionEvent) {
try {
System.out.println("List changes Listener event");
int sid = 0;
HtmlPickList pickList = (HtmlPickList)actionEvent.getComponent();
if ( (actionEvent.getComponent().getId().equalsIgnoreCase("pickListId")
) && CommonUtils.isValidObject(pickList.getValue()) ) {
sid = Integer.parseInt(getValue(sourceModuleList,
""+pickList.getValue()));
}
System.out.println("pickList Item ID : " + sid);
// actionEvent.get
} catch (Exception exception) {
exception.printStackTrace();
}
}
public String getValue(List<SelectItem> itemlist,String label){
String id ="";
try{
if ( CommonUtils.isValidObject(itemlist)
&& StringUtils.isValidString(label)
&& itemlist.size() >0 ){
if(CommonUtils.isValidObject(itemlist)){
for(SelectItem item : itemlist){
if(item.getValue().equals(label)){
id = item.getLabel();
break;
}
}
}
}
}catch(Exception ex){
ex.printStackTrace();
}
return id;
}
public boolean saveSelectedRoleModuleList() {
RoleVO roleVO = null;
List<Integer> moduleIdArray = null;
boolean isAddEdit = false;
try {
System.out.println(" Inside saveSelectedRoleModuleList");
if (this.roleId > 0) {
roleVO = masterRoleMap.get(this.roleId);
roleVO.setModuleIdList(null);
roleVO.setModuleList(null);
if (CommonUtils.isValidObject(selectedModuleList) && selectedModuleList.size()>0 ) {
moduleIdArray = new ArrayList<Integer>();
//int count = 0;
System.out.println("Size of Selected Module:" + selectedModuleList.size());
for (Object modulesVO : selectedModuleList) {
System.out.println("Final ID :" + modulesVO);
moduleIdArray.add(Integer.parseInt(modulesVO.toString()));
}
} else {
System.out.println("selected Role Module list is null");
}
roleVO.setModuleIdList(moduleIdArray);
isAddEdit = adminManager.saveOrUpdateRoles(roleVO);
MessageProperties properties = MessageProperties.getInstance();
if(isAddEdit) {
infoMessages = properties.getValueByKey(
MessageConstants.ADMIN_ROLEPERMISSION_ADD_SUCCESS);
infoMessageImg = "../images/successicon.png";
} else {
infoMessages = properties.getValueByKey(
MessageConstants.ADMIN_ROLEPERMISSION_ADD_FAILURE);
infoMessageImg = "../images/erroricon.png";
}
}
//sourceServiceList.clear();
this.roleId = 0;
initRoles();
initTargetModules();
initSourceModule();
FacesContext.getCurrentInstance().getExternalContext()
.redirect(URLConstants.MANAGE_ROLE_PERMISSION_PAGE);
} catch (ServiceException exception) {
exception.printStackTrace();
} catch (Exception e) {
// TODO: handle exception
}
return isAddEdit;
}
Where : adminManager Object is to get the Data list for Module and Role List from database.