• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

checkbox - initial value

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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; }
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could try using a SetupAction for when you initially enter the page.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
.......................................................................
 
reply
    Bookmark Topic Watch Topic
  • New Topic