Just another site

Category Archives: JSF

Request URI too long

I had a task to add a link in a chart. Depends on the area user clicks,  the system will create a get request, forward the user to next page.  The URL looks like “http://localhost:8080/nextpage?q=para1:1,2,3,4;para2:3,2,2,3;para3:test1,test2,test..”. The URL becomes too long and gives an error in the browser: request URI too long.

All we need to do is to change the request to post request. We create a hidden form on the page, which contains one input field and one button. the input field is used to save the parameters value (q in the example), and when user click the chart. I set the parameters value to the input field, then trigger a click on the button to submit the form.

And the code in javascript listener:


JSF execute javascript after ajax call

To Execute js script after the f:ajax call

<h:selectOneMenu id="checklist" value="#{checklistReportAction.checklist}" required="true">
      <s:selectItems value="#{checklistReportAction.checklists}" var="_checklist"
        label="#{}" noSelectionLabel="Select Checklist..."/>
        <s:convertEntity />							 	
	<f:ajax  render="filterPanel checklistFieldPanel" listener="#{checklistReportAction.selectListener}" event="change" execute="@this" onevent="showCheckBox"/>

The above code will call showCheckbox function after user change value for the dropdown list

Enter key to submit form in JSF

Add a hidden button in the form:

<h:commandButton id="hiddenSearch" style="visibility: hidden;" action="#{}"/>

value is not valid in h:selectonemenu convertor Validation

The equals method of the entity should return true. What happened in my case is that the entity is lazy loaded, which got a class type of lazyinitializer.  overwrite the equals method solve the problem:

remove this code:

if (getClass() != obj.getClass())
return false;


clear entered value in model panel

We could use facescontext to clear entered data in model panel.

selectedCustomer = null;

FacesContext context  = FacesContext.getCurrentInstance();
return "";

jsf popup panel validation

Around the content with s:validateAll tag, and then add oncomplete attribute on the save button.

<a4j:commandButton oncomplete=”if (#{facesContext.maximumSeverity == null}){Richfaces.hideModalPanel(‘trackingFieldPanel’)}”/>
If there’s any validation error, the window will stay open.

validation on jsf popup model panel

if validation failed , popup should remain open

msgPanel is the output panel inside the  popup model panel

<a4j:commandButton id=”saveActivity” action=”#{createActivity.saveActivity}” value=”Save”
styleClass=”btn alignright btn_green smallFont” reRender=”msgPanel,activitiesList”
oncomplete=”if (#{facesContext.maximumSeverity == null}){closeModalPanel(‘activityPanel’);return false}”/>

CDATA and javascript

&& are not valid characters in XML so they are also not valid for Facelets as well.
Use script in CDATA to get full javascript support in Facelets . CDATA is used like this :


function check(){
if (isCondition1 &&  !isCondition2){
alert(“Please input a valid number!”)

“The converter works with any managed entity”.

if we have to include unmanaged entity into selectone menu, we will need manually create select items.

Jsf page:

<h:selectOneMenu id=”contact” required=”true” styleClass=”input”  value=”#{}” >
<f:selectItems value=”#{newCustomerController.newCustomerContacts}”/>

java code to generate select items:

for(Contact contact : selectedCustomer.getContacts()) {
SelectItem item = new SelectItem();
item.setLabel(contact.getFirstName() + ” ” + contact.getLastName());

Property not found on type org.hibernate.collection.PersistentSet

JSF doesn’t support dataTable backed by Sets (Seam does if you use @DataModel).