wood burning stoves 2.0*
The moose likes JSP and the fly likes Checkbox Isuue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Checkbox Isuue" Watch "Checkbox Isuue" New topic
Author

Checkbox Isuue

Sonu Sen
Greenhorn

Joined: Jun 03, 2009
Posts: 17
Hi i am using pure jsp, servlets and Hibernate.I am not using any tag library or struts. I have a one form in this form i have a 4-5 check boxes. my question is How to insert the checkbox value in the database ?

My POJO file is .....

public boolean isBwTVFlag(){
return this.bwTVFlag;
}

public void setBwTVFlag(boolean bwTVFlag){
this.bwTVFlag = bwTVFlag;
}

public boolean isColorTVFlag(){
return this.colorTVFlag;
}

public void setColorTVFlag(boolean colorTVFlag){
this.colorTVFlag = colorTVFlag;
}

public boolean isPhoneFlag(){
return this.phoneFlag;
}

public void setPhoneFlag(boolean phoneFlag){
this.phoneFlag = phoneFlag;
}

public boolean isSingleBedFlag(){
return this.singleBedFlag;
}

public void setSingleBedFlag(boolean singleBedFlag){
this.singleBedFlag = singleBedFlag;
}


My Servlet Is........


Boolean bwTVFlag = Boolean.valueOf(request.getParameter("bwTVFlag"));

Boolean colorTVFlag = Boolean.valueOf(request.getParameter("colorTVFlag"));

Boolean phoneFlag = Boolean.valueOf(request.getParameter("phoneFlag"));

Boolean singleBedFlag = Boolean.valueOf(request.getParameter("singleBedFlag"));

Boolean twinBedFlag = Boolean.valueOf(request.getParameter("twinBedFlag"));

String flag = request.getParameter("editFlag");

