Pass backing bean field/variable on URL – JSF

Posted: November 28, 2012 in web


<p:commandButton action="#{bean.sendVIN(vin)}" value="Step2" />


    private Car car;

    public String sendID(String vin) {
        return String.format("step2?faces-redirect=true&vin=%s", vin);


		<f:viewParam name="vin" value="#{}"
			converter="#{carConverter}" />


@FacesConverter(forClass = Car.class)
public class CarConverter implements Converter {

    List<Car> cars;

    public CarConverter() {

    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if (cars == null) {
            return null;
        for (Car car : cars) {
            if (car.getVIN().equals(value)) {
                return car;
        return null;

    public String getAsString(FacesContext context, UIComponent component, Object object) {
        if (object == null) {
            return null;
        } else {
            return ((Car) object).getVIN();


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s