Billy Bacon wrote:
I've run into the same issue but with a different tag other than <c:out>.
I'm assuming they are related but I'm really looking for some advice here...

I'm in the process of converting my application to JSTL from Struts tags.
Once Struts 1.1 Release Candidate 2 came out supporting EL I decided to
stick with Struts EL since converting the entire application to JSTL and
removing all of my Struts tags didn't seem possible when I started to run
into this issue.

In my original code I had the following "if" statement within my JSP...

<logic:equal name="adminDownloadForm" property="idFlag" value="true">
<%-- Show some related information if 'idFlag' evaluates to true --%>
</logic:equal>

The above worked just fine and returned the expected information. When I
tried to convert this simple "if" statement to JSTL I ran into a problem...
Here's the code I attempted to use...

<c:if test="${adminDownloadForm.idFlag}">
<%-- Show some related information if 'idFlag' evaluates to true --%>
</c:if>

Once I tried the <c:if> tag and executed the JSP I received the error
described by Matt below... "


An error occurred while evaluating custom action
attribute "value" with value
"${adminDownloadForm.idFlag}": Unable to find a value for
"ifFlag" in object of class
"com.xxxx.xxx.xxxx.xxx" using operator "."
(null)'

This means that there's something quite not right with the "idFlag" property in your bean. The JSTL EL goes strictly by the JavaBeans specification, so the bean must satisfy all rules for the property access methods. A quite common problem is to have a "getter" method that returns an object of one type, and a "setter" method that takes an object of another type:

  public class MyBean {
    ...
    public boolean getIdFlag() {...}
    public setIdFlag(String value) {...}
  }

This is not valid according to the JavaBeans spec, so the end result is
that this class doesn't define a property named "idFlag" at all, even
though it has a getIdFlag() method.

JSTL is not aware of the adminDownloadForm object. I know this Form is
related to Struts but the behavior of these JSTL tags is inconsistent. In
order to get my <c:if> tag to work properly I had to use a <bean:define> tag
from the Struts library and define the 'idFlag' variable.

Now if I do something like this, my <c:if> tag works fine....

<bean:define id="idFlag" name="adminDownloadForm" property="idFlag" />
<c:if test="${idFlag}">
....
</c:if>

I have not looked at the Struts code, but I assume that it doesn't use the JavaBeans support classes to get the property value. If it uses plain introspection to get hold of a method called getIdFlag() and call it, it works even though the class doesn't have a bean property with the name "idFlag" according to the JavaBeans spec.

But now I'm writing two lines of code when all I needed was one line using
the <logic:equals> tag from the Struts library. I know an additional line of
code is not the end of the world but which is better practice? Is having
Struts tags and JSTL tags in your JSP bad practice? Could it cause confusion
to other developers down the road?

In general, using more than one tag library from different sources in a JSP application is not bad practice (it's commonly needed, actually). But I recommend sticking to JSTL in the cases where there's a direct replacement for the Struts tag, as in the case of <logic:equals> vs. <c:if>.

Back to my point of JSTL being inconsistent... I have this standalone tag in
my JSP (with no bean define or <c:set> and I do not get an exception from
this tag... It works just fine....

<c:forEach var="assetType" items="${summaryForm.assetTypeQueues}">

What's confusing and inconsistent is that I didn't need to define the
'summaryForm' object. It was capable of seeing it and extracted the variable
I asked from it just fine. Why doesn't the <c:if> tag act in the same
manner? Is this a bug or am I doing something wrong?

See above. It's arguably a bug in your bean class (unless there's something else going on here that I'm not aware of).

I apologize for the novel I just wrote but I didnšt want to leave out any
details. Any advice would be greatly appreciated.

I hope this helps, Hans -- Hans Bergsten <[EMAIL PROTECTED]> Gefion Software <http://www.gefionsoftware.com/> Author of O'Reilly's "JavaServer Pages", covering JSP 1.2 and JSTL 1.0 Details at <http://TheJSPBook.com/>


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to