Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

checkbox - initial value

 
Tracy Ward
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI

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....

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

struts-config:
..initialcompleteCancelForm
<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" />
</action>

form bean:

private boolean ckCancelled;
public boolean getCkCompleted() { return ckCompleted; }
public void setCkCompleted(boolean ckCompleted) { this.ckCompleted = ckCompleted; }
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try using a SetupAction for when you initially enter the page.
 
Sravani Siri
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the best I could come up with.
ActionForm -


code:
--------------------------------------------------------------------------------

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

code:
--------------------------------------------------------------------------------

<logic:iterate name="***" id="item" property="items"><html:multibox property="selectedItems"><bean:write name="item"/></html:multibox><bean:write name="item"/></logic:iterate>
.......................................................................
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic