You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by "Tom Holmes Jr." <to...@tomholmes.net> on 2005/07/06 17:01:51 UTC

combining tags

I used to have some JSP code that looked like:

 <logic:iterate name="myForm" property="myDataList" id="iter">
        <html:checkbox name="iter" property="checkedRes" indexed="true"/>
        <bean:write name="iter" property="roomType"/>
       <html:text name="iter" property="numItems" indexed="true" 
style="width:40"/>
 </logic:iterate>

I'd like to switch to something likes this:
<c:forEach items="${SelectedRoomsForm.roomsList}" var="data" 
varStatus="status">
        <html:checkbox name="data" property="checkedRes" indexed="true"/>
        <c:out value="${data.roomType}"/>
       <html:text name="data" property="numItems" indexed="true" 
style="width:40"/>
</c:forEach>

The <c:out> tag I am sure works, but I am not sure about the 
<html:checkbox> or the <html:text>

Does this code look ok, or is there something I have to change?

Thanks.
                                          Tom

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Re: combining tags

Posted by Rahul Akolkar <ra...@gmail.com>.
Tom - Please see reply below:

On 7/6/05, Tom Holmes Jr. <to...@tomholmes.net> wrote:
> I used to have some JSP code that looked like:
> 
>  <logic:iterate name="myForm" property="myDataList" id="iter">
>        <html:checkbox name="iter" property="checkedRes" indexed="true"/>
>        <bean:write name="iter" property="roomType"/>
>       <html:text name="iter" property="numItems" indexed="true"
> style="width:40"/>
>  </logic:iterate>
> 
> I'd like to switch to something likes this:
> <c:forEach items="${SelectedRoomsForm.roomsList}" var="data"
> varStatus="status">
>        <html:checkbox name="data" property="checkedRes" indexed="true"/>
>        <c:out value="${data.roomType}"/>
>       <html:text name="data" property="numItems" indexed="true"
> style="width:40"/>
> </c:forEach>
> 
> The <c:out> tag I am sure works, but I am not sure about the
> <html:checkbox> or the <html:text>
> 
> Does this code look ok, or is there something I have to change?

Though you can mix and match JSTL and the Struts taglibs, you should
be aware of the inter-dependencies between specific tags. For example,
the indexed property of the struts-html tags relies on a parent
logic:iterate to produce the resulting name attribute. I recommend
reading this FAQ page [
http://struts.apache.org/faqs/indexedprops.html ] and the TLD docs in
general.

If you stare at the markup generated by the first snippet, that will
tell you what the JSTL snippet should look like.

-Rahul

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Re: combining tags

Posted by Martin Cooper <mf...@gmail.com>.
On 7/6/05, Wendy Smoak <ja...@wendysmoak.com> wrote:
> From: "Tom Holmes Jr." <to...@tomholmes.net>
> 
> > I have no idea if it is a JSP Container 2.0 or not.  I can tell you that
> > we are using IBM Websphere 5.1.x Portal Server.
> 
> A quick Google search didn't turn up the info-- I'm trying to determine
> which version of the Servlet specification it implements.  My comment was
> merely that if it's Servlet 2.4/JSP 2.0, you probably would have written
> ${data.roomType}
> instead of <c:out value="${data.roomType}"/>.  Not that you wouldn't use
> *any* <c:xxx> tags.
> 
> So, let's assume Servlet 2.3/JSP 1.2 for now.

That would be the correct assumption. ;-) WebSphere 5.x is Servlet
2.3/JSP 1.2, while WebSphere 6.x is Servlet 2.4/JSP 2.0.

> > And we are using Struts.   My boss has told me at one point that he'd
> > wanted to start using JSTL tags more then the older JSP Tag Libraries.
> > To me, that means using more of the <c:?> tags, but we still need to use
> > html:? tags.
> 
> My point was that if you're going to add JSTL to a Struts project, you might
> also want to move to Struts-EL in order to gain the ability to use
> expressions within the Struts tags, as well as the JSTL-awareness so that
> indexed properties will work within an enclosing <c:forEach> loop.
> http://struts.apache.org/faqs/struts-el.html

Yep, you'll definitely want to move to the Struts-EL tags. It could
get quite confusing, trying to use the RT tags while you're using JSTL
elsewhere.

--
Martin Cooper


> --
> Wendy Smoak
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Re: combining tags

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Tom Holmes Jr." <to...@tomholmes.net>

> I have no idea if it is a JSP Container 2.0 or not.  I can tell you that
> we are using IBM Websphere 5.1.x Portal Server.

A quick Google search didn't turn up the info-- I'm trying to determine
which version of the Servlet specification it implements.  My comment was
merely that if it's Servlet 2.4/JSP 2.0, you probably would have written
${data.roomType}
instead of <c:out value="${data.roomType}"/>.  Not that you wouldn't use
*any* <c:xxx> tags.

