tags:

views:

7284

answers:

1

I am working on struts2. I have 3 checkbox in my jsp page (say a.jsp) like

<s:checkbox name="authority" fieldValue="ORIGINATOR"/>
<s:checkbox name="authority" fieldValue="EVALUATOR"/>
<s:checkbox name="authority" fieldValue="EXECUTOR"/>

Suppose I checked first two and when I fetched the value of “authority” in my action class in gives “ORIGINATOR, EVALUATOR”. Now in another jsp page (say b.jsp) I have all these checkbox as it is and I need those two checkbox should be checked here what I have checked in my previous jsp page (a.jsp).

Thanks in advance.

+1  A: 

You can set the "value" property to "true" to make this check box checked. Understood? For example, you can write the code like this: < s:checkbox name="authority" fieldValue="ORIGINATOR" value="%{var}" > while the "var" is in the server side.

Well, this is an example:

the a.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <s:form action="Handler" method="post">
     <s:checkbox name="authority" fieldValue="ORIGINATOR" label="ORIGINATOR"/>
     <s:checkbox name="authority" fieldValue="EVALUATOR" label="EVALUATOR"/>
     <s:checkbox name="authority" fieldValue="EXECUTOR" label="EXECUTOR"/>
     <s:submit label="Submit"></s:submit>
    </s:form>
</body>
</html>

b.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <s:form>
     <s:checkbox name="authority" fieldValue="ORIGINATOR" value="%{isORIGINATORSet}" label="ORIGINATOR"/>
     <s:checkbox name="authority" fieldValue="EVALUATOR" value="%{isEVALUATORSet}" label="EVALUATOR"/>
     <s:checkbox name="authority" fieldValue="EXECUTOR" value="%{isEXECUTORSet}" label="EXECUTOR"/>
    </s:form>
</body>
</html>

The handler is:

package com.sesoft.test;

import com.opensymphony.xwork2.Action;

public class Handler implements Action{

    private String isORIGINATORSet = "false";

    private String isEVALUATORSet = "false";

    private String isEXECUTORSet = "false";

    private String[] authority;

    @Override
    public String execute() throws Exception {


     for(String s : authority){

      if(s.equals("ORIGINATOR"))
       isORIGINATORSet = "true";
      if(s.equals("EVALUATOR"))
       isEVALUATORSet = "true";
      if(s.equals("EXECUTOR"))
       isEXECUTORSet = "true";
     }

     return Action.SUCCESS;
    }

    public void setAuthority(String[] authority){

     this.authority = authority;
    }

    public String getIsORIGINATORSet(){

     return this.isORIGINATORSet;
    }

    public String getIsEVALUATORSet(){

     return this.isEVALUATORSet;
    }

    public String getIsEXECUTORSet(){

     return this.isEXECUTORSet;
    }
}
Sefler
Sefler, didn't get your reply. Confirming you that I am getting value for multiple checked checkbox seperated with commas like (ORIGINATOR, EVALUATOR, EXECUTOR). And on the bases of these value I have to checked the corresponding checkbox in another jsp page.
vivmal