I have a login and a register form on one and the same page and I try to return the global error message only on the concerning form. How to I do that correctly?
import org.omnifaces.util.Messages;
// login class submit()
Messages.addGlobalError('Login failed');
// register class submit()
Messages.addGlobalError('Register failed');
<h:form id="login-form">
<h:messages globalOnly="true" />
// [...]
<h:commandButton value="Login" action="#{login.submit()}" />
</h:form>
<h:form id="register-form">
<h:messages globalOnly="true" />
// [...]
<h:commandButton value="Sign up" action="#{register.submit()}" />
</h:form>
That is a contradictory... you simply never assign a global error to a specific component (the form is a component).
Simply make an error that you assign to the id of the form by using
Messages.addError(id, error);
add a <h:message for="..."> where the for contains the id of the form.
Here is how your example should look like:
import org.omnifaces.util.Messages;
// login class submit()
Messages.addError('login-form', 'Login failed');
// register class submit()
Messages.addError('register-form', 'Register failed');
<h:form id="login-form">
<h:messages globalOnly="true" for="login-from" />
// [...]
<h:commandButton value="Login" action="#{login.submit()}"/>
</h:form>
<h:form id="register-form">
<h:messages globalOnly="true" for="register-from" />
// [...]
<h:commandButton value="Sign up" action="#{register.submit()}"/>
</h:form>
primefaces mobile commandLink action does not work, it's not loading the page with id="station1". f:setPropertyActionListener is work and call setSelectedStation() method .
<pm:page id="fastStationPage">
<pm:header title="Fast Charging Station" swatch="b" ></pm:header>
<pm:content>
<h:form id="stationsDetailsForm">
<p:growl id="messages" showDetail="true" />
<p:dataList value="#{navigationViewImpl.fastStationList}" var="station" type="ordered">
<p:commandLink value="#{station.name}" action="pm:station1?transition=slide" update=":station1:stationDetail">
<f:setPropertyActionListener value="#{station}" target="#{navigationViewImpl.selectedStation}" />
</p:commandLink>
</p:dataList>
</h:form>
</pm:content>
</pm:page>
<pm:page id="station1">
<pm:content>
<h:outputText id="stationDetail" value="#{navigationViewImpl.selectedStation.name}" escape="false"/>
</pm:content>
</pm:page>
public void setSelectedStation(StationDTO selectedStation) {
this.selectedStation = selectedStation;
}
I got answer. I not configure face-config.xml file. I am not add navigation-handler
<application>
<navigation-handler>
org.primefaces.mobile.application.MobileNavigationHandler
</navigation-handler>
</application>
i have to edit a row in a table using rich faces 4 and modal panel. I am new one so please tell me in details and i know to make a table in rich faces. i already searched so many things but not getting any fruitful
See answer for question "Richfaces: show details in popup [commandbutton, action and popupPanel]". It works in RichFaces 4.x with rowClick.
Or here is example with commandLink:
<a4j:commandLink action="#{actionBean.setupTransactionDetails}"
event="onclick" render="transactionDetails"
oncomplete="#{rich:component('transactionDetails')}.show()"
styleClass="rich-link">
<h:outputText value="#{res.transactionType}" />
<f:setPropertyActionListener value="#{res.transactionId}"
target="#{profile.transactionId}" />
</a4j:commandLink>
But I prefer updated version like this:
<a4j:jsFunction name="showDetail" action="#{actionBean.setupTransactionDetails}"
oncomplete="#{rich:component('transactionDetails')}.show();"
render="transactionDetails">
<a4j:param name="id" assignTo="#{profile.transactionId}"
converter="javax.faces.Long" />
</a4j:jsFunction>
<rich:dataTable id="txnTable" rows="#{referenceData.recordsPerPage}"
style="width: 100%" rowClasses="oddrow, evenrow"
value="#{profile.transactions}" var="res" sortMode="single">
<h:column width="110">
<f:facet name="header">
<h:outputText value="#{msg.transactionType}" />
</f:facet>
<a4j:commandLink onclick="showDetail('#{res.transactionId}');"
value="#{res.transactionType}" />
</h:column>
</rich:dataTable>
<rich:popupPanel id="transactionDetails" autosized="true"
style="max-height:600px;">
<!-- f:facet name="header" and f:facet name="controls" here -->
<h:form id="transactionDetailsForm">
<!-- some details here -->
</h:form>
</rich:popupPanel>
Profile backing bean
private Long transactionId; // + getter and setter
Action backing bean
public void setupTransactionDetails() {
Transaction txn = DAO.getInstance().get(Transaction.class, getProfile().getTransactionId());
transactionForm.setup(txn);
}
In case if you use EL 2.2 (or higher) you can call action bean method with parameter.
I've got a form within a p:dialog component being submitted via AJAX. The form in the dialog is via a ui:include of another .xhtml containing just the form and its components (no, I am not nesting forms; the dialog itself is not within any form). The included page's backing bean is 'ViewScoped'.
MOST things function fine:
On successful validation, the form will execute the save method; after a successful save, the dialog closes; opening a subsequent record shows proper record information from the database.
On unsuccessful validation, the submitted values persist and the dialog remains open and displays validation errors, fixing the invalid fields and resubmitting results in a successful save.
The problem comes in when the action called by the p:commandButton fails. In the event that it fails, the dialog remains open and displays "Error saving changes" via h:messages to the user; additionally, the submitted values still persist in the input fields. This is fine (and even desired) while the form remains open, however-- upon closing the dialog and reopening it, the submitted values are STILL in the text fields. This is bad because it gives the user the impression that the save did succeed (as the h:messages component is now blank due to the dialog update).
So far I have tried the following, NONE of which have remedied the problem:
1.1) Setting the backing bean of the included form to a new instance of the bean on dialog open.
1.2) Since the bean is now a new instance, I am also repopulating the address object with details from a data bean.
2.1) Disabling the close button on the dialog and adding a p:commandButton "Cancel" button with a p:resetInput component in
it to close the dialog/reset the form. (dialog closes, but submitted
values in form persist).
2.2) Calling a method from this p:commandButton that removes the RequestMap for the included form's backing bean.
2.3) Tried with the button set to both immediate=true and immediate=false.
2.4) Tried with the button set to process=#this, a similar tactic I have used to close a form to ensure it will have fresh fields upon
reopening.
You would think between setting the backing bean to a new instance, and repopulating the address object I would be seeing a fresh form, but NOPE.
Here is some of the source:
Portion of mainform.xhtml
<p:dialog id="dlgAddress"
header="Address Edit"
widgetVar="dialogAddress"
dynamic="true"
modal="false"
closable="false"
resizable="false"
styleClass="dlgAddress"
visible="#{addressform.showDlgAddress}">
<ui:include src="addressform.xhtml"/>
</p:dialog>
addressform.xhtml
<h:form id="fDlgAddress">
<div id="addresses-container">
<h:messages id="msgDlgAddress" errorClass="errormsg" infoClass="infomsg1" layout="table"/>
<h:panelGrid columns="1"
styleClass="pgAddresses"
rendered="#{!addressform.address.exists}">
<h:outputText value="No active #{addressform.address.atypCode} address found."
styleClass="record-not-exists"/>
<h:outputText value="Use the form below to create one."/>
</h:panelGrid>
<p:panelGrid columns="2"
styleClass="pgDlgForm pgAddresses">
<h:outputLabel value="Address Type"/>
<h:inputText id="atypCode1"
value="#{addressform.address.atypCode}"
disabled="true"
rendered="#{addressform.address.exists}"/>
<h:selectOneMenu id="atypCode2"
value="#{addressform.address.atypCode}"
rendered="#{!addressform.address.exists}">
<f:selectItems value="#{addressform.atypCodeList}"
var="atyp"
itemValue="#{atyp}"
itemLabel="#{atyp}"/>
</h:selectOneMenu>
<h:outputLabel value="Street 1"
for="street1"/>
<h:inputText id="street1"
value="#{addressform.address.addressLine1}"/>
<h:outputLabel value="Street 2"
for="street2"/>
<h:inputText id="street2"
value="#{addressform.address.addressLine2}"/>
<h:outputLabel value="Street 3"
for="street3"/>
<h:inputText id="street3"
value="#{addressform.address.addressLine3}"/>
<h:outputLabel value="Street 4"
for="street4"/>
<h:inputText id="street4"
value="#{addressform.address.addressLine4}"/>
<h:outputLabel value="City"
for="city"/>
<h:inputText id="city"
value="#{addressform.address.city}"
required="true"
requiredMessage="Please enter a city."/>
<h:outputLabel value="State"
for="statCode"/>
<h:selectOneMenu id="statCode"
value="#{addressform.address.stateCode}">
<f:selectItem itemLabel="Select State/Province"
itemValue=""/>
<f:selectItems value="#{states.statesList}"
var="stat"
itemValue="#{stat.statCode}"
itemLabel="#{stat.statDesc}"/>
</h:selectOneMenu>
<h:outputLabel value="Zip Code"
for="zipCode"/>
<h:inputText id="zipCode"
value="#{addressform.address.zip}"/>
<h:outputLabel value="Country"
for="natnCode"/>
<h:selectOneMenu id="natnCode"
value="#{addressform.address.nationCode}"
required="true"
requiredMessage="Please choose a nation.">
<f:selectItem itemLabel="Select Country"
itemValue=""/>
<f:selectItems value="#{nations.nationsList}"
var="natn"
itemValue="#{natn.natnCode}"
itemLabel="#{natn.natnDesc}"/>
</h:selectOneMenu>
<h:outputLabel value="From Date"
for="fromDate"/>
<p:calendar id="fromDate"
value="#{addressform.address.fromDate}"
showButtonPanel="true"/>
<h:outputLabel value="To Date"
for="toDate"/>
<p:calendar id="toDate"
value="#{addressform.address.toDate}"
showButtonPanel="true"/>
<h:outputLabel value="Inactivate"
for="inactivateAddress"
rendered="#{addressform.address.exists}"/>
<h:selectBooleanCheckbox id="inactivateAddress"
value="#{addressform.address.inactivate}"
rendered="#{addressform.address.exists}"/>
<h:outputLabel value="Delete"
for="deleteAddress"
rendered="#{addressform.address.exists}"/>
<h:selectBooleanCheckbox id="deleteAddress"
value="#{addressform.address.delete}"
rendered="#{addressform.address.exists}"/>
</p:panelGrid>
</div>
<div class="button-container">
<p:commandButton value="Save Changes"
action="#{addressform.save}"
type="submit"
ajax="true"
process="#form"
update="#form"/>
<p:commandButton value="Cancel"
process="#this"
onclick="dialogAddress.hide();">
<p:resetInput target="fDlgAddress"/>
</p:commandButton>
</div>
</h:form>
Recorddetailsform (backing bean for form from which address dialog is called)
public void showDlgAddress(){
FacesContext ctx = FacesContext.getCurrentInstance();
ELResolver resolver = ctx.getApplication().getELResolver();
RecordDetails recordDetails = (RecordDetails) resolver.getValue(ctx.getELContext(), null, "recordDetails");
//Set addressform backing bean to new instance and load address into it from recordDetails
resolver.setValue(ctx.getELContext(), null, "addressform", new Addressform());
Addressform addressform = (Addressform) resolver.getValue(ctx.getELContext(), null, "addressform");
addressform.setAddress(recordDetails.getAddress());
}
Addressform (address form's backing bean)
public void save() {
FacesContext ctx = FacesContext.getCurrentInstance();
RequestContext rctx = RequestContext.getCurrentInstance();
ELResolver resolver = ctx.getApplication().getELResolver();
Records records = (Records) resolver.getValue(ctx.getELContext(), null, "records");
RecordDetails recordDetails = (RecordDetails) resolver.getValue(ctx.getELContext(), null, "recordDetails");
Mainform mainform = (Mainform) resolver.getValue(ctx.getELContext(), null, "mainform");
Person person = (Person) resolver.getValue(ctx.getELContext(), null, "person");
//Pretty lengthy SQL stuff here. Commented out. Just wanted to display the display logic below for the dialog.
if (errorMsg != null) {//If errorMsg is not null, then error occurred.
showDlgAddress = true;//Ensures address dialog remains open in event of action error.
queueErrorMessage(errorMsg);
rctx.update("dlgAddress");
return;//break out of method on error.
} else {
showDlgAddress = false;
rctx.update("dlgAddress");
}
//If everything saves without error, repopulate address and update recordDetails dialog.
recordDetails.populateAddress(records.getSelectedRecord());
mainform.updateDlgRecordDetails();
}
Other Info:
JSF2
Primefaces 3.5
Tomcat 6.0
Netbeans
Try this:
Put your dialog inside a form (dialogInputForm)
Add the attribute update=":dialogInputForm"
Nest the resetInput tag within the button that opens the dialog and specify the target as the just created form
The commandButton:
<p:commandButton process="#this" actionListener="#{bean.prepare}" update=":dialogInputForm" oncomplete="thirdPartyDialog.show()" value="Open Input Dialog" >
<p:resetInput target=":dialogInputForm" />
</p:commandButton>
And the form which contais the dialog
<h:form id="dialogInputForm" >
... your dialog ...
</h:form>
This worked for me, place this ajax event in the dialog. When the dialog is closed, the validations will be cleaned
<p:dialog id="dlgAddress"
header="Address Edit"
widgetVar="dialogAddress"
dynamic="true"
modal="false"
closable="false"
resizable="false"
styleClass="dlgAddress"
visible="#{addressform.showDlgAddress}">
<ui:include src="addressform.xhtml"/>
<p:ajax event="close" update="dlgAddress" resetValues="true" />
</p:dialog>
Hi have a form that call an Action properly. But when i enable the authentication forms, the action to login doesn't fire up (i test it with a breakpoint).
My Web.config is:
<authentication mode="Forms">
<forms loginUrl="Autenticacao/Index"></forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
It's in the view Index of controller Autenticacao where i have my form:
<% Html.BeginForm("Login", "Autenticacao"); %>
<input type="text" id="autenticacaoReferencia" name="autenticacaoReferencia" /><br />
<input type="text" id="autenticacaoPassword" name="autenticacaoPassword" /><br />
<input type="submit" value="Entrar" />
<% Html.EndForm(); %>
The controller Login is sucefully called just if the authentication form is disable.
Am i using the BeginForm in a wrong way?
Edit: The Login action:
public ActionResult Login(string autenticacaoReferencia, string autenticacaoPassword, string returnUrl)
{
...
}
Thanks
Are you decorating your actions with the [Authorize] attribute?