0

1st problem : i have a jsp in which there are two tabs ,for the second tab i have included the struts include tag. When i open the second tab and performs the action the second tab form values are not passing to the action.

2nd problem : in the select tag i have populate the list but it is coming as prepopulated means all the options are coming as selected="selected"

main jsp in which tabs are made

<!-- admin first tab starts here -->
    <form action="saveRolesAndPermissions" method="post">
    <table align="center">
        <tr>
            <td ><s:text name="FTID" ></s:text></td>
            <td ><s:textfield id="FTID" name="ft_id">
                </s:textfield></td>
                <td><input type="button" value="validate" onclick="userPresent()"></td>
        </tr>

    </table>

            <table>
                <tr>
                    <td>First Name</td>
                    <td><input id="first_name" type="text" readonly onkeydown="return false"></td>
                    <td>Last Name</td>
                    <td><input id="last_name" 
                        type="text" readonly onkeydown="return false"></td>
                    <td>Email-Id</td>
                    <td><input id="mail_id" type="text"
                        readonly onkeydown="return false"></td>
                </tr>
            </table>


            <table align="center">
        <tr>
            <td><s:text name="ROLES"></s:text></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td><s:text name="Available Roles"></s:text></td>
            <td></td>
            <td><s:text name="Assigned Roles"></s:text></td>
        </tr>
        <tr>
            <td><s:select id="roles" name="availableRole"
                    multiple="true" list="availableRole"></s:select></td>
            <td><input type="button" value="&gt" onclick="move_list_items('roles','assignedroles');"/><input
                type="button" value="&lt" onclick="move_list_items('assignedroles','roles');"/></td>

            <td><s:select id="assignedroles" name="assignedRole" multiple="true"
                    list="{}" >
                    </s:select></td>
        </tr>
    </table>
    <br /> <br /> <br />
    <table>
        <tr>
            <td><s:text name="Permissions"></s:text></td>
            <td></td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td><s:text
                    name="Available Permissions"></s:text></td>
            <td></td>
            <td><s:text name="Assigned Permissions"></s:text></td>
        </tr>
        <tr>
            <td><s:select id="permissions" multiple="true"
                    name="availablePermission" list="availablePermission" headerValue=""></s:select></td>
            <td><input
                type="button" value="&gt" onclick="move_list_items('permissions','assignedpermissions');"/><br /> <input type="button" 
                value="&lt" onclick="move_list_items('assignedpermissions','permissions');" /></td>
            <td><s:select id="assignedpermissions" multiple="true" name="assignedPermission"
                    list="{}" ></s:select></td>
        </tr>
    </table>
    <br /> <br />

            <table align="center" style="width: 25%;">
                <tr>
                    <td><s:if test="hasActionMessages()">
                            <div class="welcome" style="list-style:none">
                                <s:actionmessage />
                            </div>
                        </s:if></td>
                </tr>
            </table> 


            <table>
        <tr>
            <td><s:submit 
                    value="save"onclick="saveRole();return false;"></s:submit></td>
            <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" name="close"
                value="close" /></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
        </tr>
    </table>
    </form>


<!-- second tab for modify roles -->
<div id="content02" class="content" >
<s:include value="../asp/aspAdminModify.jsp"></s:include>
</div>
<!-- /second tab ends here -->

included jsp

<form action="grantedRolesAndPermissions" method="post">
    <table>
        <tr>
            <td><s:text name="FTID" ></s:text></td>
            <td><s:textfield id="modify_FTID" name="modifyftid">
                </s:textfield></td>
                <td><s:submit 
                    value="search" onclick="search();return false;"></s:submit>
                </td>
        </tr>

    </table>

Bean for the first tab

private String ft_id;
    private ArrayList<String> availableRole;
    private ArrayList<String> availablePermission;
    private ArrayList<String> assignedRole;
    private ArrayList<String> assignedPermission;
//getters and setters

Action for the first tab

public class ASPadmin extends ActionSupport implements ServletRequestAware, ModelDriven<ASPAdminBean>{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private AdminASPService aspService = new AdminASPService();
    private HttpServletRequest request = ServletActionContext.getRequest();
    private HttpServletResponse response = ServletActionContext.getResponse();
    public CMTUser cmtuser;
    private ASPAdminBean aspAdminBean = new ASPAdminBean();


    //getters and setters



    public String populateRolesAndPermissions() throws Exception
    {
        /*aspAdminBean=new ASPAdminBean();*/
        aspAdminBean.setAvailableRole(aspService.getRolesList());
        aspAdminBean.setAvailablePermission(aspService.getPermissionsList());
        return SUCCESS;

    }

    public String saveRolesAndPermissions() throws Exception
    {

        User user = CMTUser.getUser(request);
        String login = user.getUserId();
        String[] temp = login.split("\\.");
        String abcfinal = temp[0].substring(0, 1).toUpperCase()
                + temp[0].substring(1);
        String deffinal = temp[1].substring(0, 1).toUpperCase()
                + temp[1].substring(1);
        String name = abcfinal + " " + deffinal;
        System.out.println("name ==============>" + name);
        String id = aspService.saveRolesPermissions(aspAdminBean,name);
        System.out.println("id=======>"+id);
        if("Y".equals(id)){
            addActionMessage("Record Inserted Successfully");
            populateRolesAndPermissions();
            return SUCCESS; 
        }
        else{
            return ERROR;
        }

    }

