Question

I've been searching and found things such as this link, but I am already calling the ID in the f:ajax.

I'm trying to validate the input from the first code block as an integer; this field is also looked at by a boolean check box, that allows the users to check a box, and it copy over the data to the other section of the form. I can get the value from the first block to copy to the third, and I can get the value from the first code block to validate if I remove the f:ajax, but I cannot get the rich:message validation to work with the f:ajax call, in spite of using the ID and it being in a panel group. What am I doing wrong?

Trying to validate:

<h:outputLabel for="fireDrillStaffQuantity" value="Staff Quantity:"/>
<h:panelGroup>
    <h:inputText id="fireDrillStaffQuantity" value="#     {fireDrillBean.fireDrill.fireDrillStaffQuantity}" style="width: 175px;">
         <f:ajax event="change" execute="@this" bypassUpdates="#{true}"/>     
    </h:inputText>
    <rich:message for="fireDrillStaffQuantity" ajaxRendered="true"/>    
</h:panelGroup> 
<h:outputText value="*"/>

The boolean check box:

<h:outputLabel for="disasterDrillCopyTime" value="Use Fire Drill Data?"/>
<h:selectBooleanCheckbox value="#{fireDrillBean.copyTimes}" id="disasterDrillCopyTime"> 
    <a4j:ajax event="change" execute="@this" render="disasterDrillStartTime,disasterDrillEndTime,disasterDrillStaffQuantity,disasterDrillStaffInitials,disasterDrillSupportedQuantity,disasterDrillSupportedInitials"/>      
</h:selectBooleanCheckbox>
<h:outputText value=""/>

The field that the first block gets copied to:

<h:outputLabel for="disasterDrillStaffQuantity" value="Staff Quantity:"/>
<h:inputText id="disasterDrillStaffQuantity" value="#{fireDrillBean.fireDrill.disasterDrillStaffQuantity}" style="width: 175px;">
    <a4j:ajax event="change" execute="@this"  bypassUpdates="#{true}"  render="disasterDrillStaffQuantity"/>
</h:inputText>
<h:outputText value="*"/>

In other parts of the form, I can get validation using an a4j:ajax call (below) but I don't know how to incorporate this into an item already using the f:ajax

<a4j:ajax event="blur" bypassUpdates="true" execute="@this" /> 

And just for a sanity check, here is the header of my xhtml file:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:forgeview="http://jboss.org/forge/view"
    xmlns:rich="http://richfaces.org/rich"  
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:p="http://java.sun.com/jsf/html"
    template="/resources/scaffold/pageTemplate.xhtml">
Was it helpful?

Solution

Ah, ok. You're using @ajaxRendered="true" which means that the message has to be rendered by some ajax action.

You can either use @render in the <f:ajax> (and the message has to have an id)

<f:ajax … render="message" />
<rich:message id="message" … />

or you can use <a4j:ajax> instead (the attributes are the same) that will rerender the message automatically. Or you can not use the @ajaxRendered.

Also note that the change event doesn't trigger when you change the value of the input, it triggers after the input loses focus. If you want the input to validate as you're typing you should use keyup.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top