Test for null

15 views
Skip to first unread message

aj

unread,
Apr 4, 2009, 7:20:50 PM4/4/09
to Orkut Developer Forum
In my widget I would like to change the messaging if the visitor does
not have the widget installed. But I don't see a way to perform this
check correctly

<Require feature="opensocial-0.9" />

<script xmlns:os="http://ns.opensocial.org/2008/markup" type="text/
os-data">
<os:ViewerRequest key="theviewer"/>
</script>

<script type="text/os-template">
<div if="${'theviewer' != ''}">
<p>1.Viewer is not null</p>
</div>

<div if="${empty theviewer }">
<p>2.Viewer is empty</p>
</div>

<div if="${ 'theviewer' =='' }">
<p>3.Viewer is empty</p>
</div>

</script>

1.Viewer is not null, is printed always
2.Viewer is empty , is never printed.
3.Viewer is empty, is never printed.

What is the correct syntax? Is this documented somewhere in entirety?

Thanks,
AJ

Gama

unread,
Apr 6, 2009, 11:35:21 AM4/6/09
to Orkut Developer Forum
Hi Aj,

I was having the same problem and them I had tried something direrent.
Try to use the code as follows:

<div if=${!theviewer}">
<p>4.Viewer is empty or null</p>
</div>

I hope this answers your problem.

I'm looking for a more updated documentation too. So if you have
already found let me know.

Best Regards,
Guilherme Gama

Badaro

unread,
Apr 6, 2009, 12:47:59 PM4/6/09
to Orkut Developer Forum
I asked the same question last week, and I'm still waiting for an
answer:
http://groups.google.com/group/opensocial-orkut/browse_thread/thread/e4fd97798a9ac9a6#

I few tests I already made, all failures:

<h5 if="${viewer == null}">Viewer does not have App (A)</h5>
<h5 if="${!viewer}">Viewer does not have App (B)</h5>
<h5 if="${typeof(viewer) == 'undefined'}">Viewer does not have App
(C)</h5>

Sample gadget here:
http://badaro.labone.net/ostemplates/gadget

Jota

unread,
Apr 6, 2009, 6:28:45 PM4/6/09
to opensoci...@googlegroups.com
Have you tried this:

<li if="${owner.isViewer}">__MSG_Your Ranking__</li>

<li if="${owner.isViewer eq null}">__MSG_Ranking__</li>


[]'s,
Jota

Badaro

unread,
Apr 7, 2009, 9:37:04 AM4/7/09
to Orkut Developer Forum
Jota,

This is not a test for what I want.

I need to tell if I have a viewer without the application, since in
these cases I can't access any information about the viewer, and I
need to adjust the layout of the profile.

Filipe Badaro

On Apr 6, 7:28 pm, Jota <jefferson.ru...@gmail.com> wrote:
> Have you tried this:
>
> <li if="${owner.isViewer}">__MSG_Your Ranking__</li>
>
> <li if="${owner.isViewer eq null}">__MSG_Ranking__</li>
>
> []'s,
> Jota
>
> On Mon, Apr 6, 2009 at 1:47 PM, Badaro <bad...@gmail.com> wrote:
>
> > I asked the same question last week, and I'm still waiting for an
> > answer:
>
> >http://groups.google.com/group/opensocial-orkut/browse_thread/thread/...

Apurv Gupta

unread,
Apr 9, 2009, 11:31:53 AM4/9/09
to opensoci...@googlegroups.com
Does <div if="${viewer}"> work for you?

Badaro

unread,
Apr 9, 2009, 6:57:05 PM4/9/09
to Orkut Developer Forum
No, it doesnt. But even if it did, it's not the problem. I already
have a working test for the "viewer has app" case: ${viewer !=null}

What I need is a working test for the negative case: "viewer does not
have app". I already made several tests, and none worked:

<h5 if="${viewer == null}">Viewer does not have App (A)</h5>
<h5 if="${!viewer}">Viewer does not have App (B)</h5>
<h5 if="${typeof(viewer) == 'undefined'}">Viewer does not have App
(C)</h5>

Apurv Gupta

unread,
Apr 9, 2009, 9:23:27 PM4/9/09
to opensoci...@googlegroups.com
<div if="${Cur.viewer != null}"> is what you need. Since viewer is not available, you have to use Cur to refer to it.

Bit offtopic,
Here's a little debugging tip that would help you see the data that os-data section generates.
- Open the application iframe in a new tab
- Remove parameter sanitize=1 and reaload
- view source of frame.
- You'll find a opensocial.data.DataContext.putDataSet( which has the result of evaluation of os-data section

Let me know if above doesn't work for you.

Vince

unread,
Apr 10, 2009, 9:53:57 PM4/10/09
to Orkut Developer Forum
Apurv - no go. I put the following in mine:

<div if="${Cur.viewer != null}">yes</div>
<div if="${Cur.viewer == null}">yes2</div>

yes2 appeared when I looked at my gadget on my own profile, and it
also said yes2 when my friend viewed my profile (my friend does not
have the app installed).

I find it hard to believe no one has a solution to this problem - I
guess I just figured most apps need to deal with a user not having the
app installed as a separate case.

Vince

unread,
Apr 10, 2009, 10:54:04 PM4/10/09
to Orkut Developer Forum
Apurv - following your advice, I found the following:

