File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes <hmtl:checkbox>problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "<hmtl:checkbox>problem" Watch "<hmtl:checkbox>problem" New topic
Author

<hmtl:checkbox>problem

harendra juturu
Greenhorn

Joined: Sep 23, 2009
Posts: 2
hi,


I am using technology jsp,struts,java.i designed jsp page 10 checkbox using struts html:checkbox tag.while load the page i selected few checkbox
the corresponding value store into database.its fine.
i want see the checked status based on geting database checkbox values.

please refer the code
<%--
Document : Privilages
Created on : Sep 21, 2009, 8:43:25 PM
Author : madhu
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="struts/html" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="struts/logic" prefix="logic" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>User Privilages</title>
</head>
<script>

function view(){
document.forms[0].mode.value="view";
document.forms[0].submit();

}
</script>
<body>
<h3 align="center"><font color="green"> USER PRIVILAGE</font></h3>
<html:form action="/privilages" method="post">
<input type="hidden" name="mode" value="input" />
<input type="hidden" name="viewmode" value="input" />
<table align="center" width="521" border="0">
<tr >
<td>
<html:select property="groupSelect" styleClass="select">
<option>Admin</option>
<option>Others</option>
<option>Collector </option>
<option>Suspended</option>
</html:select>
</td>
<tr>
<td><b><font color="blue">File Management</font></b></td>
<td><b><font color="blue">Employee</font></b></td>
</tr>
<tr>
<td><html:checkbox property="fmBox1" value="1">File Manager</html:checkbox></td>
<td><html:checkbox property="empChk1" value="6">Summery</html:checkbox></td>
</tr>
<tr>
<td><html:checkbox property="fmBox2" value="2">File Loading</html:checkbox> </td>
<td><html:checkbox property="empChk2" value="7">Planner</html:checkbox> </td>
</tr>
<tr>
<td><html:checkbox property="fmBox3" value="3">Activities</html:checkbox></td>
<td><html:checkbox property="empChk3" value="8">File Holding</html:checkbox> </td>
</tr>
<tr>
<td><html:checkbox property="fmBox4" value="4">Status Report</html:checkbox></td>
<td><html:checkbox property="empChk4" value="9">Collection</html:checkbox> </td>
</tr>
<tr>
<td><html:checkbox property="fmBox5" value="5">Transaction Report</html:checkbox></td>
<td><html:checkbox property="empChk5" value="10">Queues</html:checkbox> </td>
</tr>
<tr>
<td></td>
<td><html:checkbox property="empChk6" value="11">promises</html:checkbox> </td>
</tr>
<tr>
<td></td>
<td><html:checkbox property="empChk7" value="12">Calls</html:checkbox> </td>
</tr>
<tr>
<td> </td>
<td><html:checkbox property="empChk8" value="13">Debtor Notes</html:checkbox> </td>
</tr>
<tr>
<td><b><font color="blue">User Management</font></b></td>
<td><b><font color="blue">Must Do!</font></b></td>
</tr>
<tr>
<td><html:checkbox property="umChk1" value="14">User Maintenance</html:checkbox></td>
<td><html:checkbox property="mdChk1" value="16">planner</html:checkbox></td>
</tr>
<tr>
<td><html:checkbox property="umChk2" value="15">User Privilage</html:checkbox></td>
<td><html:checkbox property="mdChk2" value="17">File Holding</html:checkbox></td>
</tr>
<tr>
<td><b><font color="blue">Payments</font></b></td>
<td><b><font color="blue">Others</font></b></td>
</tr>
<tr>
<td><html:checkbox property="pmChk1" value="18">Payment Uploading</html:checkbox></td>
<td><html:checkbox property="otChk1" value="21">Searching</html:checkbox></td>
</tr>
<tr>
<td><html:checkbox property="pmChk2" value="19">Payment Entry</html:checkbox></td>
<td><html:checkbox property="otChk2" value="22">Clients</html:checkbox></td>
</tr>
<tr>
<td><html:checkbox property="pmChk3" value="20">Payment Status/Result</html:checkbox></td>
<td><html:checkbox property="otChk3" value="23">Reports</html:checkbox></td>
</tr>
<tr>
<td></td>
<td><html:checkbox property="otChk4" value="24">Voice Loger</html:checkbox></td>
</tr>
<tr>
</tr>
<tr>
<td colspan="3"><html:reset value="Reset"></html:reset>
<html:submit value="Update"></html:submit>
<input type="button" name="btnView" value="View" onclick="javascript:view()">
</tr>
</table>
</html:form>
</body>
</html>
---
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package USRMGMT;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import javax.naming.Context;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
//import com.myapp.struts.util.CommonUtilMethod;
import com.myapp.struts.util.DBConnection;

