This question already has answers here:
Creating FacesMessage in action method outside JSF conversion/validation mechanism?
(1 answer)
Show JSF validation error next to the fields
(1 answer)
Closed 6 months ago.
I have a JSF page with primefaces. How do I get an error message to occur on a failed login? I tried requiredMessage but the result is negative.
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="name" value="Name" />
<p:inputText id="buyerName" required="true" requiredMessage="Enter your name" />
<h:outputLabel for="surname" value="Surname" />
<p:inputText id="buyerSurname" required="true" />
<h:panelGrid columns="2" cellpadding="5">
<p:messages/>
<h:outputLabel for="name" value="Name" />
<p:inputText id="buyerName" required="true" requiredMessage="Enter your name" />
<h:outputLabel for="surname" value="Surname" />
<p:inputText id="buyerSurname" required="true" />
Related
I want to implement a login-functionality using user-input directly (w/o variables in handling bean).
After migrating to Primefaces, the xhtml-code code does not work anymore.
<h:form>
...
<h:outputLabel for="mail" value="Email:" />
<p:inputText id="mail" value="#{mail}" required="true"/>
<h:outputLabel for="password" value="Passwort:" />
<p:password id="password" value="#{password}" required="true"/>
<p:commandButton value="Anmelden" update="loginGrowl" action="#{user.login(mail.value,password.value)}"/>
...
</h:form>
It gives the error:
WARNUNG: #{user.login(mail.value,password.value)}: javax.el.PropertyNotFoundException: /index.xhtml #43,122 action="#{user.login(mail.value,password.value)}": Property [value] not found on type [java.lang.String]
It turned out that 'mail' and 'password' actually ARE the input strings.. So the following will work (JSF 2.3; PrimeFaces 7.0):
<h:form>
<h:outputLabel for="mail" value="Email:" />
<p:inputText id="mail" value="#{mail}" required="true"/>
<h:outputLabel for="password" value="Passwort:" />
<p:password id="password" value="#{password}" required="true"/>
<f:facet name="footer">
<p:commandButton value="Anmelden" action="#{user.login(mail,password)}"/>
</f:facet>
</h:form>
I don't know when they changed it and I can't find anything documented so I'll leave the question here answered by myself for anyone who might stumble around.
I have a p:datascroller configured to display a list of entities and lazy loading them upon clicking the more button.
<h:form id="investigationOperationsForm">
<p:dataScroller
value="#{investigationManagerBackingBean.lazyLoadedInvestigationOperations}"
var="investigationOperation" chunkSize="9" lazy="true"
rowIndexVar="test">
<f:facet name="header">
Scroll down to load investigations
</f:facet>
<h:panelGrid columns="2" style="width:100%"
columnClasses="logo,detail">
<p:commandLink oncomplete="PF('investigationDialogW').show()"
update="investigationEditorForm" immediate="true">
<f:setPropertyActionListener value="#{investigationOperation}"
target="#{investigationManagerBackingBean.selection}" />
<p:graphicImage alt="Investigation Operation"
url="/images/common/investigation-operation.png" />
</p:commandLink>
<!-- h:outputText value="#{investigationOperation.name}" /-->
<p:outputPanel id="pnl">
<h:panelGrid columns="2" cellpadding="5">
<h:outputText value="Name:" />
<h:outputText value="#{investigationOperation.name}"
style="font-weight: bold" />
<h:outputText value="Description:" />
<h:outputText value="#{investigationOperation.shortDescription}"
style="font-weight: bold" />
</h:panelGrid>
<p:draggable for="pnl" />
</p:outputPanel>
</h:panelGrid>
<f:facet name="loader">
<p:outputPanel
visible="#{investigationManagerBackingBean.lazyLoadedInvestigationOperations.rowCount gt 10}"
rendered="#{investigationManagerBackingBean.lazyLoadedInvestigationOperations.rowCount gt 10}">
<p:commandLink value="More" />
</p:outputPanel>
</f:facet>
</p:dataScroller>
</h:form>
In addition, I have a dialog that pops up when the p:commandLink oncomplete method is executed where I can update the value of the current selection and persist the changes.
<p:dialog id="investigationDialog"
header="#{msg['inv-manager.invDialog.header.title']}"
widgetVar="investigationDialogW" minWidth="400" minHeight="400"
resizable="false" position="center center" modal="true">
<p:panel id="investigationEditorPanel">
<h:form id="investigationEditorForm">
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="name"
value="#{msg['inv-manager.invDialog.nameFieldLabel']}" />
<p:inplace id="nameInplaceEditor" editor="true">
<p:inputText
value="#{investigationManagerBackingBean.selection.name}"
id="name" required="true" immediate="true"
label="#{msg['inv-manager.invDialog.nameFieldInputLabel']}" />
</p:inplace>
<h:outputLabel for="shortDescription"
value="#{msg['inv-manager.invDialog.shortDescriptionFieldLabel']}" />
<p:inplace id="shortDescriptionInplaceEditor" editor="true">
<p:inputText
value="#{investigationManagerBackingBean.selection.shortDescription}"
id="shortDescription" required="true" immediate="true"
label="#{msg['inv-manager.invDialog.shortDescriptionFieldInputLabel']}" />
</p:inplace>
<h:outputLabel for="description"
value="#{msg['inv-manager.invDialog.descriptionFieldLabel']}" />
<p:inputTextarea id="description" required="false"
label="#{msg['inv-manager.invDialog.descriptionFieldInputLabel']}"
immediate="true"
value="#{investigationManagerBackingBean.selection.description}" />
<p:commandButton id="okButton"
value="#{msg['inv-manager.invDialog.okButton']}" type="submit"
partialSubmit="true" process="investigationEditorForm"
action="#{investigationManagerBackingBean.createOrUpdate()}"
onclick="dlg.hide();" />
</h:panelGrid>
</h:form>
</p:panel>
</p:dialog>
The backing bean is configured to be #ViewScoped and everything works as defined. However, upon update the values of the p:datascroller are reset and the load method of the lazy loading model is executed and the datascroller is repopulated with new values from the database.
I have no reference to the datascroller or its containing form in the p:dialog and am wondering why the datascroller is being updated automagically? What am I missing in the equation. Have I overlooked something or something specific to the p:datascroller model that I need to consider when following this approach?
Look forward to the expertise of the community in resolving this issue.
Many thanks in advance :)
This question already has answers here:
How to dynamically add JSF components
(3 answers)
Closed 6 years ago.
I have an "Add" button at the bottom that when clicked, I want it to duplicate part of form below the existing one. How to change automatic id and value for new inputs , I need this later for generating reports with all entries.
<h:panelGrid columns="2">
<p:outputLabel value="From: " />
<p:inputMask id="date1" value="#{data.date1}" mask="99/99/9999"/>
<p:outputLabel value="To: " />
<p:inputMask id="date2" value="#{data.date2}" mask="99/99/9999"/>
<p:outputLabel value="Name: " />
<p:inputText id=name1 value="#{data.name}" />
<p:outputLabel value="Description: " />
<p:inputTextarea id=description1 value="#{data.description}" />
</h:panelGrid>
i would do it this way:
create an ArrayList of your Data-Object example List<Data> dataList; in your ManagedBean, then use dataTable in the view to display the fields of each Data-Object.
when you click the "duplicate Button", an action/ajax methode could be called within your bean to duplicate or add new entries to the dataList, ...etc.
something like:
<h:dataTable var="data" value="#{bean.dataList}">
<h:column>
<h:panelGrid columns="2">
<p:outputLabel value="From: " />
<p:inputMask id="date1" value="#{data.date1}" mask="99/99/9999"/>
<p:outputLabel value="To: " />
<p:inputMask id="date2" value="#{data.date2}" mask="99/99/9999"/>
<p:outputLabel value="Name: " />
<p:inputText id=name1 value="#{data.name}" />
<p:outputLabel value="Description: " />
<p:inputTextarea id=description1 value="#{data.description}" />
</h:panelGrid>
</h:column>
</h:dataTable>
I am not able to validate input fields using primefaces ajax on the client side by calling event blur using primefaces
<h:panelGrid columns="2">
<p:outputLabel for="uname" value="Name"/>
<p:inputText id="uname" value="#{userbean.name}" required="true" requiredMessage="Enter your name">
<p:ajax event="blur" rendererType="name"/>
</p:inputText>
<h:outputText value=""/>
<p:message id="name" for="uname" />
<p:outputLabel for="add" value="Address"/>
<p:inputText id="add" value="#{userbean.address}" required="true" requiredMessage="Enter your address">
<p:ajax event="blur" rendered="address"/>
</p:inputText>
<h:outputText value=""/>
<p:message id="address" for="add" />
<h:commandButton value="Submit"/>
</h:panelGrid>
I am not sure what you're doing with 'rendererType and rendered' on your ajax events - they make no sense and ikely just breaking.
I've got it working fine in the below example (note my bean is different name) - i made the grid only 1 in colum size just for testing purposes and you're best off wrapping those full data objects you want re-rendered after ajax request. see the below code p:ajax uses 'update' to render content, where f:ajax uses render="id" etc..
<h:form>
<h:panelGrid columns="1">
<h:panelGroup layout="block" id="nameSection" >
<p:outputLabel for="uname" value="Name"/>
<p:inputText id="uname" value="#{onBlur.name}" required="true" requiredMessage="Enter your name">
<p:ajax event="blur" update="nameSection"/>
</p:inputText>
<h:outputText value=""/>
<p:message id="name" for="uname" />
</h:panelGroup>
<h:panelGroup layout="block" id="addressSection" >
<p:outputLabel for="add" value="Address"/>
<p:inputText id="add" value="#{onBlur.address}" required="true" requiredMessage="Enter your address">
<p:ajax event="blur" update="addressSection"/>
</p:inputText>
<h:outputText value=""/>
<p:message id="address" for="add" />
</h:panelGroup>
</h:panelGrid>
<h:commandButton value="Submit"/>
</h:form>
This is my form ..
<p:panel id="panel" header="Portfolio Transaction">
<p:messages id="msgs" />
<p:panelGrid columns="7" id="transactionPanel" style="display: inline-block;">
<f:facet name="header">
Register New Trade
</f:facet>
<h:outputLabel for="tipsSuggestionBoxId" value="Company Name:*"></h:outputLabel>
<h:outputText value="Date:*" />
<h:outputText value="Type:*" />
<h:outputText value="Quantity:*" />
<h:outputText value="Price:*" />
<h:outputText value="Brokerage:" />
<h:outputText value="Notes:" />
<p:autoComplete id="tipsSuggestionBoxId"
completeMethod="#{portfolioTransactionBean.autoSelectCompany}"
value="#{portfolioTransactionBean.txnCurrentRecord.companyName}"
minChars="3" nothingLabel="No similar company found"
requestDelay="1" minQueryLength="3" required="true"
requiredMessage="Company Name Cannot be empty">
</p:autoComplete>
<p:calendar id="from_date" size="10" required="true"
requiredMessage="Date Cannot be empty"
value="#{portfolioTransactionBean.txnCurrentRecord.umptTransDate}"
mode="popup" showOn="both" pattern="dd/MM/yyyy"
popupIconOnly="true" readonly="#{facesContext.renderResponse}">
</p:calendar>
<p:selectOneMenu id="tranType"
value="#{portfolioTransactionBean.txnCurrentRecord.umptTransType}">
<f:selectItem itemLabel="Transaction Type" itemValue="" />
<f:selectItem itemLabel="Buy" itemValue="Buy" />
<f:selectItem itemLabel="Sell" itemValue="Sell" />
</p:selectOneMenu>
<p:spinner id="transQuntity" required="true"
value="#{portfolioTransactionBean.txnCurrentRecord.umptQty}" min="1" label="Quanity" size="5"
validatorMessage="Field Is mandatory" />
<p:spinner id="transPrice" required="true" size="5"
value="#{portfolioTransactionBean.txnCurrentRecord.umptPrice}"
label="Price"
validatorMessage="Field Is mandatory" />
<p:spinner id="brokerage" size="5"
value="#{portfolioTransactionBean.txnCurrentRecord.umptBrokerage}" />
<h:inputText
value="#{portfolioTransactionBean.txnCurrentRecord.umptNotes}" />
<f:facet name="footer">
<p:commandButton value="Save Transaction " icon="ui-icon-check"
action="#{portfolioTransactionBean.savePortfolioTransaction}"
update="panel" style="float:right;right:20%;">
<p:resetInput target="transactionPanel" />
</p:commandButton>
<p:spacer width="100" height="10" />
<p:commandButton value="Clear" update="transactionPanel"
process="#this">
<p:resetInput target="transactionPanel" />
</p:commandButton>
</f:facet>
</p:panelGrid>
after form validation fail like user not input date or company name , i am able to see proper message but after that i am not able to input any value from keybord.Any one know what is the issue with code.
This problem not occurring only when validation fail even when i clicked on clear button i am getting same issue. Any one get this issue?
Yes, it is true for some components in primefaces. The only solution is trying using some other components which replaces the problamatic components. or other wise if there is some error show the error , and write a code which refreshes entire screen if user gets an error message. Ofcourse the user needs to enter all details again.