BootsFaces DateTimePicker AJAX not working - ajax

In BootStrap calling a backend bean via AJAX does not seem to work for the DateTimePicker component.
If I am wrong with my code, could anybody please help?
To my surprise also the DateTimePicker reference page of BootStrap does not work with AJAX. On the reference page (https://showcase.bootsfaces.net/forms/DateTimePicker.jsf)
the reference code
<b:form>
<b:dateTimePicker value="#{test.dataToPick}" ondtchange="ajax:test.updateTestField()" process="#this" update="#next" label="Select date:" iconAwesome="bolt" />
<b:inputText value="#{test.testField}" label="Result: " readonly="true" />
</b:form>
is also not working.
Here is my code that is not working:
<b:form>
<b:dateTimePicker value="#{listBean.editMonth}"
readonly="false"
allow-input-toggle="false"
icon-position="right"
mode="popup"
format="MMM YYYY"
side-by-side="false"
show-date="true"
show-time="false"
show-icon="true"
required="true"
viewMode="months"
locale="en"
iconSize="xs"
styleClass="datePicker"
id="monthpicker"
process="#this"
ondtchange="ajax:listTradesBean.updateMonth()"
onblur="ajax:listTradesBean.updateMonth()"/>
</b:form>
Normally I would expect that the backend code "updateMonth()" would be called. The java code snippet for the backend bean simply is:
public void updateMonth() {
System.out.println("WORKING!");
}
Other methods within this backend bean are called without problems using AJAX.

You are right, the example in the Bootsfaces showcase page does not work.
Strangely enough, I managed to build a working example that solves your problem by using the traditional JSF AJAX (legacy) syntax:
<b:dateTimePicker id="datePicker"
format="DD/MM/YYYY HH:mm"
value="#{testBB.selectedDate}"
required="true"
renderLabel="false"
ajax="true"
process="#this"
update="#this"
ondtchange="#{testBB.doSomething()}">
</b:dateTimePicker>
As far as I know, this will work the same way as "ajax:testBB.doSomething()".

Related

oncomplete of p:commandButton not firing within ui:composition

The following code appears in a ui:composition page and uses a template, the template inserts this page using ui:insert.
<p:commandButton id="basic" value="Contact #{viewProfileView.profile.credentials.username}" onclick="PF('dlg1').show();" type="button" />
<h:form id="createMail">
<p:dialog id="createMailDialog" header="Contact #{viewProfileView.profile.credentials.username}" widgetVar="dlg1" modal="true" draggable="false">
<p:growl id="growl"/>
<p:inputTextarea value="#{viewProfileView.emailBody}"
rows="5" cols="80" maxlength="399"
counter="charsLeft"
counterTemplate=" {0} chars remaining."
autoResize="false" />
<h:outputText id="charsLeft" />
<p:commandButton id="sendMailButton" value="Send"
action="#{viewProfileView.sendMail}"
update="growl"
oncomplete="PF('dlg1').hide();"/>
</p:dialog>
</h:form>
I'm using latest JSF and Primefaces 5.1.
Everything works fine except for the oncomplete of the 'sendMailButton' commandButton fails to be called to close the dialog. I know this code works as I have put it in a page of its own and seen it working, it just doesnt want to work as part of a ui:composition with template.
Help would be most appreciated as i've been searching for an answer without luck.
UPDATE: If I change 'oncomplete' to 'onsuccess' it works, but only once, however this does not resolve my issue.
Many thanks.
It appears that it was the template that was causing problems. Working now.

JSF2 HTML5 input (email) does not update models

I've got a problem considering updating my backing-bean within an ajax-roundtrip in a JSF2 application if the value is bound to a html5 input type=email.
First of all, I created an "Html5InputRenderer", so that the JSF-runtime can create the html5-markup for a , in order to write
The central "magic" the "Html5InputRenderer does is:
markup.replaceAll("type=\"text\"", "type=\"email\"");
within the overridden method encodeEnd(..) of javax.faces.renderer.Renderer.
This h:input is put in to a form and enriched with f:ajax:
<h:form id="form">
<f:ajax render="testOut">
<h:inputText id="test" renderedType="email" value="#{testBean.value}" />
</f:ajax>
<h:outputText id="testOut" value="#{testBean.value}" />
</h:form>
The atribute 'renderedType' is the hint for the JSF-"Html5InputRenderer" to render the html5 markup for the h:input
Test the snippet. It will not update #{testBean.value} although an ajax roundtrip is invoked by the JSF-runtime.
Test the snippet removing the attribute 'renderedType', everything works like expected.

Listener not called by p:ajax on p:inputText

I want to implement custom filtering on a p:dataTable. In the header of the dataTable, I have a p:inputText that I want to filter the table via ajax. The problem I am having is that the bean method is not being called by the p:ajax tag. Here is the offending code snippet:
<h:form id="form1">
<p:dataTable id="selectTable" var="select"
selectionMode="multiple" rowKey="#{select.id}"
value="#{pc_Selectcourses.allCourses}">
<f:facet name="header">
<p:outputPanel>
Search For Courses Completed:
<p:inputText id="filterEntry" value="#{pc_Selectcourses.query}">
<p:ajax event="keyup" update=":form1:selectTable"
listener="#{pc_Selectcourses.filterListener}" />
</p:inputText>
</p:outputPanel>
</f:facet>
<!-- table columns here, etc. -->
</p:dataTable>
</h:form>
And the backing bean:
public void filterListener() {
System.out.println("Hello world, hope you're listening...");
}
When I type in the inputText, the Sysout is never printed. I also notice that my ajax notifier/status icon doesn't show any activity, so I doubt anything is happening.
Edit
I just tried dragging and dropping p:ajax from Eclipse's Palette into my xhtml code and it said to use this I needed to import libraries into my workspace. I let it go ahead and it added primefaces v3.2 jar file into Web_INF/lib. The p:ajax still doesn't work.
I am confused as to why it asked for this as all the Primefaces components have been working great all along. Is there possibly something wrong with the project setup?
I saw this same problem today. It turns out that in your backing bean, if you have a getter function for query but NOT a setter function, p:ajax won't call its listener. Since you didn't post that section of your Java code, I assume there's a good chance this is your problem.

Show modalpanel conditional validation JSF

After at all, I´m sorry for my english.
I have a problem showing a modalPanel.
I would like show a modalPanel if the validation of the form was correct and doesn´t show it if the validation fail.
<h:form>
<rich:calendar id="date" datePattern="dd-MM-yyyy"
value="#{Bean.startDate}" required="true"/>
<a4j:commandButton value="Accept" action="#{Bean.Action}"
onclick="if(#{empty facesContext.maximumSeverity}) #{rich:component('popUp')}.show();" />
</form>
The maximumSeverity doesn´t work here because when the page load at first time, maximumSeverity is empty.
Is possible call the validation of the lifecycle of JSF to know if the form is correct or not?
Thanks!
The onclick runs before the action is invoked. You need oncomplete instead.
If you're using JSF 2.0, it's by the way better to use FacesContext#isValidationFailed() instead as normal INFO messages also count in the severity.
<a4j:commandButton value="Accept" action="#{Bean.Action}"
oncomplete="if(#{not facesContext.validationFailed}) #{rich:component('popUp')}.show();" />

How to inject one JSF2 page into another with jQuery's AJAX

I'm using jQuery's .load function to load one JSF page into another.
This works really well until the loaded JSF page uses some AJAX functionality. When this happens, the parent JSF page's AJAX stops working. In fact, after the two pages are combined whichever page has its AJAX called next is the one that continues to work. The other page stops working. If I use the parent page first, the child breaks. If I use the child first, the parent breaks.
Am I doing something wrong? I'm guessing JSF isn't designed for this sort of behaviour and that's fine but then how do I go about doing what I want?
Basically, we have a report page. When the user clicks the link to a report we would like the report to load dynamically into the existing page. That way, the user doesn't experience a page refresh. It's a pretty slick behaviour BUT obviously isn't ideal due to the pages breaking.
I suppose I could do this with a page that contains every report in an outputpanel and then determine which one is rendered based on a value in the backing bean but I can see lots of occasions where I'd like to be able to "inject" one page into another (for dynamic dialogs for instance) and it would suck to have to keep everything in one giant template.
Has anyone else come across this sort of problem? How did you solve it?
Do not use jQuery.load(). It does not take JSF view state into account at all, so all forms will fail to work. Rather make use of <f:ajax> and rendered attribute instead. Here's a basic example:
<h:form id="list">
<h:dataTable value="#{bean.reports}" var="report">
<h:column>#{report.name}</h:column>
<h:column>
<h:commandLink value="Edit" action="#{bean.edit(report)}">
<f:ajax render=":edit" />
</h:commandLink>
</h:column>
</h:dataTable>
</h:form>
<h:form id="edit">
<h:panelGrid columns="3" rendered="#{not empty bean.report}">
<h:outputLabel for="name" value="Name" />
<h:inputText id="name" value="#{bean.report.name}" required="true" />
<h:message for="name" />
...
<h:panelGroup />
<h:commandButton value="save" action="#{bean.save}" />
<h:messages globalOnly="true" layout="table" />
</h:panelGrid>
</h:form>
You can if necessary split off the content into an <ui:include>.

Resources