Primefaces CommandLink

Filed Under: JSF

Today we will look into Primefaces CommandLink component. Primefaces CommandLink extends standard JSF commandLink with Ajax capabilities.

Primefaces CommandLink

Below table contains some of the basic information of Primefaces CommandLink component.

TagcommandLink
Component Classorg.primefaces.component.commandlink.CommandLink
Component Typeorg.primefaces.component.CommandLink
Component Familyorg.primefaces.component
Renderer Typeorg.primefaces.component.CommandLinkRenderer
Renderer Classorg.primefaces.component. commandlink.CommandLinkRenderer

Primefaces CommandLink Attributes

NameDefaultTypeDescription
idnullStringUnique identifier of the component
renderedtrueBooleanBoolean value to specify the rendering of the component, when set to false component will not be rendered.
bindingnullObjectAn el expression that maps to a server side UIComponent instance in a backing bean
valuenullStringHref value of the rendered anchor.
actionnullMethodExpr/ StringA method expression or a String outcome that’d be processed when link is clicked.
actionListenernullMethodExprAn actionlistener that’d be processed when link is clicked.
immediatefalseBooleanBoolean value that determines the phaseId, when true actions are processed at apply_request_values, when false at invoke_application phase.
asyncfalseBooleanWhen set to true, ajax requests are not queued.
processnullStringComponent(s) to process partially instead of whole view.
ajaxtrueBooleanSpecifies the submit mode, when set to true(default), submit would be made with Ajax.
updatenullStringComponent(s) to be updated with ajax.
onstartnullStringClient side callback to execute before ajax request is begins.
oncompletenullStringClient side callback to execute when ajax request is completed.
onsuccessnullStringClient side callback to execute when ajax request succeeds.
onerrornullStringClient side callback to execute when ajax request fails.
globaltrueBooleanDefines whether to trigger ajaxStatus or not.
delaynullStringIf less than delay milliseconds elapses between calls to request() only the most recent one is sent and all other requests are discarded. If this option is not specified, or if the value of delay is the literal string ‘none’ without the quotes, no delay is used.
partialSubmitfalseBooleanEnables serialization of values belonging to the partially processed components only.
resetValuesfalseBooleanIf true, local values of input components to be updated within the ajax request would be reset.
ignoreAutoUpdatefalseBooleanIf true, components which autoUpdate=”true” will not be updated for this request. If not specified, or the value is false, no such indication is made.
stylenullStringStyle to be applied on the anchor element
styleClassnullStringStyleClass to be applied on the anchor element
onblurnullStringClient side callback to execute when link loses focus.
onclicknullStringClient side callback to execute when link is clicked.
ondblclicknullStringClient side callback to execute when link is double clicked.
onfocusnullStringClient side callback to execute when link receives focus.
onkeydownnullStringClient side callback to execute when a key is pressed down over link.
onkeypressnullStringClient side callback to execute when a key is pressed and released over link.
onkeyupnullStringClient side callback to execute when a key is released over link.
onmousedownnullStringClient side callback to execute when a pointer button is pressed down over link.
onmousemovenullStringClient side callback to execute when a pointer button is moved within link.
onmouseoutnullStringClient side callback to execute when a pointer button is moved away from link.
onmouseovernullStringClient side callback to execute when a pointer button is moved onto link.
onmouseupnullStringClient side callback to execute when a pointer button is released over link.
accesskeynullStringAccess key that when pressed transfers focus to the link.
charsetnullStringCharacter encoding of the resource designated by this hyperlink.
coordsnullStringPosition and shape of the hot spot on the screen for client use in image maps.
dirnullStringDirection indication for text that does not inherit directionality. Valid values are LTR and RTL.
disablednullBooleanDisables the link
hreflangnullStringLanguae code of the resource designated by the link.
relnullStringRelationship from the current document to the anchor specified by the link, values are provided by a space-separated list of link types.
revnullStringA reverse link from the anchor specified by this link to the current document, values are provided by a space-separated list of link types.
shapenullStringShape of hot spot on the screen, valid values are default, rect, circle and poly.
tabindexnullIntegerPosition of the button element in the tabbing order.
targetnullStringName of a frame where the resource targeted by this link will be displayed.
titlenullStringAdvisory tooltip information.
typenullStringType of resource referenced by the link.

Primefaces CommandLink Example

Primefaces CommandLink is similar to JSF h:commandLink except that the form is submitted with ajax by default.

simpleCommandLink.xhtml


<html xmlns="https://www.w3.org/1999/xhtml"
	xmlns:ui="https://java.sun.com/jsf/facelets"
	xmlns:h="https://java.sun.com/jsf/html"
	xmlns:f="https://java.sun.com/jsf/core"
	xmlns:p="https://primefaces.org/ui">
<h:head>
	<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form>
	<p:commandLink value="Do Action" action="#{commandLinkManagedBean.doSomeAction}"></p:commandLink>
</h:form>
</html>

package com.journaldev.primefaces.beans;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class CommandLinkManagedBean {
	public String doSomeAction(){
		System.out.println("CommandLink is used");
		return "";
	}
}

Below image shows the console output when you click on the Primefaces CommandLink link multiple times.

Primefaces CommandLink - Simple CommandLink

That’s all for a quick roundup on Primefaces CommandLink component. You can download the Primefaces CommandLink example project from below link.

Comments

  1. Denis Duval says:

    Hello,
    I’m using Primefaces in a web project.
    If I use p: commandLink (with ajax = false) or h: commandLink to display a next page,
    a blank page appears quickly, and then displays correctly.
    How to remove this blank page ?
    Is there a solution ?
    THANK YOU!

  2. sudhir kumar says:

    Good work

Leave a Reply

Your email address will not be published. Required fields are marked *

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages