Hide link based on whether a user is logged in in XPages

I know this has to be easy, but I am somewhat new to Xpages.

I have an Xpage that has a custom control that displays a series of links to views. If the user is not logged on (their username is Anonymous) I want to hide one of the links.

In the visible option of the link I selected “Compute Dynamically” and added in this code:

if(@UserName()==“Anonymous”){

return true;

}

else {

return false;

}

but the view is still visible. I tried “compute dynamicall” and “on load” and neither worked.

Any help would be greatly appreciated.

Subject: (Solved)

I just found my error.

Changing the code to

var userName:NotesName = session.createName(@UserName());

if (userName.getCommon() == “Anonymous”) {

false;

}

else {

true;

}

worked.

Subject: Quicker code - as suggested below.

I used:

return (@UserName() == “Anonymous”);

and

return (@UserName() != “Anonymous”);

Subject: it always bugs me

to see if statements whose “then” and “else” parts are True and False.

if (x == y) {

return false;

}

else {

return true;

}

is just a less efficient way to write:

return (x != y);

Subject: Must be a LotusScript developer! (wink, nudge)…