We've implemented the same solution in our project with this tag. Hope can help you. Cheers. Guillermo.
package ar.com.eds.x71.framework.ui.taglibs.struts.html; import javax.servlet.jsp.JspException; import org.apache.struts.taglib.html.BaseFieldTag; import org.apache.struts.util.RequestUtils; import org.apache.struts.util.ResponseUtils; /** * CheckBox, que tiene un hidden asociado para que mande siempre valor, esté o no checkeado. [EMAIL PROTECTED] Guillermo Meyer **/ public class CheckBoxTag extends BaseFieldTag { /** * Genera el checkBox * */ private String arrayIndex=null; public int doStartTag() throws JspException { //esto crea el hidden StringBuffer results = new StringBuffer("<input type=\"hidden\" name=\""); results.append(property); results.append("\""); results.append(" value=\""); Object valor=null; if (value != null) { valor=value; results.append(valor); } else { valor = RequestUtils.lookup(pageContext, name, property, null); if (valor == null) valor = "false"; results.append(valor.toString()); } results.append("\">"); // Create an appropriate "input" element based on our parameters results.append("<input type=\"checkbox\""); results.append(" name=\""); results.append(this.property); results.append("_chk\""); String valor2 = valor.toString(); if (valor2.equalsIgnoreCase("true") || valor2.equalsIgnoreCase("yes") || valor2.equalsIgnoreCase("on")) results.append(" checked"); results.append(prepareEventHandlers()); results.append(prepareStyles()); results.append(">"); ResponseUtils.write(pageContext, results.toString()); return (EVAL_PAGE); } protected String getJSOnClick() { StringBuffer sb = new StringBuffer(); sb.append("if(this.checked) this.form.elements['"); sb.append(this.property); sb.append("']"); if(this.getArrayIndex()!=null) { sb.append("["); sb.append(this.getArrayIndex()); sb.append("]"); } sb.append(".value='true'; else this.form.elements['"); sb.append(this.property); sb.append("']"); if(this.getArrayIndex()!=null) { sb.append("["); sb.append(this.getArrayIndex()); sb.append("]"); } sb.append(".value='false';"); return sb.toString(); } /** * Prepares the event handlers for inclusion in the component's HTML tag. * @return The prepared String for inclusion in the HTML tag. */ protected String prepareEventHandlers() { StringBuffer handlers = new StringBuffer(); prepareMouseEvents(handlers); prepareKeyEvents(handlers); prepareFocusEvents(handlers); return handlers.toString(); } // -------------------------------------------------------- Private Methods /** * Prepares the mouse event handlers, appending them to the the given * StringBuffer. * @param handlers The StringBuffer that output will be appended to. */ private void prepareMouseEvents(StringBuffer handlers) { handlers.append(" onclick=\""); handlers.append(this.getJSOnClick()); if (this.getOnclick()!= null) { handlers.append(this.getOnclick()); handlers.append("\""); } handlers.append(";\""); if (this.getOndblclick() != null) { handlers.append(" ondblclick=\""); handlers.append(this.getOndblclick()); handlers.append("\""); } if (this.getOnmouseover() != null) { handlers.append(" onmouseover=\""); handlers.append(this.getOnmouseover()); handlers.append("\""); } if (this.getOnmouseout() != null) { handlers.append(" onmouseout=\""); handlers.append(this.getOnmouseout()); handlers.append("\""); } if (this.getOnmousemove() != null) { handlers.append(" onmousemove=\""); handlers.append(this.getOnmousemove()); handlers.append("\""); } if (this.getOnmousedown() != null) { handlers.append(" onmousedown=\""); handlers.append(this.getOnmousedown()); handlers.append("\""); } if (this.getOnmouseup() != null) { handlers.append(" onmouseup=\""); handlers.append(this.getOnmouseup()); handlers.append("\""); } if (this.getOnchange() != null) { handlers.append(" onchange=\""); handlers.append(this.getOnchange()); handlers.append("\""); } } /** * Prepares the keyboard event handlers, appending them to the the given * StringBuffer. * @param handlers The StringBuffer that output will be appended to. */ private void prepareKeyEvents(StringBuffer handlers) { if (this.getOnkeydown() != null) { handlers.append(" onkeydown=\""); handlers.append(this.getOnkeydown()); handlers.append("\""); } if (this.getOnkeyup() != null) { handlers.append(" onkeyup=\""); handlers.append(this.getOnkeyup()); handlers.append("\""); } if (this.getOnkeypress() != null) { handlers.append(" onkeypress=\""); handlers.append(this.getOnkeypress()); handlers.append("\""); } } /** * Prepares the focus event handlers, appending them to the the given * StringBuffer. * @param handlers The StringBuffer that output will be appended to. */ private void prepareFocusEvents(StringBuffer handlers) { if (this.getOnblur() != null) { handlers.append(" onblur=\""); handlers.append(this.getOnblur()); handlers.append("\""); } if (this.getOnfocus() != null) { handlers.append(" onfocus=\""); handlers.append(this.getOnfocus()); handlers.append("\""); } if (this.getDisabled()) { handlers.append(" disabled=\"disabled\""); } if (this.getReadonly()) { handlers.append(" readonly=\"readonly\""); } } /** * Returns the arrayIndex. * @return String */ public String getArrayIndex() { return arrayIndex; } /** * Sets the arrayIndex. * @param arrayIndex The arrayIndex to set */ public void setArrayIndex(String arrayIndex) { this.arrayIndex = arrayIndex; } } -----Original Message----- From: Samyukta Akunuru [mailto:[EMAIL PROTECTED] Sent: Viernes, 13 de Febrero de 2004 01:03 p.m. To: Struts Users Mailing List Subject: RE: how to send checkbox value? Thanks Scott,willl try mine with this sample~~~~ -----Original Message----- From: Ferguson, Scott [mailto:[EMAIL PROTECTED] Sent: Friday, February 13, 2004 9:58 AM To: Struts Users Mailing List Subject: RE: how to send checkbox value? Stolen from an old project... <script> function clicked_yn(hidden, option) { var temp = option.value; if (option.checked) { hidden.value = "Y"; } else { hidden.value = "N"; } } </script> <% String val = ""; String hasFieldName = ""; if(bean.getFieldName() != null && bean.getFieldName().equalsIgnoreCase("y")) { hasFieldName = "checked"; } else { bean.setFieldName("N"); } %> : : <INPUT type="checkbox" onclick="clicked_yn(fieldName, fieldNameBox);" name=fieldNameBox <%=hasFieldName %>/> <INPUT type="hidden" name="fieldName" value="<%=bean.getFieldName()%>"/> : : Note that the value of the field represented visually by the checkbox should only have "Y" or "N" as values. See if that helps.... saF -----Original Message----- From: Samyukta Akunuru [mailto:[EMAIL PROTECTED] Sent: Friday, February 13, 2004 11:47 AM To: Struts Users Mailing List Subject: RE: how to send checkbox value? Could you enlcose the sample....Thanks! -----Original Message----- From: Ferguson, Scott [mailto:[EMAIL PROTECTED] Sent: Friday, February 13, 2004 9:46 AM To: Struts Users Mailing List Subject: RE: how to send checkbox value? Have a hidden field that is the actual name of your field, use some jsp code fo set the value of the checkbox at load time based on the value of the hidden field, and use JavaScript to set the hidden field when the checkbox is changed. I have done this in non-Struts apps and expect to be using it very soon in a Struts app. saF -----Original Message----- From: Wendy Smoak [mailto:[EMAIL PROTECTED] Sent: Friday, February 13, 2004 11:37 AM To: Struts Users Mailing List Subject: RE: how to send checkbox value? > From: Sathish Babu K R [mailto:[EMAIL PROTECTED] > i like to send check box value of a page to another > page when a link is clicked which does not go thru any > form.its a struts environment You can send parameters on the URL of the link, no need to have a form. Or you can have a form and use JavaScript to set a value and submit the form when a link is clicked. -- Wendy Smoak Application Systems Analyst, Sr. ASU IA Information Resources Management --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] NOTA DE CONFIDENCIALIDAD Este mensaje (y sus anexos) es confidencial, esta dirigido exclusivamente a las personas direccionadas en el mail y puede contener informacion (i)de propiedad exclusiva de Interbanking S.A. o (ii) amparada por el secreto profesional. Cualquier opinion en el contenido, es exclusiva de su autor y no representa necesariamente la opinion de Interbanking S.A. El acceso no autorizado, uso, reproduccion, o divulgacion esta prohibido. Interbanking S.A no asumira responsabilidad ni obligacion legal alguna por cualquier informacion incorrecta o alterada contenida en este mensaje. Si usted ha recibido este mensaje por error, le rogamos tenga la amabilidad de destruirlo inmediatamente junto con todas las copias del mismo, notificando al remitente. No debera utilizar, revelar, distribuir, imprimir o copiar este mensaje ni ninguna de sus partes si usted no es el destinatario. Muchas gracias. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]