BootsFaces does not render area from ajax - jsf

I am trying to render a data table using ajax (BootsFaces) according to the values provided in the form. Unfortunately, desired part does not render. I can see the ajax request is going in the network tab, but it does not do anything (Area does not render and this searchPartialBean.getSearchList() method does not get called). Below is my code snippet. Is there any issue in the way I am doing it ?
<b:tab title="Search">
<h:form>
<b:row>
<b:column mediumScreen="7">
<b:inputText placeholder="Telephone number" label="Telephone number"
value="#{searchPartialBean.telephoneNumber}"/>
<b:inputText placeholder="First name" label="First Name"
value="#{searchPartialBean.firstName}"/>
<b:inputText placeholder="Last name" label="Last Name"
value="#{searchPartialBean.lastName}"/>
<b:commandButton look="primary" id="search-form-submit" value="Search"
update="serach-results-table"/>
</b:column>
<b:column mediumScreen="5">
<b:alert severity="info" title="Info">
This will contain the search help.
</b:alert>
</b:column>
</b:row>
<br />
<b:panel id="serach-results-table">
<b:dataTable rendered="#{searchPartialBean.valuesPresent}" value="#{searchPartialBean.getSearchList()}" var="patient">
<b:dataTableColumn label="Date" value="#{patient.firstName}"/>
</b:dataTable>
</b:panel>
</h:form>
</b:tab>

You've wrapped a form in a tab. Both widgets define a namespace, which, in turn, adds a prefix to the id of each widget within. Probably that's the problem.
My first approach would be to add a colon to indicate you're searching in the inner namespace:
update=":search-results-table"
If that doesn't work, you can use the recursive search expression of BootsFaces:
update="**:search-results-table"
However, my favorite approach is to use a CSS pseudo class like so:
update="#(.search-results-table)"
<b:panel styleClass="search-results-table">

Related

Validation of a b:modal form is not working

I am trying to validate a modal form ( JSF/Bootsfaces ) and prevent it from being saved if the inputtext is not correct. For some reason I ignore it is not working, here is the JSF code:
<b:modal id="creation"
title="#{msgs['page.manageFlights.addingNew']}"
styleClass="formValidationModalClass"
closeOnEscape="false"
backdrop="false"
closable="false">
<b:form id="createModal">
<b:selectOneMenu
value="#{flightBean.currentFlight.journey}"
label="#{msgs['page.manageFlights.findAllJourneys']}"
required="true"
requiredMessage="Please select a journey"
large-screen="full-width">
<f:selectItems value="#{journeyBean.findAllJourneys()}" var="journey" itemValue="#{journey}" itemLabel="#{journey.departureLocation} -> #{journey.arrivalLocation}" />
</b:selectOneMenu>
<b:dateTimePicker
value="#{flightBean.currentFlight.departureDate}"
label="#{msgs['page.manageFlights.departureDate']}"
required="true"
requiredMessage="Please enter a date and time"
large-screen="full-width">
</b:dateTimePicker>
<b:dateTimePicker
value="#{flightBean.currentFlight.arrivalDate}"
label="#{msgs['page.manageFlights.arrivalDate']}"
required="true"
requiredMessage="Please enter a date and time"
large-screen="full-width">
</b:dateTimePicker>
<b:inputText value="#{flightBean.currentFlight.numberOfBusinessClassSeats}"
label="#{msgs['page.manageFlights.numberOfBusinessClassSeats']}"
required="true"
requiredMessage="The number of seats must be positive"
large-screen="full-width">
<f:validateLongRange minimum = "1" maximum = "2000" />
</b:inputText>
<b:inputText
value="#{flightBean.currentFlight.numberOfEconomyClassSeats}"
label="#{msgs['page.manageFlights.numberOfEconomyClassSeats']}"
required="true"
requiredMessage="Please enter a number"
validatorMessage="The number of seats must be positive"
large-screen="full-width">
</b:inputText>
<br/>
<b:row>
<b:column>
<b:commandButton
largeScreen="half"
value="#{msgs['cancel.button']}"
dismiss="modal"
action="#{flightBean.resetCurrentFlight()}"
oncomplete="$('#creation').modal('hide')"
/>
<b:commandButton
largeScreen="half"
dismiss="modal"
update="#(#dataTable)"
value="#{msgs['save.button']}" look="success"
action="#{flightBean.addFlight(flightBean.currentFlight)}"
oncomplete="if(!validationFailed) { $('#creation').modal('hide')};">
</b:commandButton>
</b:column>
</b:row>
<b:fetchBeanInfos/>
<b:messages/>
</b:form>
</b:modal>
I am trying to check if the number of business class seats is positive.
As you can see I added fetchbeaninfos, validateLongRange and oncomplete.
<b:fetchBeanInfos> and validationFailed only work after an AJAX request. You need to send the input to the server, have it validated there, and only when the response is sent back to the client, validationFailed is updated.
My suggestion is to use simple JavaScript to show the error message and to disable the button.
However, if you prefer to use server-side validation, here's what to do:
Add an empty validateInput() method to your bean. It doesn't need any implementation; it just has to be there so it can be called by an JSF AJAX call.
Add an id to <b:fetchBeanInfos>.
Add an AJAX change listener to each input field. Depending on the type of the input field, you may need a different listener (onblur, onchange, etc.), but the general idea is like so:
<b:inputText
onblur="ajax:flightBean.validateInput()"
update="**:fetchBeansId"
value="..."
label="..."
required="true"
requiredMessage="..."
validatorMessage="...">
</b:inputText>
<b:fetchBeanInfos id="fetchBeansId"/>
The **:idbit helps you if your JSF page has multiple "namespaces", such as forms, modals, data tables, and tabs. These namespaces add a prefix to the id, and **:id allows you to find the id no matter what the prefix is.

