Rich-Faces

Toggle view

Implementing Logon Forms with JSF

Implementing a logon form with JSF has been alwys a bit troublesome. This requires form input elements with input names j_username and j_password. With the JSF RI this is hard to accomplish. So you typically end up with including the Apache MyFaces Tomahawk components which offer a forceId attribute.





If you are using other popular JSF component libraries, things might get a bit more handy (you can avoid including tomahawk just for fully controlling the input ids!).

With Myfaces Trinidad (Oracle ADF Faces) it is pretty easy, ids are accepted as they are:





With JBoss Rich-Faces use the a4j:form tag:


	
	
	
	

Keep Rich-Faces modal panel open when form validation errors occur

Keeping a model panel open after form validation produced errors is a bit puzzling. I found some good hints in the Rich-Faces Developer Guide
-you need a few lines of JavaScript though;(
The guide refers to a Rich-Faces Wiki article and a forum posting.

I have slightly modified the solution. On top of the page (outside the modal panel) I added a hidden form field that just indicates if validation messages exist.


	
		
	

The method property hasMessages is implemented as follows:

public boolean isHasMessages() {
	return FacesContext.getCurrentInstance().getMessages().hasNext();
}

The button uses the oncomplete attribute to test the hasMessages element with a little bit of Javascript.


green red blue grey