You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Albrecht Leiprecht <al...@t-online.de> on 2005/08/11 15:28:28 UTC

Conditionally show values in Tile (c:when?)

Hi all,

I have a tile that shows my default input row in a form. In case that I put
a value in FieldError, I want it to show it the errorMessage in red color.
So far so good. The values get to the tile (formRow)... and there it's
getting somewhat tricky. After reading a number of explanations, I
understands that struts.apache.org recommends to use JSTL whenever
possible... thus I use the c:when/c:otherwise construct like follows

<tiles:useAttribute id="errmsg" name="FieldError" scope="page"/>

<td>
  <%=errmsg.toString().length()%> 
  <%--correctly prints the expected value--%>
        
  <c:choose>
    <c:when test="${errmsg.toString().length() > 0}">
	<font color="#FF0000">
	  <tiles:getAsString name="FieldError"/>
	</font>
    </c:when>
    <c:otherwise>
	<img src="/img/blank.gif" height="1" width="111">
  	<%--unexpectedly always shows this--%>
    </c:otherwise>
  </c:choose>
</td>

Substitutes using logic:greaterThat are showing the same strange behavior...
Any Idea why this happens ? Any Tutorials, I could look up ?

TIA,
albi




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


Re: Conditionally show values in Tile (c:when?)

Posted by Swapnil Patil <sw...@gmail.com>.
Hi all,

As Albercht had mentioned in his 1st mail---

I have a tile that shows my default input row in a form. In case that I put
a value in FieldError, I want it to show it the errorMessage in red color.
So far so good. The values get to the tile (formRow)... and there it's
getting somewhat tricky. After reading a number of explanations, I
understands that struts.apache.org <http://struts.apache.org/> recommends to 
use JSTL whenever
possible... thus I use the c:when/c:otherwise construct like follows

is it true (bold text)?
I am new in Struts . Sorry by changing the topic.



On 8/11/05, Troy Bull <tr...@uni.edu> wrote:
> 
> Greg Reddin wrote:
> 
> > On Aug 11, 2005, at 9:30 AM, Albrecht Leiprecht wrote:
> >
> >> Just did the following:
> >> <%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
> >>
> >> <%
> >> int errmsglength = 5;
> >> %>
> >>
> >>
> >> Further down:
> >>
> >> <c:if test="${errmsglength > 1}">...</c:if>
> >>
> >> One would expect to see the 3 dots ... but nada ...
> >> And yes ...the taglib is loaded in the first line of the file ...Funky
> >> ...isn't it ?
> >
> >
> > Again, I think you're trying to access something in EL that it doesn't
> > know about. EL doesn't (in my understanding) automatically obtain
> > scriptlet variables. You'd have to put errmsglength in PageContext so
> > EL can find it. Try this:
> >
> > <%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
> >
> > <%
> > int errmsglength = 5;
> > pageContext.setAttribute("errmsglength", new Integer(errmsglength));
> > %>
> >
> > <c:if test="${errmsglength > 1}">...</c:if>
> >
> >
> > Greg
> 
> or you can do something like:
> 
> <c:set><%=variable%></c:set>
> 
> you need to put appropriate attributes on the c:set tag of course.
> 
> troy
> 
> --
> The best way to get convenient parking at Berkeley is to win a Nobel 
> Prize. All winners are given a reserved spot on central campus.
> 
> -- Ken
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

Re: Conditionally show values in Tile (c:when?)

Posted by Dave Newton <ne...@pingsite.com>.
I don't have access to the earlier messages, but have you been able to 
get _any_ JSTL tags to work? Do you have the JSTL jars and everything? 
I've never had _any_ problems with JSTL that weren't traceable to a 
wrong taglib or a missing JAR.

Dave

Albrecht Leiprecht wrote:

>No matter if I set it 
>
>pageContext.setAttribute("errmsglength", new Integer(errmsglength));
>
>or like this
>
><c:set><%=errmsglength%></c:set>
>
>No dots, nada. 
>I will create a fresh project that simulates the current situation and see
>if it shows the same behavior... That might allow me to track down the
>problem.
>
>At least, I learned that EL is somewhat picky about what it sees and what
>not ;)
>
>Thanks anyway guys... I'll post again, if/when I found the reason for this
>
>Rgds
>albi
>
>
>
>-----Original Message-----
>From: Troy Bull [mailto:troy.bull@uni.edu] 
>Sent: Thursday, August 11, 2005 4:47 PM
>To: Struts Users Mailing List
>Subject: Re: Conditionally show values in Tile (c:when?)
>
>Greg Reddin wrote:
>
>  
>
>>On Aug 11, 2005, at 9:30 AM, Albrecht Leiprecht wrote:
>>
>>    
>>
>>>Just did the following:
>>><%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
>>>
>>><%
>>>    int errmsglength = 5;
>>>%>
>>>
>>>
>>>Further down:
>>>
>>><c:if test="${errmsglength > 1}">...</c:if>
>>>
>>>One would expect to see the 3 dots ... but nada ...
>>>And yes ...the taglib is loaded in the first line of the file ...Funky
>>>...isn't it ?
>>>      
>>>
>>Again, I think you're trying to access something in EL that it doesn't 
>>know about.  EL doesn't (in my understanding) automatically obtain 
>>scriptlet variables.  You'd have to put errmsglength in PageContext so 
>>EL can find it.  Try this:
>>
>><%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
>>
>><%
>>    int errmsglength = 5;
>>    pageContext.setAttribute("errmsglength", new Integer(errmsglength));
>>%>
>>
>><c:if test="${errmsglength > 1}">...</c:if>
>>
>>
>>Greg
>>    
>>
>
>or you can do something like:
>
><c:set><%=variable%></c:set>
>
>you need to put appropriate attributes on the c:set tag of course.
>
>troy
>
>  
>


