简体   繁体   中英

Xpages-Data Table: On Click Event on Link if the Link has a specific label value

on my Xpage, i have a data table in which i load data from an array (arrayPerson)

a busy cat http://de.share-your-photo.com/img/1bf1672dec.jpg

In the first Column i have a link field (core control) from which i get different names.

What i try to solve is: If the Name is for Example "Thomas" i want to link to google.de But if the Name is "Katrin" i want to pop up a alert window with text in it eg alert.("No Link")) and no link to google, only the alert

<xp:link escape="true" id="link1">
<xp:this.text><![CDATA[#{javascript:arrayPerson[0]}]]>  </xp:this.text>
</xp:link>

Is this possible?

Set link's value to URL only if your condition eg arrayPerson[0] == 'Thomas' is true. Otherwise return an empty string (= click on link does "nothing").

Render an onclick event with client side code if the condition is opposite arrayPerson[0] != 'Thomas' . This executes the CSJS code with the alert box on click only if the rendered condition is true:

<xp:link
    escape="true"
    text="#{javascript:arrayPerson[0]}"
    id="link1"
    value="#{javascript:arrayPerson[0] == 'Thomas' ? 'http://www.google.de' : ''}">
    <xp:eventHandler
        event="onclick"
        submit="false"
        rendered="#{javascript:arrayPerson[0] != 'Thomas'}"
        script="alert('No Link')">
    </xp:eventHandler>
</xp:link>

There are two options.

One is to use the Events panel. Enter your if statement in the Client-Side event box. If the outcome of any Client-Side code is a boolean true value, Server-Side code runs. Otherwise Server-Side code doesn't run. So return true without an alert for "Thomas", but for "Katrin", give the alert then return false.

The other option is to compute the value property of the link. You'll compute by writing Server-Side JavaScript, but the result needs to be a string that can be parsed as Client-Side JavaScript , see example below. That's a big gotcha, but once you understand that, it's not too bad unless you need to output lots of CSJS.

<xp:this.value>
<![CDATA[#{javascript:if (arrayPerson[0]=="Katrin") {
return "alert('No Link');";
}
</xp:this.value>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM