Ajax suddenly not working - jsf

i got this error in my console.and suddenly the selectOneMenu did not fire any listener when the value changes.im using primefaces-3.0.M2.jar.
Unhandled by MetaTagHandler for type org.primefaces.component.behavior.ajax.AjaxBehavior
and this is my code in .xhtml file
<p:ajax actionListener="#{innovationManager.innovationAreaListener}" event="change" update="frmInnovation" />
anyone got any clue about this?

The <p:ajax> tag does not support the actionListener attribute. It should have been listener.
<p:ajax listener="#{innovationManager.innovationAreaListener}" event="change" update="frmInnovation" />
I wonder if you didn't omit some parts of the error message. The hint about the actionListener attribute should have been included in the exception message.

Related

jsf valuechangelistener not firing on checkbox deselect

I have a primefaces checkbox on a form with a valuechangelistener. The backing bean method gets called on checkbox select, but doesn't get called on deselect.
I'm using the same technique with almost identical code elsewhere in my application and it works fine on both select and deselect.
<p:selectBooleanCheckbox value="#{shareoutSlip.processed}"
valueChangeListener="#{orderFormBean.handleShareoutSlipProcessed}" >
<p:ajax />
</p:selectBooleanCheckbox>
Here is the valueChangeListener method (all it does for now is print a message to the console):
public void handleShareoutSlipProcessed(ValueChangeEvent vcEvent) {
logger.info("Shareout Slip Processed");
}
Is there anything else on my form that could be interfering with the method being called on checkbox deselect? I've put a h:messages tag on the form but I'm not seeing any validation messages.
Have you tried to call this method inside p:ajax tag?
<p:selectBooleanCheckbox value="#{shareoutSlip.processed}">
<p:ajax event="change" listener="#{orderFormBean.handleShareoutSlipProcessed}" />
</p:selectBooleanCheckbox>

Displaying an error message from a4j:jsFunction

I have this a4j:jsFunction below and an <h:message for="form" style="color:red" /> somewhere else on the page.
<h:form id="form">
<a4j:jsFunction id="createEvent" name="createEvent" immediate="true"
action="#{calendarController.createEvent()}"
data="#{calendarController}"
oncomplete="renderEvent(event.data.eventId, event.data.eventTitle)">
<a4j:param name="eventTitle"
assignTo="#{calendarController.eventTitle}" />
</a4j:jsFunction>
</h:form>
How do I add an error message produced in calendarController.createEvent()?
Tried it with context.addMessage("form", new FacesMessage(e.getMessage())); but it doesn't work. I get this error: WARNING: There are some unhandled FacesMessages, this means not every FacesMessage had a chance to be rendered.
With a4j:jsFunction you are just performing an Ajax call; the view is not refreshed and the other components will continue in their previous state.
Use the reRender attribute to force refreshing the h:message component.
I have had similar issue recently. I was using h:commandButton:
<h:commandButton id="buttonOK"
onclick = "#{rich:component('purchasePopup')}.hide(); finishPurchase();"
value="Ok"
styleClass="popupPrimary"
rendered="#{validationSeverity != 'ERROR'}"
type="button">
</h:commandButton>
I also had jsFunction which would be called on button click and call backing bean method. Backing bean was adding FacesMessages using addMessage method:
<a4j:jsFunction name="finishPurchase" action="finish" render="purchaseForm"/>
Solution was to add render="purchaseForm" because all tags were nested in this form.

f:setPropertyActionListener doesn't set the value however action is triggered

I need to set a boolean field whenever p:fieldset is toggled. I tried out following code but the field is never set by f:setPropertyActionListener although p:ajax listener is invoked on toggle. I tried out following code.
<p:fieldset legend="(Optional) Link.." toggleable="true">
<p:ajax event="toggle" listener="..">
<f:setPropertyActionListener target="#{viewScope.rendrUsrProjctsList}" value="#{true}"/>
</p:ajax>
</p:fieldset>
However when I tried modifying the code as below then field is successfully set:
<p:fieldset legend="(Optional) Link.." toggleable="true">
<p:ajax event="toggle" listener="#{view.viewMap.put('rendrUsrProjctsList', true)}" />
<p:ajax event="toggle" listener=".."/>
</p:ajax>
</p:fieldset>
I want to ask:
Why 1st way doesn't work ?
Is it bad attaching multiple p:ajax to
single parent as done in 2nd way ?
The <f:setPropertyActionListener> works as being an ActionListener implementation only on components implementing ActionSource interface, such as UICommand, i.e. <h:commandXxx>, <p:commandXxx>, etc. The <p:ajax> does not implement this interface and therefore the <f:setPropertyActionListener> is basically completely ignored.
As to your workaround, you could do so although I'd rather just use a concrete view scoped bean or wrap it in a composite with a backing component.

<h:selectOneRadio> value not updated in bean

<h:form>
<h:messages />
<h:selectOneRadio value="#{bean.selectedValue}" id="selectId"
layout="pageDirection">
<f:selectItems value="#{bean.values}" var="value"
itemLabel="#{value.text}" itemValue="{value}" />
</h:selectOneRadio>
<h:commandButton value="Press Me" >
<f:ajax listener="#{bean.btn_action}" execute="#form"/>
</h:commandButton>
</h:form>
Below are code details.
Bean is backing bean in #ViewScope.
bean.values is list of another managed bean which is in #RequestScope.
Radio button value is binded to above #RequestScope managed bean in backing bean. #{bean.selectedValue}
selectedValue is reference to object in backing bean having getter/setter.
Issues.
- When execute=#form is added to ajax tag, listener is not even called.
- After execute-#form, listener is getting called however radio button selected value is not updated in backing bean.
- When i debug getter is always called for selectedValue never the setter.
Any help will be appreciated.
Thanks.
Assuming that itemValue="{value}" is just a careless typo and that you never paid attention to the server logs, then this construct will silently fail if #{value} represents a non-standard type and you don't have a Converter for that type or didn't implement the type's equals() method properly.
First step would be adding render="#form" to <f:ajax>, so that <h:messages> get updated as well, so that you don't need to look into server logs for conversion/validation errors.
<f:ajax execute="#form" listener="#{bean.btn_action}" render="#form" />
Second step would be fixing the problem based on the shown conversion/validation error. Most likely you've a conversion error "null converter" or maybe you already have one, but you're getting a validation error "value is not valid" instead.
Both potential problems are answered in detail in the following answers:
How to populate options of h:selectOneMenu from database?
Using JSF Converter in h:selectOneMenu results in Validation Error: Value not valid

Ajax and Validator is not working together

When I am trying to insert a validator to a selectOneMenu element containing a ajax listener in JSF, the ajax listener begins to not working. The following is my JSF snipplet specific to issue I am talking:
<h:selectOneMenu id="metalCodes" converter="metalCodeConverter" required="true" requiredMessage="#{lang.metalStockIntroducing_metalCode_req_txt}" value="#{metalStockIntroducingProcessesBean.metal.metalCode}">
<f:selectItem itemLabel="Please select..." noSelectionOption="true" />
<f:selectItems value="#{metalStockIntroducingProcessesBean.metalCodesMenu}" />
<f:ajax listener="#{metalStockIntroducingProcessesBean.changeMetalType}" event="change" execute="metalCodes" render="metalTypesMenu" immediate="false"/>
<f:validator validatorId="densityValidator"/>
</h:selectOneMenu>
What would you friends recommend me to do in order to make the validator and ajax listener works collaborately in a h:selectOneMenu JSF element?
They ought to work fine together. The ajax listener method will only not be invoked when the validator threw an exception. Make sure that your validator isn't incorrectly doing that. Make sure that you're re-rendering the <h:message> or <h:messages> associated with the input component as well so that you get notified of any faces messages during an ajax request. Or at least read the server logs, any queued-but-not-displayed faces messages will be logged there.

Resources