tags:

views:

1096

answers:

3

Below is what I'm trying to achieve. The problem is "errors" is not defined. If I remove my match logic, the errors are displayed on the web page. Is there anyway of evaluating the text the error contains?

<logic:messagesPresent>
    <tr>
        <td class="errorcicon"><img src="images/icon_caution.gif" width="18" height="18" alt="Caution" /></td>
        <td></td>
        <td colspan="4"><html:errors /></td>
    </tr>
</logic:messagesPresent>


<logic:match name="errors" property="text" value="Service Start date is required" >
    <% pageContext.setAttribute("NOORIGIONALSERVICEDATE", "-1");%>
</logic:match>
+1  A: 

I'm not sure the question you ask fits the problem. Take a look at the taglib documentation for <logic:messagesPresent>

I believe what you need is <logic:messagesPresent message="false"> which should look at the Globals.ERROR_KEY instead of the Globals.MESSAGE_KEY. The message attribute is "true" by default.

djensen47
How about some voting love for that answer?
djensen47
+1  A: 

This will fix your bug:

<logic:messagesPresent>
    <tr>
        <td class="errorcicon"><img src="images/icon_caution.gif" width="18" height="18" alt="Caution" /></td>
        <td></td>
        <td colspan="4"><html:errors /></td>
    </tr>
</logic:messagesPresent>

<logic:present name="errors">
    <logic:match name="errors" property="text" value="Service Start date is required" >
        <% pageContext.setAttribute("NOORIGIONALSERVICEDATE", "-1");%>
    </logic:match>
</logic:present>

logic:present allows you to test if a bean is in present in scope. In this case the code in the tag logic:present will be executed.

Fred
A: 

i will test this tomorrow but is suspect it won't work because the error i was getting said that the errors bean is not define in the scope.

therefor i think the logic present will cause an error too since the error bean is still not defined.

M

I don't think so. the aim of the tag logic present is to test if the bean is defined or not. So if the bean isn't defined the code in the tag will not be executed.
Fred
yes but i want it to exedute it so what i really want is the define the "error" message tag
If there is no error why do you want to execute it???
Fred
i want to perform a different task depending on the content of the error message this needs to be perfomed client side.
yes but you can't perform this action if there is no error!!!The tag logic:present tests if a bean error is stored in any scope. Then the tag logic:match allows you to specify what kind of error has occured.If you don't test the presence of the bean it will raise an error... You have to check it
Fred