Chris Loschen wrote:
As I understand it, this would return the error only if there are no
messages at all in the application resource, which is not at all likely
in this context. We're testing whether a particular application resource
(that is, a particular key-value pair in the application resource file)
is empty, not the whole file.

No, it should return the error only if the resource named resource string exists. The key is the 'special' property name 'message(foo)', which translates into 'messages.getMessage("foo").

For me, if 'foo' is a valid message key I get the body of the <logic:notEmpty/> tag displayed; if 'foo' is not defined in my resource bundle, I don't.

That said, I still didn't get the results I had hoped for with the new
version either, unfortunately. I didn't get any errors, but it returned
true even when the value was empty. For example, when I had an
application resource key set up like so:

module.admin.manageHierarchy.businessStruc.add.directionToUser=

Hmm, I hadn't tried that; I just tested it and it worked for me.

And my JSP code is set up like this:

        <bean:define id="messages"
name="org.apache.struts.action.MESSAGE"/>
     <logic:notEmpty name="messages"
property="message(<%=directionToUserKey.toString()%>)">
         <div class="modFormBox"><bean:message
key="<%=directionToUserKey.toString()%>"/></div>
     </logic:notEmpty>

It returns notEmpty as true, because I get this in the page:

         <div class="modFormBox"></div>

I presume it must be testing that the key exists and is non-zero-length
rather than testing the value. Oh well.

That's odd. Here's a copy/paste of my test, which works as expected:

    <bean:define id="messages" name="org.apache.struts.action.MESSAGE"/>
    <logic:notEmpty name="messages" property="message(errors.cancel)">
        <p>test 1</p>
    </logic:notEmpty>

    <bean:define id="messages" name="org.apache.struts.action.MESSAGE"/>
<logic:notEmpty name="messages" property="message(errors.cancel.missing)">
        <p>test 2</p>
    </logic:notEmpty>

    <% String foo = "errors.cancel.missing"; %>
    <bean:define id="messages" name="org.apache.struts.action.MESSAGE"/>
    <logic:notEmpty name="messages" property="message(<%=foo%>)">
        <p>test 3</p>
    </logic:notEmpty>

That gives me a single paragraph, 'test 1'. Works whether 'errors.cancel.missing' is actually missing, or defined with an empty value as in your example.

If it doesn't work for you I'm out of ideas! :-/

L.


Chris