if(flag.equalsIgnoreCase("true")){
String id = request.getParameter("editID");
-------}
else{

rmb.setBwTVFlag(bwTVFlag);
rmb.setColorTVFlag(colorTVFlag);
rmb.setPhoneFlag(phoneFlag);
rmb.setSingleBedFlag(singleBedFlag);
rmb.setTwinBedFlag(twinBedFlag);


and my jsp page is....

<input type="hidden" name="editFlag" value="true">
<input type="hidden" name="editID" value="<%=rmb.getRoomId()%>">

<div style="width:200px;margin-left:70px;height:0px;position:relative;top:-28px;"><br />

<ul class="checklist cl3">
<li class="alt"><label for="c1"><input id="c1" name="bwTVFlag" type="checkbox" value="true"/>B/W T.V</label></li>
<li><label for="c2"><input id="c2" name="colorTVFlag" type="checkbox" value="true" />Color T.V</label></li>
<li class="alt"><label for="c3"><input id="c3" name="phoneFlag" type="checkbox" value="true" />Phone</label></li>
<li><label for="c4"><input id="c4" name="singleBedFlag" type="checkbox" value="true" />Single Bed</label></li>
<li class="alt"><label for="c5"><input id="c5" name="twinBedFlag" type="checkbox" value="true" />Twin Bed</label></li>


I hope i am clere ,,,Please help me...
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
Hi,

You can create a seperate DAO for inserting these values

-----DAO will contain parameters for checkbox values



-----Your servlet code will contain something like this


Cheers!!!
Ujjwal B Soni <baroda, gujarat, india> <+919909981973>
"Helping hands are better than praying lips......"
Sonu Sen
Greenhorn

Joined: Jun 03, 2009
Posts: 17
Thank you Ujjwal for your reply....

But ujjwal i dont want to add another file ..When i click on the Submit button in jsp page the value should insert into the database. I know that in the jsp page, On the Value Attribute of the checkbox some code is add but i can't get that code..

My Full Servlet is....

if(act.equalsIgnoreCase("addRoomBed")){
log.info("inside addRoomBed Action");
RoomBed rmb = null;
String wardName = request.getParameter("wardNameCB");
String roomNo = request.getParameter("roomNoTF");
String rate = request.getParameter("rateTF");
String bedNo = request.getParameter("bedNoTF");
Boolean bwTVFlag = Boolean.valueOf(request.getParameter("bwTVFlag"));
Boolean colorTVFlag = Boolean.valueOf(request.getParameter("colorTVFlag"));
Boolean phoneFlag = Boolean.valueOf(request.getParameter("phoneFlag"));
Boolean singleBedFlag = Boolean.valueOf(request.getParameter("singleBedFlag"));
Boolean twinBedFlag = Boolean.valueOf(request.getParameter("twinBedFlag"));
String flag = request.getParameter("editFlag");
if(flag.equalsIgnoreCase("true")){
String id = request.getParameter("editID");
RoomBedBo rbBo = new RoomBedBo();
List editRoomBed1 = rbBo.getRoomBed(Long.parseLong(id.trim()));
rmb = (RoomBed)editRoomBed1.get(0);
}else{
rmb= new RoomBed();
}
//rmb.setWardName(wardName);
rmb.setRoomNo(roomNo);
rmb.setRate(rate);
rmb.setBedNo(bedNo);
rmb.setActive(new Boolean(true));
/*rmb.setBwTVFlag(new Boolean(true));
rmb.setColorTVFlag(new Boolean(false));
rmb.setPhoneFlag(new Boolean(false));
rmb.setSingleBedFlag(new Boolean(false));
rmb.setTwinBedFlag(new Boolean(false));*/
rmb.setBwTVFlag(bwTVFlag);
rmb.setColorTVFlag(colorTVFlag);
rmb.setPhoneFlag(phoneFlag);
rmb.setSingleBedFlag(singleBedFlag);
rmb.setTwinBedFlag(twinBedFlag);


RoomBedBo rbBo = new RoomBedBo();
boolean saveRecord = rbBo.addRoomBed(rmb);
if(saveRecord = false) {
response.sendRedirect("/error.jsp");
rbBo=null;
}
else {
List roomBedList = rbBo.getAllRoomBedList(1);
request.setAttribute("roomBedList", roomBedList);
request.setAttribute("nextPageNumber", 2);
request.setAttribute("previousPageNumber", 1);
getServletContext().getRequestDispatcher("/RoomBedSetup.jsp").forward(request, response);
//neb=null;
}


And My jsp file is.......


<input type="hidden" name="Action" value="addRoomBed"> <!-- for new and Save -->
<%
if (request.getAttribute("editRoomBedList") != null) {
List getRoomBedList = (List) request.getAttribute("editRoomBedList");

if (getRoomBedList.size() > 0) {
RoomBed rmb =(RoomBed)getRoomBedList.get(0) ;
//out.println("------------"+rmb);
%>
<input type="hidden" name="editFlag" value="true"> <!-- for new and Save -->
<input type="hidden" name="editID" value="<%=rmb.getRoomId()%>"> <!-- for new and Save -->
<DIV class = "screenLableInputDiv"> <!--Div for Patient F Name-->
<Div class = "screenLable"> Ward Name </Div>
<select name="wardNameCB" size="1" >
<option value="" selected>Select</option>


</select>
</Div> <!--Div for Patient Name ends-->


<DIV class = "screenLableInputDiv"> <!--Div for Patient F Name-->
<Div class = "screenLable"> Room No. </Div>
<Div> <input type = "text" name = "roomNoTF" maxlength ="20" value="<%=rmb.getRoomNo()%>"></input> </Div>
</Div> <!--Div for Patient Name ends-->
<DIV class = "screenLableInputDiv"> <!--Div for Patient F Name-->
<Div class = "screenLable"> Rate </Div>
<Div> <input type = "text" name = "rateTF" maxlength ="20" value="<%=rmb.getRate()%>"></input> </Div>
</Div> <!--Div for Patient Name ends-->
<DIV class = "screenLableInputDiv"> <!--Div for Patient F Name-->
<Div class = "screenLable"> Bed No. </Div>
<Div> <input type = "text" name = "bedNoTF" maxlength ="20" value="<%=rmb.getBedNo()%>"></input> </Div>
</Div> <!--Div for Patient Name ends-->



<%
}
}else{
%>
<input type="hidden" name="editFlag" value="false"> <!-- for new and Save -->
<DIV class = "screenLableInputDiv"> <!--Div for Patient F Name-->
<Div class = "screenLable"> Ward Name </Div>
<select name="WardName" size="1">
<option value="" selected>Select</option>
<%Iterator itr;

if(request.getAttribute("wardList")!=null){
List wardname= (List)request.getAttribute("wardList");
if(wardname.size()>0){
for (int i=0;i<wardname.size();i++ )
{
Ward wrd = (Ward)wardname.get(i);
%>
<option value=<%=wrd.getWardName()%>><%=wrd.getWardName()%></option>
<% }
}
}

%>
</select>
</DIV> <!--DIV for Patient Name ends-->

<DIV class = "screenLableInputDiv"> <!--DIV for Patient F Name-->
<Div class = "screenLable"> Room No. </Div>
<Div> <input type = "text" name = "roomNoTF" maxlength ="20"></input> </Div>
</Div> <!--Div for Patient Name ends-->
<DIV class = "screenLableInputDiv"> <!--Div for Patient F Name-->
<Div class = "screenLable"> Rate </Div>
<Div> <input type = "text" name = "rateTF" maxlength ="20"></input> </Div>
</Div> <!--Div for Patient Name ends-->
<DIV class = "screenLableInputDiv"> <!--Div for Patient F Name-->
<Div class = "screenLable"> Bed No. </Div>
<Div> <input type = "text" name = "bedNoTF" maxlength ="20"></input> </Div>
</Div> <!--Div for Patient Name ends-->

<div style="width:200px;margin-left:70px;height:0px;position:relative;top:-28px;"><br />

<ul class="checklist cl3">
<li class="alt"><label for="c1"><input id="c1" name="bwTVFlag" type="checkbox" value="true"/>B/W T.V</label></li>
<li><label for="c2"><input id="c2" name="colorTVFlag" type="checkbox" value="true" />Color T.V</label></li>
<li class="alt"><label for="c3"><input id="c3" name="phoneFlag" type="checkbox" value="true" />Phone</label></li>
<li><label for="c4"><input id="c4" name="singleBedFlag" type="checkbox" value="true" />Single Bed</label></li>
<li class="alt"><label for="c5"><input id="c5" name="twinBedFlag" type="checkbox" value="true" />Twin Bed</label></li>
</div>
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
Hi,

Check that you are not getting null values here :



if you are not getting null then, try my below code

ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
Please note that the session is org.hibernate.Session; and not HTTPSession
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
Hi Bear,

Will take care from next time......

Thanks...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Checkbox Isuue
 
Similar Threads
Garbage collection doubt
how many objects will be eligible for garbage collection
check boxes retrieving problem
Javascript problem moving images from one div to another
how to disable if one or more check boxes selected