Hi,
    Answering my own question.

  The code to check if an indexed property is null or not in Struts
1.0.2/JSTL seems to be so long. I am  just using two date checks here. This
seems to be so even if we use JSTL. I think that this type of logic is quite
commonplace in web projects.

 Should it be so complex ? Am I making it so complex? It works anyway.

            <!-- Get current date and format it appropriately -->
                <jsp:useBean id="now" class="java.util.Date" />
                <fmt:formatDate var="currentdate" value="${now}"
pattern="dd/MM/yyyy"/>

            <!-- Use the variable once. Why doesn't JSTL above do that
automatically ? -->
                <jsp:useBean id="currentdate" class="java.lang.String" />

            <!-- Declare two variables at the beginning. Why is type
necessary here? 
                 These two variables are manipulated below. Why is this
declaration
                 necessary ? -->
        <bean:define id="startdate" value="<%=currentdate%>"
type="java.lang.Object"/>
    <bean:define id="enddate" value="<%=currentdate%>"
type="java.lang.Object"/>

            <!-- The logic to check if the indexed property is null or not.
                     If it is null, use the current date. -->
                <c:choose>
                        <c:when test="${reportForm.startDate[0] != null}">
                          <bean:define id="startdate" name="reportForm"
property='<%= "startDate[" + 0 + "]"    %>'/>
                        </c:when>
                        <c:when test="${reportForm.startDate[0] == null}">
                          <bean:define id="startdate"
value="<%=currentdate.toString()%>"/>
                        </c:when>
                        <c:otherwise>
                          <bean:define id="startdate"
value="<%=currentdate.toString()%>"/>
                        </c:otherwise>
                </c:choose>

            <!-- The logic to check if the indexed property is null or not.
                     If it is null, use the current date. -->
                <c:choose>
                        <c:when test="${reportForm.endDate[0] != null}">
                          <bean:define id="enddate" name="reportForm"
property='<%= "endDate[" + 0 + "]"      %>'/>
                        </c:when>
                        <c:when test="${reportForm.endDate[0] == null}">
                          <bean:define id="enddate"
value="<%=currentdate.toString()%>"/>
                        </c:when>
                        <c:otherwise>
                          <bean:define id="enddate"
value="<%=currentdate.toString()%>"/>
                        </c:otherwise>
                </c:choose>

Mohan

-----Original Message-----
From: Mohan Radhakrishnan [mailto:[EMAIL PROTECTED]
Sent: Monday, March 10, 2003 2:07 PM
To: 'Struts Users Mailing List'
Subject: bean:define and el tags


Hi

   I am trying to use simple if-else logic here.

        Date formatter -
        <jsp:useBean id="now" class="java.util.Date" />
        <fmt:formatDate var="currentdate" value="${now}"
pattern="dd/MM/yyyy"/>

   If my indexed property in the form returns null, I use the current date.

<c:choose>
<c:when test="${form.startDate[0] != null}">
<bean:define id="date" name="form" property='<%= "startDate[" + 0 + "]"
%>'/>
</c:when>
<c:when test="${form.startDate[0] == null}">
<bean:define id="date" value="<%=currentdate%>"/>
</c:when>
</c:choose>

This is to populate my html:text box like this

<html:text value="<%=date.toString()%>"

  Is something wrong here ? It seems that the variable "date" is not found
at runtime.

Thanks,
Mohan

---------------------------------------------------------------------
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]

Reply via email to