0

I am trying to open a view column link into new window or tab. I am not able to get through. I have used numerous ways like mentioned in some of the pages under same category. Here is my sample code.

<xp:viewColumn columnName="$5" id="viewColumn1"displayAs="link">
    <xp:this.pageUrl><![CDATA[#{javascript:try{
    var row = getComponent("viewPanel1").getChildren().toArray();
    var va= row[5].getValue();
    var href = "some html page";
    return href+"?confId="+va;
    }catch(e){

    }
    }]]></xp:this.pageUrl>

I have used below code to work around

<xp:viewColumn columnName="fname" id="viewColumn1" displayAs="hidden">
    <xp:link escape="true" target="_blank">
        <xp:this.text><![CDATA[#{javascript:try{view1.getColumnValue("lname");}catch(e)   {}}]]></xp:this.text>
        <xp:this.value><![CDATA[#{javascript:try{thisid = view1.getColumnValue("lname");
   var calculatedlink = "www.google.com";
   return calculatedlink}catch(e){}}]]></xp:this.value>
    </xp:link>
    <xp:viewColumnHeader value="First Name" id="viewColumnHeader1">
    </xp:viewColumnHeader>
</xp:viewColumn>
Naveen
  • 6,786
  • 10
  • 37
  • 85
Raj
  • 264
  • 1
  • 3
  • 18
  • I answered a similar question [here](http://stackoverflow.com/a/15222760/1047998) but I used the similar technique to your question. You would also want to look into [this question](http://stackoverflow.com/questions/10853134/open-document-in-new-tab-from-xpages-viewpanel). – Naveen Apr 22 '13 at 12:23
  • Thank you for your resopnse naveen. But I am not able to get through. If you want I will update the code which i used similar to your answer. – Raj Apr 22 '13 at 12:58
  • Actually I would suggest you to look into stwissel's answer. It seems to be a better option. – Naveen Apr 23 '13 at 02:48

1 Answers1

2

Raj, as a user I'm not pleased if you decide when to open a new tab or window. I do that (it is my browser after all). So you might consider your forced window opening. But if you have to....

Split the functionality: make a regular link, give the links a css class. Then use XSP.addOnLoad(...) to add target="_blank" to all the links with that css class. Keeps your code lean and makes it easy to remove.

It also opens the possibility to offer users a config option (to be stored in a cookie) if they want the new windows or not.

Let us know how it goes. :-) stw

stwissel
  • 20,110
  • 6
  • 54
  • 101
  • Thank you for your response. I did not get using above mentioned ways. I needed it urgent so I found some work around and got it..:) Now I am looking to include your advise for my further tasks. If I get through it I will surely mention it here. – Raj Apr 23 '13 at 12:03