aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "checkbox  - initial value" Watch "checkbox  - initial value" New topic
Author

checkbox - initial value

Tracy Ward
Greenhorn

Joined: Sep 07, 2005
Posts: 4
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

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
Greenhorn

Joined: Sep 20, 2005
Posts: 1
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>
.......................................................................
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: checkbox - initial value
 
Similar Threads
retaining checkbox value
SSLEXT and Struts 1.2.9
how to populate formbean property using html:checkbox values
First struts app help! Drop-down lists
<global-forwards> problem in struts-config.xml