So, let's assume Servlet 2.3/JSP 1.2 for now.

> And we are using Struts.   My boss has told me at one point that he'd
> wanted to start using JSTL tags more then the older JSP Tag Libraries.
> To me, that means using more of the <c:?> tags, but we still need to use
> html:? tags.

My point was that if you're going to add JSTL to a Struts project, you might
also want to move to Struts-EL in order to gain the ability to use
expressions within the Struts tags, as well as the JSTL-awareness so that
indexed properties will work within an enclosing <c:forEach> loop.
http://struts.apache.org/faqs/struts-el.html

-- 
Wendy Smoak


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Re: combining tags

Posted by "Tom Holmes Jr." <to...@tomholmes.net>.
Wendy Smoak wrote:

>From: "Tom Holmes Jr." <to...@tomholmes.net>
>
>  
>
>>I'd like to switch to something likes this:
>><c:forEach items="${SelectedRoomsForm.roomsList}" var="data"
>>varStatus="status">
>>        <html:checkbox name="data" property="checkedRes" indexed="true"/>
>>        <c:out value="${data.roomType}"/>
>>       <html:text name="data" property="numItems" indexed="true"
>>style="width:40"/>
>></c:forEach>
>>
>>The <c:out> tag I am sure works, but I am not sure about the
>><html:checkbox> or the <html:text>
>>
>>Does this code look ok, or is there something I have to change?
>>    
>>
>
>Assuming you're not on a JSP 2.0 container (I assume not, or you wouldn't be
>using <c:out>) you might want to switch to the Struts-EL tags instead of the
>'classic' taglib.  With the ability to use expressions in the JSTL tags,
>you'll quickly get frustrated at NOT being able to do it in the Struts tags.
>
>Indexed tags are now supported within <c:forEach> loops, according to the
>README.txt file included with Struts-EL.  To switch over, look in the
>'contrib' directory of the Struts 1.2.7 distribution, get the .jar files and
>change to:
>     <%@ taglib uri="http://struts.apache.org/tags-html-el" prefix="html-el"
>%>
>(Some people leave the prefix as 'html'.)
>
>All my checkboxes-within-forEach-loops are 'multibox' not 'checkbox'.  But I
>don't use indexed properties, so YMMV.
>
>  
>
I have no idea if it is a JSP Container 2.0 or not.  I can tell you that 
we are using IBM Websphere 5.1.x Portal Server.   I can also tell you 
that the the imports we are using in our JSP pages look like:
<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tld/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>

And we are using Struts.   My boss has told me at one point that he'd 
wanted to start using JSTL tags more then the older JSP Tag Libraries.  
To me, that means using more of the <c:?> tags, but we still need to use 
html:? tags.  To my boss, that would mean getting more functionality and 
using expressions as you stated.  For example, rather than writing:

 <bean:write name="iter" property="selectedStartDate1"/> -
  <bean:write name="iter" property="selectedEndDate1"/><br>

Instead we could do:
<c:out value="${data.selectedStartDate1} - ${data.selectedEndDate1}" />

Doesn't that seem easier to understand?  I just figured we'd get the 
same results when we submit the form.  When using <logic:iterate> I 
understand how we can do <c:out> just fine.  And it works fine with 
html:text, but it's when we do <c:if test=""> something that I was 
getting into trouble.  It didn't seem to work?

As Rahul stated, I'll check the generated HTML source and I'll also 
check the Action class to see if the data submitted is the same.

Thanks for the help.

                                               Tom

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Re: combining tags

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Tom Holmes Jr." <to...@tomholmes.net>

> I'd like to switch to something likes this:
> <c:forEach items="${SelectedRoomsForm.roomsList}" var="data"
> varStatus="status">
>         <html:checkbox name="data" property="checkedRes" indexed="true"/>
>         <c:out value="${data.roomType}"/>
>        <html:text name="data" property="numItems" indexed="true"
> style="width:40"/>
> </c:forEach>
>
> The <c:out> tag I am sure works, but I am not sure about the
> <html:checkbox> or the <html:text>
>
> Does this code look ok, or is there something I have to change?

Assuming you're not on a JSP 2.0 container (I assume not, or you wouldn't be
using <c:out>) you might want to switch to the Struts-EL tags instead of the
'classic' taglib.  With the ability to use expressions in the JSTL tags,
you'll quickly get frustrated at NOT being able to do it in the Struts tags.

Indexed tags are now supported within <c:forEach> loops, according to the
README.txt file included with Struts-EL.  To switch over, look in the
'contrib' directory of the Struts 1.2.7 distribution, get the .jar files and
change to:
     <%@ taglib uri="http://struts.apache.org/tags-html-el" prefix="html-el"
%>
(Some people leave the prefix as 'html'.)

All my checkboxes-within-forEach-loops are 'multibox' not 'checkbox'.  But I
don't use indexed properties, so YMMV.

-- 
Wendy Smoak


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org