-----Original Message-----
From: Nitish Kumar [mailto:[EMAIL PROTECTED] Sent: Monday, June 13, 2005 12:54 AM
To: 'Struts Users Mailing List'
Subject: RE: Test whether an application resource is empty


<bean:define id="messages" name="org.apache.struts.action.MESSAGE"/>

I dont understand some things here, If the application resource is empty
above code would throw this error, "Define tag cannot set a null value".


So how does this code helps in checking wether an application resouce is
empty?

Am I missing some thing here? or may be the subject is misleading..

Thanks and Regards,
Nitish Kumar
Tavant Technologies Ltd
Bangalore


-----Original Message-----
From: Laurie Harper [mailto:[EMAIL PROTECTED]
Sent: Sunday, June 12, 2005 6:30 AM
To: user@struts.apache.org
Subject: Re: Test whether an application resource is empty


Doh, I'm an idiot! :-( What I suggested is like trying to call getFoo()
on the resource bundle bean, where 'Foo' is what ever
<%=directionToUserKey.toString()%> evaluates to. Clearly not what's
needed. The following works for me:

     <bean:define id="messages"
name="org.apache.struts.action.MESSAGE"/>
     <logic:notEmpty name="messages" property="message(errors.cancel)">
         <p>using Struts bean/logic</p>
     </logic:notEmpty>

Just replace 'errors.cancel' with '<%=directionToUserKey.toString()%>' and you should be set.

Sorry for the confusion,

L.

Chris Loschen wrote:

Thanks again, Laurie, but for some reason it still returns false every


time, even if there is something under that key. I'm pretty sure I followed your directions exactly:

        <tiles:useAttribute id="directionToUserKey"
name="directionToUserKey" scope="request" classname="java.lang.String"
ignore="true"/>
        
        <logic:present name="org.apache.struts.action.MESSAGE"
property="<%=directionToUserKey.toString()%>">
<div class="modFormBox"><bean:message key="<%=directionToUserKey.toString()%>"/></div>
        </logic:present>

Although I did have to pull the key back out of the request in my second tile -- do I have to do that here as well? I may have to give up for now, since I have it working the other way, but I'm still curious what I did wrong.

Chris

-----Original Message-----
From: news [mailto:[EMAIL PROTECTED] On Behalf Of Laurie Harper
Sent: Friday, June 10, 2005 2:49 PM
To: user@struts.apache.org
Subject: Re: Test whether an application resource is empty

You want to use the name of the attribute the resource bundle is stored under, not the name of the properties file. You're not specifying it in your Struts config so you want the following:

  <logic:present name="org.apache.struts.action.MESSAGE"
      property="<%=directionToUserKey.toString()%>">
    <div class="modFormBox">...</div>
  </logic:present>

L.

Chris Loschen wrote:


Thanks Laurie,

I tried to set it up this way, but wasn't able to make it work. My struts-config file defines the message-resources parameter like so:

        <message-resources parameter="ApplicationResources"
null="false"/>

So I tried putting that in, and also tried some variants like org.apache.struts.ApplicationResources and org.apache.struts.util.MessageResources in code like this:

        <tiles:useAttribute id="directionToUserKey"
name="directionToUserKey" scope="request" classname="java.lang.String"
ignore="true"/>
        
        <logic:present name="ApplicationResources"
property="<%=directionToUserKey.toString()%>">
<div class="modFormBox"><bean:message key="<%=directionToUserKey.toString()%>"/></div>
        </logic:present>

But it always returned false, even if there was a value for the key, so I apparently set up something wrong.

I did get it working using the alternate path, however -- I set up a new tile in the tiles-defs file which was defined as a zero-length file in the default case and a small JSP for those cases where I had

directions.


The calling JSP looks like this:

        <tiles:useAttribute id="directionToUserKey"
name="directionToUserKey" scope="request" classname="java.lang.String"
ignore="true"/>
        
        <!-- Next is the inserted tile -->
        <tiles:insert attribute="directionToUserTile"/>

And the inserted tile (when I insert a non-zero-length file) looks like
this:

<%
        String directionsKey = (String)
request.getAttribute("directionToUserKey");
%>

<div class="modFormBox"><bean:message key="<%=directionsKey%>"/></div>

That is working ok, though of course I don't have the flexibility of having a value for some locales and no value for other locales. That's


not terribly important.

By the way, just for my own learning: I initially tried to put the attribute in page scope, but I kept getting a null value: is page scope specific to a particular JSP (I would have thought that was tile


scope...), or should it be available throughout the sub-elements of a given page? It works when I use request scope instead, but is that what is required here?

Thanks again for everyone's help!

Chris Loschen

-----Original Message-----
From: news [mailto:[EMAIL PROTECTED] On Behalf Of Laurie Harper
Sent: Thursday, June 09, 2005 7:07 PM
To: user@struts.apache.org
Subject: Re: Test whether an application resource is empty

Try:

 <tiles:useAttribute name="directionToUser" ...
 <logic:present name="org.apache.struts...
                property="<%=directionToUser.toString()%>">
   <div class="modFormBox">...</div>
 </logic:present>

where 'name' is the name of the attribute your resource bundle is stored under.

L.

Chris Loschen wrote:




Hi Wendy,

Thank you very much for your reply.

Yes, I also thought that I could test the key, then check to see if the value was empty. But just how to do it is eluding me. I think part


of the problem might be this:

USAGE NOTE - If you use another tag to create the body content (e.g.
bean:write), that tag must return a non-empty String. An empty String


equates to an empty body or a null String, and a new scripting variable cannot be defined as null. Your bean must return a non-empty


String, or the define tag must be wrapped within a logic tag to test for an empty or null value.

(from the Struts User Guide for bean:define at http://struts.apache.org/userGuide/struts-bean.html#define).

I'm trying to do something like

        <tiles:useAttribute name="directionToUser"
classname="java.lang.String"/>
        
        <bean:define id="directionToUserString"
class="java.lang.String">
                <bean:message key="<%=directionToUser.toString()%>"/>
        </bean:define>

        <logic:notEmpty name="directionToUserString">
<div class="modFormBox"><bean:write name="directionToUserString"/></div>
        </logic:notEmpty>

But it's failing (I think) because the bean:message returns an empty String. I would wrap it in a logic tag as suggested, but if I could do


that, I'd just use the same logic for my logic:notEmpty tag instead. So finding a way to take that value and assign that to a variable which I can then test to see whether or not it's empty is what I'm

trying to do.



It was not my idea to add all of these empty i18n values: the i18n team did it. If I can't find a way to make this idea work, that's my alternate path. If that's the road I need to take, I can do it -- I was just hopeful I could do this a little more elegantly.

Thanks for your input. Any further ideas?

Chris

-----Original Message-----
From: Wendy Smoak [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 09, 2005 11:52 AM
To: Struts Users Mailing List
Subject: Re: Test whether an application resource is empty

From: "Chris Loschen" <[EMAIL PROTECTED]>

Quick synopsis: I have localized i18n messages defined in my tiles definitions which are sometimes empty. I need to test that the value


associated with a given key is not empty before I proceed with further


processing. I can test that the key is non-empty, but I haven't yet figured out how to test the same thing for the value.


If you can test the key, then it would seem that removing the empty messages would solve the problem. Why are the empty ones there in the


first place?
Can you get rid of them?

--
Wendy Smoak



_______________
Siebel
IT'S ALL ABOUT THE CUSTOMER
Visit www.siebel.com

This e-mail message is for the sole use of the intended recipient(s) and

contains confidential and/or privileged information belonging to Siebel
Systems, Inc. or its customers or partners. Any unauthorized review,
use, copying, disclosure or distribution of this message is strictly
prohibited.
If you are not an intended recipient of this message, please contact the
sender by reply e-mail and destroy all soft and hard copies of the
message and any attachments. Thank you for your cooperation.


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





_______________
Siebel
IT'S ALL ABOUT THE CUSTOMER
Visit www.siebel.com

This e-mail message is for the sole use of the intended recipient(s) and 
contains confidential and/or privileged information belonging to Siebel 
Systems, Inc. or its customers or partners. Any unauthorized review, use, 
copying, disclosure or distribution of this message is strictly prohibited. If 
you are not an intended recipient of this message, please contact the sender by 
reply e-mail and destroy all soft and hard copies of the message and any 
attachments. Thank you for your cooperation.


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

Reply via email to