File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes checkbox  - initial value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "checkbox  - initial value" Watch "checkbox  - initial value" New topic

checkbox - initial value

Tracy Ward

Joined: Sep 07, 2005
Posts: 4

I've played with this issue for days - someone out there can help. I need the initial load of my page to have the checkboxes "checked"

i've tried:
setting the property initial value in the struts config;
setting the value in the jsp;
setting the varible to true in the form, this works great except the value is the always true, even when I unselect the box and submit the form.

so if anyone has any ideas I'd really appreciate it.

here is my code, when I check the box and submit the value passes correctly, I just cannot get the checkbox to display checked when the page loads....

<html:checkbox value="true" property="ckCancelled"/>Cancelled  

<form-property name="ckCompleted" initial="true" type="java.lang.boolean"/>
<action path="/completedCancelled" type="CompleteCancelAction"
name="initialcompleteCancelForm" scope="request" validate="true" input="/completeCancelReport.jsp">
<forward name="success" path="/jsp/completeCancelReport.jsp" />
<forward name="failure" path="/jsp/completeCancelReport.jsp" />

form bean:

private boolean ckCancelled;
public boolean getCkCompleted() { return ckCompleted; }
public void setCkCompleted(boolean ckCompleted) { this.ckCompleted = ckCompleted; }
Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

You could try using a SetupAction for when you initially enter the page.

A good workman is known by his tools.
Sravani Siri

Joined: Sep 20, 2005
Posts: 1
This is the best I could come up with.
ActionForm -


private String[] resetter = {};private boolean firstVisit = true;private String[] selectedItems = { "Non-Assessed"};private String[] items = { "Non-Assessed", "Assessed" };public String[] getSelectedItems(){return this.selectedItems;}public void setSelectedItems(String[] selectedItems){this.selectedItems = selectedItems;}public String[] getItems(){return this.items;}public void reset(ActionMapping mapping,HttpServletRequest request) {// Reset field values here.if(firstVisit){// Do not reset on first visitfirstVisit = false;}else{selectedItems = resetter;}}


JSP - *** refers to the name attribute of form-bean in struts-config


<logic:iterate name="***" id="item" property="items"><html:multibox property="selectedItems"><bean:write name="item"/></html:multibox><bean:write name="item"/></logic:iterate>
I agree. Here's the link:
subject: checkbox - initial value
It's not a secret anymore!