How do I get the button to be "pressed" submitting input text when "Enter" key is pressed?

Using just JSF, can I do this ? Or do I need to add in more layers and functionality to the program?
This is what I have so far with it:
<tr:form usesUpload="true">
<trh:tableLayout width="100%" cellPadding="10" borderWidth="0"
id="Table">
<trh:rowLayout>
<trh:cellFormat columnSpan="4">
<ocau:inlineMessage />
</trh:cellFormat>
</trh:rowLayout>
<tr:panelBox styleClass="roundedPanelPrimary">
<trh:rowLayout halign="center">
<trh:cellFormat halign="center">
<tr:inputText styleClass="tabdata" contentStyle="normalContent"
label="Account Number"
value="#{fraudSearch.fraudCustomerReqtUIModelBean.accountNumber}"
accessKey="13"
>
</tr:inputText>
</trh:cellFormat>
<trh:cellFormat halign="left">
<tr:commandButton text="Search" id="Search"
action="#{fraudSearch.getIBSNotesData}" styleClass="Button"
halign="center"
>
</tr:commandButton>
</trh:cellFormat>
</trh:rowLayout>
</tr:panelBox>
<tr:panelBox styleClass="roundedPanelPrimary"
rendered="#{fraudSearch.displaySearchResults}">
<trh:tableLayout cellPadding="10" borderWidth="0" id="Table"
width="100%">
<trh:rowLayout>
<tr:panelTabbed position="above" inlineStyle="width:auto">
<tr:showDetailItem text="IBS Data Extract" id="IBSDataExtract"
immediate="true">
<ui:include
src="/pages/recovery/fraud/displayFraudRPAIBSDataExtract.jspx">
</ui:include>
</tr:showDetailItem>
<!--
<tr:showDetailItem text="Non-Monetary Data" id="IBSNonMonData"
immediate="true">
<ui:include
src="/pages/recovery/fraud/displayFraudRPANonMonetaryData.jspx">
</ui:include>
</tr:showDetailItem>
-->
</tr:panelTabbed>
</trh:rowLayout>
</trh:tableLayout>
</tr:panelBox>
</trh:tableLayout>
</tr:form>​
So far, I have attempted to add the access key to both the text box and the button, but it doesn't appear to work. Any point in the right direction would be appreciated.
Trinidad provides a defaultCommand within it's formtag, with wich you should be able to do, what you want. See here: tr:form

Invoking a text box and action method for several input text fields?

