Re: Another questions about checkboxes
Hi Alex! Have you solved your problem yet? I was facing the same situation a cuple of weeks ago. All values from your formbean are sent in the request as parameters when you press submit - but checkbox values are only in the request if they have the value on = they are checked. The reset method works like this: values are first set to false by the reset method and then, if they are present i the request they receive value true, otherwise the have the value false. Is your problem the following: when you come to your second page the values are correct but when you submit this page you go to an action class that forwards to the first page - is that correct or do you go via two action classes to reach the first page from the second page? Anyway, since the formbean values are present as parameters in scope request, they are not found the last time the reset method is called. First the reset method sets the checkbox values to false, after that no parameters are found in the request and thats way the final checkbox value is false, even though it was true on your second page. I solved this problem by checking the formbean's checkbox values in the first action class after my second page and when I forwarded to a second action class before my first page was shown again I added parameters to the requset manually if the checkbox value was on = true. When the reset method was called these parameters were found and the formbean was populated in a correct way. Good luck / Linnéa By the way: A while ago someone sent an alternative version of the doStartTag that should solve the checkbox problem: new version for doStartTag() method : public int doStartTag() throws JspException { // Create an appropriate hidden element to put it before the input element // with value false. This will force to uncheck in the ActionForm if the checkbox // is not checked StringBuffer resultsHidden = new StringBuffer(input type=\hidden\); // Create an appropriate input element based on our parameters StringBuffer results = new StringBuffer(input type=\checkbox\); resultsHidden.append( name=\); results.append( name=\); // Indexed properties handling if (indexed != null) { IterateTag iterateTag = (IterateTag) findAncestorWithClass(this, IterateTag.class); if (iterateTag == null) { // this tag should only be nested in iteratetag, if it's not, throw exception JspException e = new JspException(messages.getMessage(indexed.noEnclosingIterate)); RequestUtils.saveException(pageContext, e); throw e; } if (name != null) { results.append(name); resultsHidden.append(name); } results.append([); results.append(iterateTag.getIndex()); results.append(]); resultsHidden.append([); resultsHidden.append(iterateTag.getIndex()); resultsHidden.append(]); if (name != null) { results.append(.); resultsHidden.append(.); } } // End of Indexed properties handling results.append(this.property); results.append(\); resultsHidden.append(this.property); resultsHidden.append(\ value=\false\ /); if (accesskey != null) { results.append( accesskey=\); results.append(accesskey); results.append(\); } if (tabindex != null) { results.append( tabindex=\); results.append(tabindex); results.append(\); } results.append( value=\); if (value == null) results.append(on); else results.append(value); results.append(\); Object result = RequestUtils.lookup(pageContext, name, property, null); if (result == null) result = ; if (!(result instanceof String)) result = result.toString(); String checked = (String) result; if (checked.equalsIgnoreCase(true) || checked.equalsIgnoreCase(yes) || checked.equalsIgnoreCase(on)) results.append( checked=\checked\); results.append(prepareEventHandlers()); results.append(prepareStyles()); results.append(); // Print this field to our output writer ResponseUtils.write(pageContext, results.toString() + resultsHidden.toString()); // Continue processing this page this.text = null; return (EVAL_BODY_TAG); } Linnéa Ahlbeck - Software Engineer phone +46 40 664 29 70 fax +46 40 30 32 62 mobile +46 708 96 14 56 Appium AB - Adelgatan 5, SE-211 22 Malmö, Sweden www.appium.com - Original Message - From: Alex Colic [EMAIL PROTECTED] To: Struts [EMAIL PROTECTED] Sent: Wednesday, January 02, 2002 4:04 PM Subject: Another questions about checkboxes Hi, I have a form that has a Boolean property that in the form reset method is reset to false. This form is used over two pages. In the first page there is a checkbox that the user
Re: Another questions about checkboxes
Hi Alex! Have you solved your problem yet? I was facing the same situation a cuple of weeks ago. All values from your formbean are sent in the request as parameters when you press submit - but checkbox values are only in the request if they have the value on = they are checked. The reset method works like this: values are first set to false by the reset method and then, if they are present i the request they receive value true, otherwise the have the value false. Is your problem the following: when you come to your second page the values are correct but when you submit this page you go to an action class that forwards to the first page - is that correct or do you go via two action classes to reach the first page from the second page? Anyway, since the formbean values are present as parameters in scope request, they are not found the last time the reset method is called. First the reset method sets the checkbox values to false, after that no parameters are found in the request and thats way the final checkbox value is false, even though it was true on your second page. I solved this problem by checking the formbean's checkbox values in the first action class after my second page and when I forwarded to a second action class before my first page was shown again I added parameters to the requset manually if the checkbox value was on = true. When the reset method was called these parameters were found and the formbean was populated in a correct way. Good luck / Linnéa By the way: A while ago someone sent an alternative version of the doStartTag that should solve the checkbox problem: new version for doStartTag() method : public int doStartTag() throws JspException { // Create an appropriate hidden element to put it before the input element // with value false. This will force to uncheck in the ActionForm if the checkbox // is not checked StringBuffer resultsHidden = new StringBuffer(input type=\hidden\); // Create an appropriate input element based on our parameters StringBuffer results = new StringBuffer(input type=\checkbox\); resultsHidden.append( name=\); results.append( name=\); // Indexed properties handling if (indexed != null) { IterateTag iterateTag = (IterateTag) findAncestorWithClass(this, IterateTag.class); if (iterateTag == null) { // this tag should only be nested in iteratetag, if it's not, throw exception JspException e = new JspException(messages.getMessage(indexed.noEnclosingIterate)); RequestUtils.saveException(pageContext, e); throw e; } if (name != null) { results.append(name); resultsHidden.append(name); } results.append([); results.append(iterateTag.getIndex()); results.append(]); resultsHidden.append([); resultsHidden.append(iterateTag.getIndex()); resultsHidden.append(]); if (name != null) { results.append(.); resultsHidden.append(.); } } // End of Indexed properties handling results.append(this.property); results.append(\); resultsHidden.append(this.property); resultsHidden.append(\ value=\false\ /); if (accesskey != null) { results.append( accesskey=\); results.append(accesskey); results.append(\); } if (tabindex != null) { results.append( tabindex=\); results.append(tabindex); results.append(\); } results.append( value=\); if (value == null) results.append(on); else results.append(value); results.append(\); Object result = RequestUtils.lookup(pageContext, name, property, null); if (result == null) result = ; if (!(result instanceof String)) result = result.toString(); String checked = (String) result; if (checked.equalsIgnoreCase(true) || checked.equalsIgnoreCase(yes) || checked.equalsIgnoreCase(on)) results.append( checked=\checked\); results.append(prepareEventHandlers()); results.append(prepareStyles()); results.append(); // Print this field to our output writer ResponseUtils.write(pageContext, results.toString() + resultsHidden.toString()); // Continue processing this page this.text = null; return (EVAL_BODY_TAG); } Linnéa Ahlbeck - Software Engineer phone +46 40 664 29 70 fax +46 40 30 32 62 mobile +46 708 96 14 56 Appium AB - Adelgatan 5, SE-211 22 Malmö, Sweden www.appium.com
Another questions about checkboxes
Hi, I have a form that has a Boolean property that in the form reset method is reset to false. This form is used over two pages. In the first page there is a checkbox that the user can select to modify this Boolean property. This page is submitted to an action class that just forwards to the second page. In the second page I display the checkbox value. After the second page the form is submitted to another action to process. The problem. In the first page the checkbox works correctly. In the second page, which is a summary page of selections on the first page, the form values are shown correctly. When the second page gets submitted to the last action class, the checkbox is reset to false and that is the value that the action class gets. I know that the second page, even though it only displays the values shown in the first page, is calling the reset method of the form. I need the reset method to set the Boolean to false because the user might go back a page and uncheck the checkbox. Does anyone have any experience of using checkboxes when the form goes over multiple pages? Any ideas on how I can fix this. Thanks a lot of any help. Alex -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: Another questions about checkboxes
In the reset method of the form class check what kind of action is accessing it and only reset the form whenever neccessary. You can do this by setting a hidden form field html:hidden property=action value=whatever in your jsp file and add the coresponding attribute in your form class. Good luck! Hi, I have a form that has a Boolean property that in the form reset method is reset to false. This form is used over two pages. In the first page there is a checkbox that the user can select to modify this Boolean property. This page is submitted to an action class that just forwards to the second page. In the second page I display the checkbox value. After the second page the form is submitted to another action to process. The problem. In the first page the checkbox works correctly. In the second page, which is a summary page of selections on the first page, the form values are shown correctly. When the second page gets submitted to the last action class, the checkbox is reset to false and that is the value that the action class gets. I know that the second page, even though it only displays the values shown in the first page, is calling the reset method of the form. I need the reset method to set the Boolean to false because the user might go back a page and uncheck the checkbox. Does anyone have any experience of using checkboxes when the form goes over multiple pages? Any ideas on how I can fix this. Thanks a lot of any help. Alex -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]