Sunday, October 14, 2007

JSF immediate attribute

Usage of JSF immediate attribute can lead to a variety of issues, so it is a handle with care piece will one learns the JSF life cycle, different phases and the bypassing through immediate. For more, check:

ClearInputComponents - Myfaces Wiki

Labels: , ,

Tuesday, October 09, 2007

Enterprise Java Community: Building Custom JSF UI Components

Fixing Required messages in JSF

Another interesting phase listener for required messages Fixing Required messages in JSF

JSF 1.2 components already support requiredMessage attribute, so this may not be handy there.

Customizing JSF Required Field Messages per Component Instance is another flavour of the same.

Labels: , ,

Designing and Implementing Web Application Interfaces

Wonderful use of phase listeners in JSF : Designing and Implementing Web Application Interfaces

It outlines how JSF can be enhanced to define custom error messages per component. Mst read for all those who are on JSF 1.1

Labels: , ,

Friday, October 05, 2007

JSF dropdown with BigInteger keys

We wanted to create a drop down with JSF which had keys as java.math.BigInteger and labels as strings. The drop down was to be pre selected with a value. If everything is string, string, thinds work well. However, the drop down value is not prepopulated if it is bound to a BigInteger. Eventually, we were able to solve this with the following code:

JSP




<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
\"http://www.w3.org/TR/html4/loose.dtd\">
<%@ page contentType=\"text/html;charset=windows-1252\"%>
<%@ taglib uri=\"http://java.sun.com/jsf/html\" prefix=\"h\"%>
<%@ taglib uri=\"http://java.sun.com/jsf/core\" prefix=\"f\"%>
<f:view>
<html>
<head>
<meta http-equiv=\"Content-Type\"
content=\"text/html; charset=windows-1252\"/>
<title>ConversionTrial</title>
</head>
<body><h:form>
<h:selectOneMenu id=\"menu\" value=\"#{ConversionBean.dto.code}\">
<f:selectItems value=\"#{ConversionBean.valueList}\"/>
</h:selectOneMenu>
</h:form></body>
</html>
</f:view>



Managed Bean



package view;



import java.math.BigInteger;



import java.util.ArrayList;



import javax.faces.model.SelectItem;



public class ConversionBean {

    private DTO dto;

    private ArrayList valueList;

    

    public ConversionBean() {

        dto = new DTO(new BigInteger(\"10\"), \"Large\");

    }

    

    public ArrayList getValueList(){

        valueList = new ArrayList();

        valueList.add(new SelectItem(new BigInteger(\"0\"), \"Small\"));

        valueList.add(new SelectItem(new BigInteger(\"5\"), \"Medium\"));

        valueList.add(new SelectItem(new BigInteger(\"10\"), \"Large\"));

        

        return valueList;

    }

    

    public DTO getDto(){

        return this.dto;

    }

}



DTO




package view;



import java.math.BigInteger;



public class DTO {

    private BigInteger code;

    private String val;

    

    public DTO(BigInteger code, String val) {

        this.code = code;

        this.val = val;

    }

    

    public void setCode(BigInteger s){

        System.out.println(\"setCode to \" + s);

        this.code = s;

    }

    

    public BigInteger getCode(){

        System.out.println(\"getCode returns \" + code);

        return this.code;

    }

}

Labels: , ,