RE: Conditionally show values in Tile (c:when?)

Posted by Albrecht Leiprecht <al...@t-online.de>.
No matter if I set it 

pageContext.setAttribute("errmsglength", new Integer(errmsglength));

or like this

<c:set><%=errmsglength%></c:set>

No dots, nada. 
I will create a fresh project that simulates the current situation and see
if it shows the same behavior... That might allow me to track down the
problem.

At least, I learned that EL is somewhat picky about what it sees and what
not ;)

Thanks anyway guys... I'll post again, if/when I found the reason for this

Rgds
albi



-----Original Message-----
From: Troy Bull [mailto:troy.bull@uni.edu] 
Sent: Thursday, August 11, 2005 4:47 PM
To: Struts Users Mailing List
Subject: Re: Conditionally show values in Tile (c:when?)

Greg Reddin wrote:

> On Aug 11, 2005, at 9:30 AM, Albrecht Leiprecht wrote:
>
>> Just did the following:
>> <%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
>>
>> <%
>>     int errmsglength = 5;
>> %>
>>
>>
>> Further down:
>>
>> <c:if test="${errmsglength > 1}">...</c:if>
>>
>> One would expect to see the 3 dots ... but nada ...
>> And yes ...the taglib is loaded in the first line of the file ...Funky
>> ...isn't it ?
>
>
> Again, I think you're trying to access something in EL that it doesn't 
> know about.  EL doesn't (in my understanding) automatically obtain 
> scriptlet variables.  You'd have to put errmsglength in PageContext so 
> EL can find it.  Try this:
>
> <%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
>
> <%
>     int errmsglength = 5;
>     pageContext.setAttribute("errmsglength", new Integer(errmsglength));
> %>
>
> <c:if test="${errmsglength > 1}">...</c:if>
>
>
> Greg

or you can do something like:

<c:set><%=variable%></c:set>

you need to put appropriate attributes on the c:set tag of course.

troy

-- 
The best way to get convenient parking at Berkeley is to win a Nobel Prize.
All winners are given a reserved spot on central campus.

 -- Ken


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


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


Re: Conditionally show values in Tile (c:when?)

Posted by Troy Bull <tr...@uni.edu>.
Greg Reddin wrote:

> On Aug 11, 2005, at 9:30 AM, Albrecht Leiprecht wrote:
>
>> Just did the following:
>> <%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
>>
>> <%
>>     int errmsglength = 5;
>> %>
>>
>>
>> Further down:
>>
>> <c:if test="${errmsglength > 1}">...</c:if>
>>
>> One would expect to see the 3 dots ... but nada ...
>> And yes ...the taglib is loaded in the first line of the file ...Funky
>> ...isn't it ?
>
>
> Again, I think you're trying to access something in EL that it doesn't 
> know about.  EL doesn't (in my understanding) automatically obtain 
> scriptlet variables.  You'd have to put errmsglength in PageContext so 
> EL can find it.  Try this:
>
> <%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
>
> <%
>     int errmsglength = 5;
>     pageContext.setAttribute("errmsglength", new Integer(errmsglength));
> %>
>
> <c:if test="${errmsglength > 1}">...</c:if>
>
>
> Greg

or you can do something like:

<c:set><%=variable%></c:set>

you need to put appropriate attributes on the c:set tag of course.

troy

-- 
The best way to get convenient parking at Berkeley is to win a Nobel Prize.  All winners are given a reserved spot on central campus.

 -- Ken


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


Re: Conditionally show values in Tile (c:when?)

Posted by Greg Reddin <gr...@fnf.com>.
On Aug 11, 2005, at 9:30 AM, Albrecht Leiprecht wrote:
> Just did the following:
> <%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
>
> <%
> 	int errmsglength = 5;
> %>
>
>
> Further down:
>
> <c:if test="${errmsglength > 1}">...</c:if>
>
> One would expect to see the 3 dots ... but nada ...
> And yes ...the taglib is loaded in the first line of the file ...Funky
> ...isn't it ?

Again, I think you're trying to access something in EL that it doesn't 
know about.  EL doesn't (in my understanding) automatically obtain 
scriptlet variables.  You'd have to put errmsglength in PageContext so 
EL can find it.  Try this:

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>

<%
	int errmsglength = 5;
	pageContext.setAttribute("errmsglength", new Integer(errmsglength));
%>