"opensocial-0.8":{"path":"http://%host%/
api","domain":"google.com","supportedFields":{"person":
["id","name","thumbnailUrl","nickname"],"filterType":
["all","hasApp"],"activityMediaItem":
["type","mimeType","url"],"activity":
["id","externalId","userId","appId","streamTitle","streamUrl","streamSourceUrl","streamFaviconUrl","title","body","url","mediaItems","postedTime"],"sortOrder":
["name"],"name":
["unstructured","familyName","givenName","additionalName","honorificPrefix,
honorificSuffix"]},"impl":"rpc","enableCaja":false}

There is nothing listed for id, name, givenName, familyName, etc.

As I said earlier, I tried

<div if="${Cur.viewer != null}">yes</div>
<div if="${Cur.viewer == null}">yes2</div>

for all three cases. I tried it for (a) owner viewing app on his own
profile, (b) visitor with app installed viewing app on friend's
profile, and (c) visitor withOUT app installed viewing app on friend's
profile.

In all 3 cases, "yes2" was output. I am not sure what this means, but
at the very least it means Cur.viewer shows no distinction between the
three cases.

Vince

unread,
Apr 12, 2009, 3:31:49 AM4/12/09
to Orkut Developer Forum
So - if the viewer doesn't have the application installed,
viewer.isOwner() and owner.isViewer() do not work. I need someway to
test if the person using the app is the owner or viewer, and the
script work whether or not the viewer has the app installed.
Opensocial has some real problems if you can't solve this simple
problem.

Apurv Gupta

unread,
Apr 12, 2009, 4:20:56 AM4/12/09
to opensoci...@googlegroups.com
Try ${Top.viewer == null}

Cur is valid only within a repeat.

Vince

unread,
Apr 12, 2009, 12:22:48 PM4/12/09
to Orkut Developer Forum
Still no luck. Here is my code:

<div if="${Cur.viewer != null}">yes</div>
<div if="${Cur.viewer == null}">yes2</div>
<div if="${Top.viewer != null}">yes3</div>
<div if="${Top.viewer == null}">yes4</div>

When I viewed the app as a visitor (without app installed), it output
yes2 and yes4. So far so good, right? But when I view my app as the
owner (view the app on my own profile), yes2 and yes4 is still output.
Why would yes2 and yes4 be output when I am the owner? Why would
Top.viewer and Cur.viewer be null??


On Apr 12, 4:20 am, Apurv Gupta <apurv.gu...@gmail.com> wrote:
> Try ${Top.viewer == null}ref:http://wiki.opensocial-templates.org/index.php?title=OpenSocial_Templ...
>
> Cur is valid only within a repeat.
>

Badaro

unread,
Apr 13, 2009, 10:25:42 AM4/13/09
to Orkut Developer Forum
Working test for all cases (finally!):

<h5 if="${owner.isViewer}">Viewer is Owner</h5>
<h5 if="${!owner.isViewer && viewer.code!=401}">Viewer has App</
h5>
<h5 if="${!owner.isViewer && viewer.code==401}">Viewer does not
have App </h5>

Apurv and Vijaya: I have been following closely the development of OS
Templates, and I can tell that you changed the behavior of the
templates - now, when the user is not identified, you return a JSON
like this one:

{"message":"unauthorized: Get profile permission denied.","code":401}

Can we assume this won't change in the future, and the tests I posted
above will continue to work?

Apurv Gupta

unread,
Apr 13, 2009, 11:12:06 AM4/13/09
to opensoci...@googlegroups.com
Unfortunately, I think this is buggy behavior. When we get 0.9 compliant, http error code of 401 should be treated as an error, and viewer should get null.

With full compliance of 0.9, if ="${viewer}" should work. Let me discuss it with the team and get back to you on the final resolution.

Badaro

unread,
Apr 13, 2009, 3:01:25 PM4/13/09
to Orkut Developer Forum
Please confirm this.

ashok

unread,
Apr 20, 2009, 8:28:02 AM4/20/09
to Orkut Developer Forum
<script type="text/os-template" xmlns:os="http://ns.opensocial.org/
2008/markup">
<os:xNavigateToApp>Send gift to a friend</os:xNavigateToApp>
</script>

Not working from profile to canvas page
pls let me know if there is any solution ?


On Apr 10, 6:23 am, Apurv Gupta <apurv.gu...@gmail.com> wrote:
> <div if="${Cur.viewer != null}"> is what you need. Since viewer is not
> available, you have to use Cur to refer to it.
> Bit offtopic,
> Here's a little debugging tip that would help you see the data that os-data
> section generates.
> - Open the application iframe in a new tab
> - Remove parameter sanitize=1 and reaload
> - view source of frame.
> - You'll find a opensocial.data.DataContext.putDataSet( which has the result
> of evaluation of os-data section
>

suresh govindhan

unread,
Apr 21, 2009, 7:57:54 AM4/21/09
to opensoci...@googlegroups.com
HAI FRIEND........................................................................................................
......................................................................
.....................................................................
..................................GOOD EVENING

 

Rajasekhar

unread,
May 4, 2009, 2:35:22 AM5/4/09
to Orkut Developer Forum
i am getting the JSON outpput from the httprequest .how can eval that
data and how to get that inner objects.

thanks
Sekhar

On Apr 10, 6:23 am, Apurv Gupta <apurv.gu...@gmail.com> wrote:
> <div if="${Cur.viewer != null}"> is what you need. Since viewer is not
> available, you have to use Cur to refer to it.
> Bit offtopic,
> Here's a little debugging tip that would help you see the data that os-data
> section generates.
> - Open the application iframe in a new tab
> - Remove parameter sanitize=1 and reaload
> - view source of frame.
> - You'll find a opensocial.data.DataContext.putDataSet( which has the result
> of evaluation of os-data section
>

eduardorochabr

unread,
May 4, 2009, 7:41:23 AM5/4/09
to Orkut Developer Forum
Reply all
Reply to author
Forward
0 new messages