I'm new to jsf and not sure how to frame the question in a right way. I'm doing a name lookup functionality and my input form is as follows:
Accept input from a text field.(Backed by managed bean and
getters and setters)
Invoke the action using command button.
Display it back on the UI.
I'm not able to paste the entire code because of confidentiality.
<h:form>
<p:outputLabel value="ABC" />
<p:inputText id="a" value="#{mybean.variable}" size="10" />
<p:commandButton value="Check" actionListener="#{mybean.getName()}" update="name">
</p:commandButton>
<p:inputText id="name" value="#{mybean.Value}" />
</h:form>
The above mentioned works fine,However I have 5 input text fields and their corresponding action methods like as follows:
<p:outputLabel value="DEF" />
<p:inputText id="b" value="#{mybean.variable1}" size="10" />
<p:commandButton value="Check" actionListener="#{mybean.getName()}" update="name" >
</p:commandButton>
<p:inputText id="name" value="#{mybean.Value}" />
</h:form>
and so on.
When I put all the text boxes and their corresponding actions,the input is not passed to the backend and the console does not display anything.
Any help appreciated.
Thanks.

How to get rid of empty tooltips while displaying error messages on tooltips in PrimeFaces?

I display error messages somewhere on <p:tooltip> as follows.
<p:inputText id="text" value="#{bean.text}" required="true"/>
<p:tooltip for="text">
<p:message for="text"/>
</p:tooltip>
Although it displays an error message the given tooltip, an empty/unnecessary tooltip is shown, when there is no error as can be seen in the following picture - beside the bottom right corner of the text box.
How to get rid of such empty tooltips? (I tried someway but it did not work)
It can be done by checking for an error message in the list java.util.List<FacesMessage> that can be obtained by using facesContext.messageList.
The rendered attribute of <p:tooltip> can be set based on the error message/s found in the list for the associated component/s something along the line.
rendered="#{not empty facesContext.getMessageList('clientId')}"
A working code snippet :
<h:form id="form">
<p:panel id="panel">
<p:inputText id="text" value="#{bean.text}" required="true"/>
<p:tooltip for="text" rendered="#{not empty facesContext.getMessageList('form:text')}">
<p:message for="text"/>
</p:tooltip>
<p:commandButton value="Submit" update="panel"/>
</p:panel>
</h:form>
Or by using component binding. Such as,
<p:inputText id="text" binding="#{inputComponent}" value="#{bean.text}"/>
<p:tooltip for="text" rendered="#{not empty facesContext.getMessageList(inputComponent.clientId)}">
<p:message for="text"/>
</p:tooltip>
Or even
<p:inputText id="text" binding="#{inputComponent}" value="#{bean.text}"/>
<p:tooltip for="text" rendered="#{not inputComponent.valid}">
<p:message for="text"/>
</p:tooltip>
The last two cases are useful especially when the (input) component is enclosed within an iterating component like a <p/h:dataTable>, <p:dataGrid>, <p:dataList> (or even <ui:repeat>) where the uniqueness of enclosing components is determined based on the iterating row index of an iterating component such as, form:dataTable:0:text, form:dataTable:1:text, form:dataTable:2:text... and so on
p:tooltip should have a "rendered" attribute, set it to false
from documentation:
rendered : default=TRUE - value to specify the rendering of the
component, when set to false component will not be rendered.
Source: http://courses.coreservlets.com/Course-Materials/pdf/jsf/primefaces/users-guide/p-tooltip.pdf

Escaped itemLabel for p:selectBooleanCheckbox

I have a question regarding the primefaces component p:selectBooleanCheckbox.
I have following code, which renders a simple boolean checkbox with its label.
<p:selectBooleanCheckbox id="agb" value="#{mobiFormF000001Model.agbChecked}" itemLabel="#{msgs['agb']}">
<f:ajax render="submit" />
</p:selectBooleanCheckbox>
Now my problem is, that in the label i have an URL, which now is escaped and my label looks like this:
Ich bestätige, dass ich die Angaben zum Datenschutz gelesen habe und diese akzeptiere.
Is there a way to get that part rendered as link?
Why don't you simply use <h:outputText> that has the escape property?
<p:selectBooleanCheckbox id="agb" value="#{mobiFormF000001Model.agbChecked}" >
<f:ajax render="submit" />
</p:selectBooleanCheckbox>
<h:outputText escape="false" value="#{msgs['agb']}" />
You can link a p:outputLabel to the checkbox and put any content in its body:
<p:selectBooleanCheckbox value="#{bean.value}"/>
<p:outputLabel for="#previous">
I agree to the terms and conditions
</p:outputLabel>

Resources