August 9, 2012

af:inputFile component


<af:inputFile /> component is useful to browse and select file to upload. Hence, whenever we want to accept files from users, we can display this component on the JSF page. But to get the selected values from this component the “usesUpload” attribute of the form should be set to “true”, otherwise it returns null always.

<af:form id="f1" usesUpload="true">

<af:inputFile label="Image File" id="if1" />

</af:form>

August 7, 2012

Getting current record of data control from program

By using the below code, we can get the current row from the data control.

BindingContext bindingctx = BindingContext.getCurrent();
BindingContainer bindings = bindingctx.getCurrentBindingsEntry(); 
DCBindingContainer bindingsImpl = (DCBindingContainer)bindings; 
DCIteratorBinding iter =  bindingsImpl.findIteratorBinding(<binding iterator>); 
Row currentRow=iter.getCurrentRow();

Where <binding iterator> is the iterator name which data control is binded to the page and holds the data

Getting Request and Response Object of JSF page


By using the below statements we can get the Request and Response objects of the JSF page.

(HttpServletRequest)javax.faces.context.FacesContext.getCurrentInstance().getExternalContext().getRequest();

(HttpServletResponse)javax.faces.context.FacesContext.getCurrentInstance().getExternalContext().getResponse();