Book Image

Primefaces Cookbook Second Edition

Book Image

Primefaces Cookbook Second Edition

Overview of this book

Table of Contents (20 chapters)
PrimeFaces Cookbook Second Edition
Credits
Foreword
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Spinner – different ways to provide input


The input component spinner provides a numerical input via increment and decrement buttons.

How to do it…

A basic definition of the component would be as follows:

<p:spinner value="#{spinnerBean.intValue}" />

This will render an input textbox on the page, with controls to increase and decrease the value as shown in the following screenshot:

There's more…

The stepFactor attribute defines the stepping factor that will be applied for each increment and decrement with the default value 1. The following definition will increase or decrease the value by 0.5:

<p:spinner value="#{spinnerBean.doubleValue}" stepFactor="0.5" />

Adding prefix and suffix

The prefix and suffix attributes provide the ability to place fixed strings on the input field as a prefix or suffix to the input respectively. The first definition will render the $ sign as a prefix, and the second one will render the % sign as a suffix with the value of the input field:

<p:spinner value...