/**
*
* @author madhu
*/
public class PrivilagesAction extends Action{

DBConnection db=new DBConnection();

public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)
throws Exception{

System.out.println("entering a privilages Action forword Method");
PrivilagesActionForm paf=(PrivilagesActionForm)form;
System.out.println("entering a privilages action class");
String groupSel=paf.getGroupSelect();
System.out.println("****selected group name --:"+groupSel);
String mode = (String)request.getParameter("mode");
System.out.println("The Mode Is---"+mode);

String fmChk1=request.getParameter("fmBox1");
String fmChk2=request.getParameter("fmBox2");
String fmChk3=request.getParameter("fmBox3");
String fmChk4=request.getParameter("fmBox4");
String fmChk5=request.getParameter("fmBox5");

String empCh1=request.getParameter("empChk1");
String empCh2=request.getParameter("empChk2");
String empCh3=request.getParameter("empChk3");
String empCh4=request.getParameter("empChk4");
String empCh5=request.getParameter("empChk5");
String empCh6=request.getParameter("empChk6");
String empCh7=request.getParameter("empChk7");
String empCh8=request.getParameter("empChk8");

String umCh1=request.getParameter("umChk1");
String umCh2=request.getParameter("umChk2");

String mdCh1=request.getParameter("mdChk1");
String mdCh2=request.getParameter("mdChk2");

String pmCh1=request.getParameter("pmChk1");
String pmCh2=request.getParameter("pmChk2");
String pmCh3=request.getParameter("pmChk3");

String otCh1=request.getParameter("otChk1");
String otCh2=request.getParameter("otChk2");
String otCh3=request.getParameter("otChk3");
String otCh4=request.getParameter("otChk4");
//System
System.out.println("Fm1---:"+fmChk1);
System.out.println("Fm2 ---:"+fmChk2);
System.out.println("Fm3 ---:"+fmChk3);
System.out.println("Fm4 ---:"+fmChk4);
System.out.println("Fm5 ---:"+fmChk5);

System.out.println("Emp1 ---:"+empCh1);
System.out.println("Emp2 ---:"+empCh2);
System.out.println("Emp3 ---:"+empCh3);
System.out.println("Emp4 ---:"+empCh4);
System.out.println("Emp5 ---:"+empCh5);
System.out.println("Emp6 ---:"+empCh6);
System.out.println("Emp7 ---:"+empCh7);
System.out.println("Emp8 ---:"+empCh8);

System.out.println("um1 ---:"+umCh1);
System.out.println("um2 ---:"+umCh2);

System.out.println("md1 ---:"+mdCh1);
System.out.println("md2 ---:"+mdCh2);

System.out.println("pm1 ---:"+pmCh1);
System.out.println("pm2 ---:"+pmCh2);
System.out.println("pm3 ---:"+pmCh3);

System.out.println("ot1----:"+otCh1);
System.out.println("ot2----:"+otCh2);
System.out.println("ot3----:"+otCh3);
System.out.println("ot4----:"+otCh4);
//system :|| (fmChk2!=null && fmChk2.equals("2")) || (fmChk3!=null && fmChk3.equals("3")) || (fmChk4!=null && fmChk4.equals("4")) || (fmChk5!=null && fmChk5.equals("5"))
String conCat="";
if(fmChk1!=null && fmChk1.equals("1")) {
conCat=conCat+fmChk1+"_";
}
if(fmChk2!=null && fmChk2.equals("2")){
conCat=conCat+fmChk2+"_";
}else { fmChk2="2"; }
if(fmChk3!=null && fmChk3.equals("3")){
conCat=conCat+fmChk3+"_";
}else { fmChk3="3"; }
if(fmChk4!=null && fmChk4.equals("4")){
conCat=conCat+fmChk4+"_";
}else { fmChk4="4"; }
if(fmChk5!=null && fmChk5.equals("5")){
conCat=conCat+fmChk5+"_";
}else { fmChk5="5"; }

if(empCh1!=null && empCh1.equals("6")){
conCat=conCat+empCh1+"_";
}else { empCh1="6"; }
if(empCh2!=null && empCh2.equals("7")){
conCat=conCat+empCh2+"_";
}else { empCh2="7"; }

if(empCh3!=null && empCh3.equals("8")){
conCat=conCat+empCh3+"_";
}else { empCh3="8"; }

if(empCh4!=null && empCh4.equals("9")){
conCat=conCat+empCh4+"_";
}else { empCh4="9"; }
if(empCh5!=null && empCh5.equals("10")){
conCat=conCat+empCh5+"_";
}else { empCh5="10"; }
if(empCh6!=null && empCh6.equals("11")){
conCat=conCat+empCh6+"_";
}else { empCh6="11"; }
if(empCh7!=null && empCh7.equals("12")){
conCat=conCat+empCh7+"_";
}else { empCh7="12"; }
if(empCh8!=null && empCh8.equals("13")){
conCat=conCat+empCh8+"_";
}else { empCh8="13"; }
if(umCh1!=null && umCh1.equals("14")){
conCat=conCat+umCh1+"_";
}else { umCh1="14"; }
if(umCh2!=null && umCh2.equals("15")){
conCat=conCat+umCh2+"_";
}else { umCh2="15"; }
if(mdCh1!=null && mdCh1.equals("16")){
conCat=conCat+mdCh1+"_";
}else { mdCh1="16"; }
if(mdCh2!=null && mdCh2.equals("17")){
conCat=conCat+mdCh2+"_";
}else { mdCh2="17"; }
if(pmCh1!=null && pmCh1.equals("18")){
conCat=conCat+pmCh1+"_";
}else { pmCh1="18"; }
if(pmCh2!=null && pmCh2.equals("19")){
conCat=conCat+pmCh2+"_";
}else { pmCh2="19"; }
if(pmCh3!=null && pmCh3.equals("20")){
conCat=conCat+pmCh3+"_";
}else { pmCh3="20"; }
if(otCh1!=null && otCh1.equals("21")){
conCat=conCat+otCh1+"_";
}else { otCh1="21"; }
if(otCh2!=null && otCh2.equals("22")){
conCat=conCat+otCh2+"_";
}else { otCh2="22"; }
if(otCh3!=null && otCh3.equals("23")){
conCat=conCat+otCh3+"_";
}else { otCh3="23"; }
if(otCh4!=null && otCh4.equals("24")){
conCat=conCat+otCh4+"_";
}else { otCh4="24"; }
int count=0,ma=0;String cnt="";
ma=maxValue();
System.out.println("the higest:"+ma);
if(ma==0){ count=count+1 ; }else { count=ma+1;cnt=Integer.toString(count);}
//code begin mode=input
if(mode!=null && mode.equalsIgnoreCase("input")){
//
System.out.println("-----ConCatenate-----:"+conCat);
StringBuffer sb=new StringBuffer(conCat);
int len=sb.length();
sb.deleteCharAt(len-1);
System.out.println("--the string is underscore is delete---"+sb);
//
PreparedStatement insertUserDetails=null;
Connection con=null;
con=db.getConnection();
System.out.println("Input Section----");
int uid=100;int gid=200;String ui=Integer.toString(uid);
String gidd=Integer.toString(gid);
//String groupname="Admin";
try{
String queryInsert="";
queryInsert="insert into groupp(gid,user_id,group_id,group_name,privilages)values('"+cnt+"','"+ui+"','"+gidd+"','"+groupSel+"','"+sb+"')";
System.out.println("After Query:"+queryInsert);
insertUserDetails=con.prepareStatement(queryInsert);
System.out.println("--privilages---");
insertUserDetails.executeUpdate();
System.out.println("Inserted Privilages--");
}catch(SQLException e){
System.out.println(e);
}
insertUserDetails.close();
//end if condition mode:input
//code begin mode=view
}else if(mode!=null && mode.equalsIgnoreCase("view")){
System.out.println("inside view mode if condition is ----:");
String priv="";String [] temp = null;
priv=viewPrivilages(groupSel);
System.out.println("The group privilages is ---:"+priv);
temp=priv.split("_");
for(int i=0;i<temp.length;i++){
System.out.println("the First String***: "+temp[i]);
}

}//end if condition mode value is view
return(mapping.findForward("privilagesSuccess"));
//end action forword execute method
}
//the method for getting a group privilages
public String viewPrivilages(String grpName){
StringBuffer buf = new StringBuffer();
Statement st = null;
Connection con = null;
ResultSet rs = null;
int seaUid=0;
try{
con=db.getConnection();
st=con.createStatement();
String queryId="";
String pri="";
queryId="select gid,user_id,group_id,group_name,privilages from groupp where group_name='"+grpName+"'";
rs =st.executeQuery(queryId);
if(rs.next()!=false){
seaUid=rs.getInt("user_id");
System.out.println("search userId---"+seaUid);
pri=rs.getString("privilages");pri.toString();
buf.append(rs.getString("privilages").trim());
}

}catch(SQLException e){
System.out.println(e.toString());
}
return buf.toString() ;
//end viewPrivilages method
}
//Getting highest number in maxvalue method
public int maxValue(){
System.out.println("entering maxvalue method");
Connection con = null;
ResultSet rs = null;
String url = null;
Statement st = null;
StringBuffer sb = null;
//boolean bool = false;
int maximum=0;
try{
con=db.getConnection();
st = con.createStatement();
sb = new StringBuffer();
sb.append("select max(gid) as maxValue from groupp");
rs = st.executeQuery(sb.toString());
System.out.println("connection");
if(rs.next()!= false){
maximum=rs.getInt("maxValue");
}else{maximum=0;}
System.out.println("Maximum value group id is---"+rs.getInt("maxValue"));
System.out.println("the maximum value is insid maxvalue method--"+maximum);
}catch(SQLException e){

System.out.println(e.toString());
}
return(maximum);
//end maxvalue method
}
//end PrivilagesAction class
}
----
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package USRMGMT;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import org.apache.struts.action.ActionForm;

/**
*
* @author madhu
*/
public class PrivilagesActionForm extends ActionForm{

private String fmBox1;
private String fmBox2;
private String fmBox3;
private String fmBox4;
private String fmBox5;

private String empChk1;
private String empChk2;
private String empChk3;
private String empChk4;
private String empChk5;
private String empChk6;
private String empChk7;
private String empChk8;

private String umChk1;
private String umChk2;

private String mdChk1;
private String mdChk2;

private String pmChk1;
private String pmChk2;
private String pmChk3;

private String otChk1;
private String otChk2;
private String otChk3;
private String otChk4;
private String groupSelect;

public String getGroupSelect() {
return groupSelect;
}

public void setGroupSelect(String groupSelect) {
this.groupSelect = groupSelect;
}
public String getOtChk1() {
return otChk1;
}

public void setOtChk1(String otChk1) {
this.otChk1 = otChk1;
}

public String getOtChk2() {
return otChk2;
}

public void setOtChk2(String otChk2) {
this.otChk2 = otChk2;
}

public String getOtChk3() {
return otChk3;
}

public void setOtChk3(String otChk3) {
this.otChk3 = otChk3;
}

public String getOtChk4() {
return otChk4;
}

public void setOtChk4(String otChk4) {
this.otChk4 = otChk4;
}

public String getPmChk1() {
return pmChk1;
}

public void setPmChk1(String pmChk1) {
this.pmChk1 = pmChk1;
}

public String getPmChk2() {
return pmChk2;
}

public void setPmChk2(String pmChk2) {
this.pmChk2 = pmChk2;
}

public String getPmChk3() {
return pmChk3;
}

public void setPmChk3(String pmChk3) {
this.pmChk3 = pmChk3;
}



public String getMdChk1() {
return mdChk1;
}

public void setMdChk1(String mdChk1) {
this.mdChk1 = mdChk1;
}

public String getMdChk2() {
return mdChk2;
}

public void setMdChk2(String mdChk2) {
this.mdChk2 = mdChk2;
}

public String getUmChk1() {
return umChk1;
}

public void setUmChk1(String umChk1) {
this.umChk1 = umChk1;
}

public String getUmChk2() {
return umChk2;
}

public void setUmChk2(String umChk2) {
this.umChk2 = umChk2;
}

public String getEmpChk3() {
return empChk3;
}

public void setEmpChk3(String empChk3) {
this.empChk3 = empChk3;
}

public String getEmpChk4() {
return empChk4;
}

public void setEmpChk4(String empChk4) {
this.empChk4 = empChk4;
}

public String getEmpChk5() {
return empChk5;
}

public void setEmpChk5(String empChk5) {
this.empChk5 = empChk5;
}

public String getEmpChk6() {
return empChk6;
}

public void setEmpChk6(String empChk6) {
this.empChk6 = empChk6;
}

public String getEmpChk7() {
return empChk7;
}

public void setEmpChk7(String empChk7) {
this.empChk7 = empChk7;
}

public String getEmpChk8() {
return empChk8;
}

public void setEmpChk8(String empChk8) {
this.empChk8 = empChk8;
}


public String getEmpChk1() {
return empChk1;
}

public void setEmpChk1(String empChk1) {
this.empChk1 = empChk1;
}

public String getEmpChk2() {
return empChk2;
}

public void setEmpChk2(String empChk2) {
this.empChk2 = empChk2;
}
public String getFmBox1() {
return fmBox1;
}

public void setFmBox1(String fmBox1) {
this.fmBox1 = fmBox1;
}

public String getFmBox2() {
return fmBox2;
}

public void setFmBox2(String fmBox2) {
this.fmBox2 = fmBox2;
}

public String getFmBox3() {
return fmBox3;
}

public void setFmBox3(String fmBox3) {
this.fmBox3 = fmBox3;
}

public String getFmBox4() {
return fmBox4;
}

public void setFmBox4(String fmBox4) {
this.fmBox4 = fmBox4;
}

public String getFmBox5() {
return fmBox5;
}

public void setFmBox5(String fmBox5) {
this.fmBox5 = fmBox5;
}
public void reset(){

fmBox1="";
fmBox2="";
fmBox3="";
fmBox4="";
fmBox5="";
empChk1="";
empChk2="";
empChk3="";
empChk4="";
empChk5="";
empChk6="";
empChk7="";
empChk8="";
umChk1="";
umChk2="";

mdChk1="";
mdChk2="";

pmChk1="";
pmChk2="";
pmChk3="";
otChk1="";
otChk2="";
otChk3="";
otChk4="";

}





public PrivilagesActionForm(){
}
//end action form class
}
-----
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Hi harendra, welcome to javaranch.

Please Use Code Tags when you post a source code. You can edit your message using button and then add code tags to it...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

And please post only relevant portions of the source code.

And say what problem you're actually having.
 
Consider Paul's rocket mass heater.
 
subject: <hmtl:checkbox>problem
 
Similar Threads
"The path of an ForwardConfig cannot be null" error in Second run
Doubt in Validating the values form database
How to Validate duplicate entries in database using struts1
Doubt in Action Form
Unable to update database