<c:if test="${errmsglength > 1}">...</c:if>


Greg


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


Re: Conditionally show values in Tile (c:when?)

Posted by Dave Newton <ne...@pingsite.com>.
Albrecht Leiprecht wrote:

><% int errmsglength = 5; %>
>
><c:if test="${errmsglength > 1}">...</c:if>
>
>One would expect to see the 3 dots ... but nada ... Funky...isn't it ?
>  
>
Not really. JSTL looks for variables in application, session, request, 
or page scope.

<% request.setAttribute("errmsglength", new Integer(5); %>
<c:if test="${errmsglength > 5}">...</c:if>

Dave



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


RE: Conditionally show values in Tile (c:when?)

Posted by Albrecht Leiprecht <al...@t-online.de>.
Just did the following:
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>

<%
	int errmsglength = 5;
%>


Further down:

<c:if test="${errmsglength > 1}">...</c:if>

One would expect to see the 3 dots ... but nada ...
And yes ...the taglib is loaded in the first line of the file ...Funky
...isn't it ?


I'm using 5.0.x Tomcat, 1.2.7 Struts and I'm unsure what version 
of the JSTL libs, but other stuff like fmt and so on seems to work


Rgds
Albi

Ps: I'll do some testing later, why JSTL didn't work 


-----Original Message-----
From: Dave Newton [mailto:newton@pingsite.com] 
Sent: Thursday, August 11, 2005 4:12 PM
To: Struts Users Mailing List
Subject: Re: Conditionally show values in Tile (c:when?)

Greg Reddin wrote:

> Can you do toString() in EL?  I thought you could only access bean 
> properties.  If so, you'd need to provide a getLength() method on your 
> errormsg bean and do this
>
>     <c:when test="${errmsg.length > 0}">

Or <c:if test="${not empty errmsg}">...</c:if> depending on how you're 
filling errmsg and remove some additional clutter from the JSP.

Dave



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


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


Re: Conditionally show values in Tile (c:when?)

Posted by Dave Newton <ne...@pingsite.com>.
Greg Reddin wrote:

> Can you do toString() in EL?  I thought you could only access bean 
> properties.  If so, you'd need to provide a getLength() method on your 
> errormsg bean and do this
>
>     <c:when test="${errmsg.length > 0}">

Or <c:if test="${not empty errmsg}">...</c:if> depending on how you're 
filling errmsg and remove some additional clutter from the JSP.

Dave



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


Re: Conditionally show values in Tile (c:when?)

Posted by Greg Reddin <gr...@fnf.com>.
On Aug 11, 2005, at 8:28 AM, Albrecht Leiprecht wrote:
> <td>
>   <%=errmsg.toString().length()%>
>   <%--correctly prints the expected value--%>
>
>   <c:choose>
>     <c:when test="${errmsg.toString().length() > 0}">

Can you do toString() in EL?  I thought you could only access bean 
properties.  If so, you'd need to provide a getLength() method on your 
errormsg bean and do this

	<c:when test="${errmsg.length > 0}">

Greg


> 	<font color="#FF0000">
> 	  <tiles:getAsString name="FieldError"/>
> 	</font>
>     </c:when>
>     <c:otherwise>
> 	<img src="/img/blank.gif" height="1" width="111">
>   	<%--unexpectedly always shows this--%>
>     </c:otherwise>
>   </c:choose>
> </td>
>
> Substitutes using logic:greaterThat are showing the same strange 
> behavior...
> Any Idea why this happens ? Any Tutorials, I could look up ?
>
> TIA,
> albi
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>


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


RE: Conditionally show values in Tile (c:when?)

Posted by Albrecht Leiprecht <al...@t-online.de>.
Let me rephrase the question ....

Is there any limitation on using JSTL in Tiles ???

Rgs
albi

-----Original Message-----
From: Albrecht Leiprecht [mailto:aleiprecht@t-online.de] 
Sent: Thursday, August 11, 2005 3:28 PM
To: 'Struts Users Mailing List'
Subject: Conditionally show values in Tile (c:when?)

Hi all,

I have a tile that shows my default input row in a form. In case that I put
a value in FieldError, I want it to show it the errorMessage in red color.
So far so good. The values get to the tile (formRow)... and there it's
getting somewhat tricky. After reading a number of explanations, I
understands that struts.apache.org recommends to use JSTL whenever
possible... thus I use the c:when/c:otherwise construct like follows

<tiles:useAttribute id="errmsg" name="FieldError" scope="page"/>

<td>
  <%=errmsg.toString().length()%> 
  <%--correctly prints the expected value--%>
        
  <c:choose>
    <c:when test="${errmsg.toString().length() > 0}">
	<font color="#FF0000">
	  <tiles:getAsString name="FieldError"/>
	</font>
    </c:when>
    <c:otherwise>
	<img src="/img/blank.gif" height="1" width="111">
  	<%--unexpectedly always shows this--%>
    </c:otherwise>
  </c:choose>
</td>

Substitutes using logic:greaterThat are showing the same strange behavior...
Any Idea why this happens ? Any Tutorials, I could look up ?

TIA,
albi




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


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