You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Struts Newsgroup (@Basebeans.com)" <st...@basebeans.com> on 2002/07/31 14:40:02 UTC

How do I use the tag to replace of the past JSP code?

Subject: How do I use the <html:checkbox> tag to replace of the past JSP code?
From: "news.basebeans.com" <ju...@intech.com.tw>
 ===
Hi,

    I used the following code to setup checkbox value and checked status
before using struts.
<%
 if (arrSParameters != null) {
  for (Enumeration objEnu = arrSParameters.elements() ;
objEnu.hasMoreElements() ;) {
   objParameter = (PLSystemParameter)objEnu.nextElement();
%>
<input type="checkbox" name="parameterCode"
value="<%=objParameter.getParameterCode()%>"
<%=HTMLTools.getCheckedString(arrSPCodes,
objSParameter.getParameterCode())%>>
<%
  }
 }
%>
    I used a for-loop to generate many checkboxes, and all of the
checkboxes' values are from java beans' property. Besides, I used a function
which utilize whether the specified java bean's property belong to a string
array to judge if the "checked" string was showed.

    I use the struts now. The following code is my experiment. I didn't know
how to setup the checkbox attribut to show "checked" string.
<logic:iterate id="objParameter" collection="<%= arrSParameters %>"
indexId="index">
  <html:checkbox name="objParameter" property="parameterCode" />
</logic:iterate>

    The result page didn't show the same as the result of the past code. The
struts result is follow code.
<input type="checkbox" name="parameterCode" value="on">
<input type="checkbox" name="parameterCode" value="on">
<input type="checkbox" name="parameterCode" value="on">
<input type="checkbox" name="parameterCode" value="on">
    The checkboxes's value is struts' default value "on" not the java beans'
property. I hope the result page shows the following code.
<input type="checkbox" name="parameterCode" value="WORK_START_HOUR">
<input type="checkbox" name="parameterCode" value="WORK_END_HOUR" checked>
<input type="checkbox" name="parameterCode" value="REST_START_HOUR">
<input type="checkbox" name="parameterCode" value="REST_END_HOUR" checked>
The checkboxes' values are appropriate for the java beans' property and the
"checked" string can be showed or not by condition.

    If the checkbox tag of the struts doesn't support this requirement or I
must extend the checkbox tag of the struts, please tell me, too.

Thank you very much

Judging Huang in Taiwan




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How do I use the tag to replace of the past JSP code?

Posted by "David M. Karr" <dm...@earthlink.net>.
>>>>> "Struts" == Struts Newsgroup <(@Basebeans.com) <st...@basebeans.com>> writes:

    Struts>     I used the following code to setup checkbox value and checked status
    Struts> before using struts.
    Struts> <%
    Struts>  if (arrSParameters != null) {
    Struts>   for (Enumeration objEnu = arrSParameters.elements() ;
    Struts> objEnu.hasMoreElements() ;) {
    Struts>    objParameter = (PLSystemParameter)objEnu.nextElement();
    Struts> %>
    Struts> <input type="checkbox" name="parameterCode"
    Struts> value="<%=objParameter.getParameterCode()%>"
    Struts> <%=HTMLTools.getCheckedString(arrSPCodes,
    Struts> objSParameter.getParameterCode())%>>
    Struts> <%
    Struts>   }
    Struts>  }
    Struts> %>
    Struts>     I used a for-loop to generate many checkboxes, and all of the
    Struts> checkboxes' values are from java beans' property. Besides, I used a function
    Struts> which utilize whether the specified java bean's property belong to a string
    Struts> array to judge if the "checked" string was showed.

    Struts>     I use the struts now. The following code is my experiment. I didn't know
    Struts> how to setup the checkbox attribut to show "checked" string.
    Struts> <logic:iterate id="objParameter" collection="<%= arrSParameters %>"
    Struts> indexId="index">
    Struts>   <html:checkbox name="objParameter" property="parameterCode" />
    Struts> </logic:iterate>

I believe the better way to do this is to use a "multibox" tag, instead of a
"checkbox" tag.  I almost wonder sometimes whether the need for "multibox" is
larger than "checkbox".  I don't have enough experience building applications
using these to really get a feeling for that.  I would think a very useful
enhancement would be a "NOTE:" in the "checkbox" documentation saying that you
should likely use "multibox" if you are tending for your "value"s to be
attribute or capability names, as opposed to "on" or "yes".

-- 
===================================================================
David M. Karr          ; Java/J2EE/XML/Unix/C++
dmkarr@earthlink.net


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>