    @Override
    public String execute() throws Exception {
        String url = request.getRequestURL().toString();
        String[] actionArray = url.split("/");
        String event = null;
        String forward = SUCCESS;
        for (int i = 0; i < actionArray.length; i++) {
            event = actionArray[i];

        }
        System.err.println(event);
        try {


            if (event.equals("aspAdmin.action")) {

                    populateRolesAndPermissions();

            }
        }catch (Exception e) {
            e.printStackTrace();
        }
        return SUCCESS;
    }

    @Override
    public void setServletRequest(HttpServletRequest req) {
        this.request = req;

    }

    @Override
    public ASPAdminBean getModel() {
        // TODO Auto-generated method stub
        return aspAdminBean;
    }

}

bean for second tab

public class ASPAdminModifyBean {
    private String modifyftid;
    private  String  aspmodifyassignedRole;
    private String  aspmodifyassignedPermission;
    private String createddate;
    private String createdby;
    private String updateddate;
    private String updatedby;
    private String username;
    private ArrayList<String>  modifyavailableRole;
    private ArrayList<String>  modifyavailablePermission;
    private  ArrayList<String>  modifyassignedRole;
    private ArrayList<String>  modifyassignedPermission;
//getters and setters   

action for the second tab

public class ASPadminModify extends ActionSupport implements ServletRequestAware, ModelDriven<ASPAdminModifyBean> {



    private AdminASPService aspService = new AdminASPService();
    private GetRolePermissionListInt[] roleVO;
    private HttpServletRequest request = ServletActionContext.getRequest();
    private HttpServletResponse response = ServletActionContext.getResponse();
    private ASPAdminModifyBean modify = new ASPAdminModifyBean();
    GetRolePermissionListInt role;

    //getters and setters for the above


    public String grantRolesPermissions(){
        System.out.println("enter the grant roles and permissions");
        String tab2="modify";
        boolean id;
        HttpServletRequest request=getRequest();
        HttpSession session=request.getSession();
        session.setAttribute("tabs",tab2 );
        role=aspService.getGrantedRolesAndPermissions(modify);
        System.out.println("assigned roles===================>"+role.getAssignedRoles());
        modify.setAspmodifyassignedRole(role.getAssignedRoles());
        modify.setAspmodifyassignedPermission(role.getAssignedPermissions());
        modify.setCreatedby(role.getCreatedBy());
        modify.setCreateddate(role.getCreatedDate());
        modify.setUpdatedby(role.getUpdatedBy());
        modify.setUpdateddate(role.getUpdatedDate());
        modify.setUsername(role.getUserName());
        modify.setModifyftid(role.getFtid());
        System.out.println("assigned permissions==============>"+role.getAssignedPermissions());
        System.out.println("updated by=================>"+role.getUpdatedBy());
        System.out.println("update date=================>"+role.getUpdatedDate());
        System.out.println("created by===================>"+role.getCreatedBy());
        System.out.println("created date=====================>"+role.getCreatedDate());
        System.out.println("ftid=============================>"+role.getFtid());
        System.out.println("user name===========================>"+role.getUserName());
        System.out.println("ftid=============>"+role.getFtid());
        if(role!=null){
            return SUCCESS;
        }else{
            return ERROR;
        }

    }


    @Override
    public void setServletRequest(HttpServletRequest arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public ASPAdminModifyBean getModel() {
        // TODO Auto-generated method stub
        return modify;
    }

}
Harish Gupta
  • 364
  • 2
  • 8
  • 23
  • There is really too much code up there. Please, take your time to clean it up from the noise (all the useless elements, eg. before and after the forms, or the tableheaders, and so on), keeping here only the parts relevant to the problem(s) – Andrea Ligios Apr 23 '14 at 16:49
  • @AndreaLigios i have cleaned – Harish Gupta Apr 23 '14 at 16:56
  • Good. You could clean it up more by removing all the style="", align="",class="",
    and ... then please, add your relevant Action code (eg, the definition of availableRole, and its initialization)
    – Andrea Ligios Apr 23 '14 at 17:07
  • This is a pretty strong argument for using CSS and non-intrusive JavaScript :/ Also note that fields that don't require a body don't actually need an explicit end tag, just use the self-closing version. I don't see an include tag anywhere, but it's really difficult to read that JSP anyway. – Dave Newton Apr 23 '14 at 17:08
  • @AndreaLigios i have updated my code can u please help me – Harish Gupta Apr 23 '14 at 17:57
  • @DaveNewton see the main page scroll down – Harish Gupta Apr 23 '14 at 17:57

1 Answers1

0

Well, the code is grown again :)

Start by :

  • changing your ArrayList declarations to List (in both beans, and regenerate getters and setters);
  • changing the way you get the Request, the Response and the Session, by using Struts2 Aware s interfaces (and their setters, with code inside)

Then if it still doesn't work, describe a little better what do you mean by "values are not passing to Action", and consider posting your interceptor stack config.

Hope that helps...

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243