h:commandButton is not working - action [duplicate] - jsf

This question already has answers here:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
Closed 6 years ago.
I am making an application using jsf and I have a problem when sending data from one of the rows of the datatable to a bean and then redirect to another page. Just to state, I'm using bootsfaces. Here are the codes:
JSF page:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="/templates/layout.xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:b="http://bootsfaces.net/ui"
xmlns:f="http://java.sun.com/jsf/core">
<ui:define name="title">Home</ui:define>
<ui:define name="content">
<b:dataTable value="#{LeiloesMB.lista()}" var="l">
<b:column>
<f:facet name="header">
<h:outputText value="Leilao"/>
</f:facet>
<h:outputText value="#{l.leilao.id}"/>
</b:column>
<b:column>
<f:facet name="header">
<h:outputText value="Encerramento"/>
</f:facet>
<h:outputText value="#{l.leilao.encerramento}"/>
</b:column>
<b:column>
<f:facet name="header">
<h:outputText value="Item"/>
</f:facet>
<h:outputText value="#{l.item.nome}"/>
</b:column>
<b:column>
<f:facet name="header">
<h:outputText value="Descrição"/>
</f:facet>
<h:outputText value="#{l.item.descricao}"/>
</b:column>
<b:column>
<f:facet name="header">
<h:outputText value="Maior Lance"/>
</f:facet>
<h:outputText value="#{l.valor}"/>
</b:column>
<b:column>
<f:facet name="header">
<h:outputLabel value="ID"/>
</f:facet>
<h:outputLabel value="#{l.usuario.id}"/>
</b:column>
<b:column>
<f:facet name="header">
<h:outputLabel value="Nome"/>
</f:facet>
<h:outputLabel value="#{l.usuario.nome}"/>
</b:column>
<b:column rendered="#{not empty Usuario.user.nome}">
<f:facet name="header">
<h:outputLabel value="Realizar Lance"/>
</f:facet>
<h:form>
<h:commandButton value="Faça seu lance" action="#{LanceMB.lance(Usuario.user, l)}"/>
</h:form>
</b:column>
</b:dataTable>
</ui:define>
</ui:composition>
LanceMB code:
#SessionScoped
#ManagedBean(name="LanceMB")
public class NovoLance {
private Usuario user = new Usuario();
private LancesLeilao ll = new LancesLeilao();
private double novo_valor;
public String lance(Usuario usuario, LancesLeilao lal){
this.user = usuario;
this.ll = lal;
return "novolance";
}
//getters.. setters
}
Usuario code:
#ManagedBean(name="Usuario")
#SessionScoped
public class UserSession {
private String email, senha;
private Usuario user = new Usuario();
//getters and setters..
}
Any question leave a comment.

A <h:commandButton /> is used to push the values of individual fields in a form to the managed bean defined. I see that you have enclosed just the button within the form but not the values themselves.
Wrap all the values within the form including the button and give it a try. It should work if everything else has been defined correctly.
Hope this helps :)

Related

Some of the action buttons does not work after bootsrap [duplicate]

This question already has answers here:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
Closed 1 year ago.
I have a project and I decided to make it look better. I learned how to use bootstrap and then tried on some of my pages. Although doing the same things on xhtml pages, some of my pages' buttons does not work correctly. Here is an example from my code
my add function which is being used from interface:
#Override
public void add(Object object) {
Session session = factory.openSession();
session.beginTransaction();
session.save(object);
session.getTransaction().commit();
session.close();
}
and i use it like this in my registerpage:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
template="/template/site.xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<ui:define name="content">
<h:form>
<style>
.error{color:red}
</style>
<div class="form-group">
<label for="inputEmail4">Product name</label>
<h:inputText class="form-control" value="#{product_bean.p_name}"
id="name"
required="true"
requiredMessage="Product name can't be empty!"
>
<f:validator validatorId="only_letter_validator"/>
</h:inputText>
<h:message for="name" styleClass="error"/> <br></br>
</div>
<h:commandButton value="Save" action="#{products_controller.add(product_bean)}">
<f:actionListener binding="#{products_controller.setFactory()}"/>
</h:commandButton>
</h:form>
</ui:define>
</ui:composition>
my command button is working fine.
here is my delete method:
#Override
public void delete(int id) {
Session session = factory.openSession();
session.beginTransaction();
session.createQuery("delete from Product where id=" + id).executeUpdate();
session.getTransaction().commit();
session.close();
}
and this is how I use it:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
template="/template/site.xhtml">
<ui:define name="content">
<h2><h:outputText value ="Product List"></h:outputText></h2>
<h:dataTable styleClass="table table-striped" value = "#{products_controller.productsList}" rows="#{products_controller.productsList.size()}" var = "item" border="1" headerClass="tableHeader" >
<h:column>
<f:facet name="header"> ProductID </f:facet>
<h:outputText value="#{item.p_id}" />
</h:column>
<h:column>
<f:facet name="header"> Productname </f:facet>
<h:outputText value="#{item.p_name}" />
</h:column>
<h:column>
<f:facet name="header"> Product class </f:facet>
<h:outputText value="#{item.p_class}" />
</h:column>
<h:column>
<f:facet name="header" > Productprice </f:facet>
<h:outputText value="#{item.p_price}" />
</h:column>
<h:column>
<f:facet name="header"> ProductPP </f:facet>
<h:outputText value="#{item.p_property}" />
</h:column>
<h:column>
<f:facet name="header"> ProductTotal </f:facet>
<h:outputText value="#{item.p_total}" />
</h:column>
</h:dataTable>
<br></br><br></br>
<div>
Ürün ID Numarası <h:inputText value="#{deleteID}"
id="id"
required="true"
requiredMessage="Can not be empty!"
validator="#{inputValidators.OnlyLetter}"/>
<h:message for="id" styleClass="error"/>
<h:commandButton value="Delete" action="#{products_controller.delete(deleteID)}">
<f:actionListener binding="#{products_controller.setFactory()}"/>
</h:commandButton>
</div>
</ui:define>
</ui:composition>
actually I am thinking they are same and it was working before I started to use bootstrap. one is working but other is not. what is different or what should I change? I traced it but could not figure out anything.
i found the solution and saw there are many people strugling with this problem. so i am sharing.
if your commandButtons are not in a <h:form> BUTTONHERE <h:form> they don't work. You can take whole table or just buttons between form parts, they will work.

p:dataTable not updated by PrimeFaces.current().ajax().update

I am starting developpment with JSF and PrimeFace datatable. I have prepared the following xhtml page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Find Capital of Countries</title>
</h:head>
<h:body>
<h:form id="FrmTest">
<p:dataTable id="ListSites" value="#{testing.SiteSearch()}" var="lst" editable="true">
<f:facet name="header">
List of Sites
</f:facet>
<p:column>
<f:facet name="header">
Site Code
</f:facet>
#{lst.stCode}
</p:column>
<p:column headerText="Site Description">
<h:outputText value="#{lst.stDescription}" />
</p:column>
<p:column headerText="is Active">
<div style="text-align: center;">
<p:selectBooleanCheckbox value="#{lst.stActive}" />
</div>
</p:column>
<p:column>
<f:facet name="header">
Site Active
</f:facet>
<div style="text-align: center;">
<h:outputText value= "#{lst.stActive}" />
</div>
</p:column>
<p:column>
<f:facet name="header">
Modified By
</f:facet>
#{lst.modifiedBy}
</p:column>
<p:column>
<f:facet name="header">
Modification Date
</f:facet>
#{lst.modifiedDate}
</p:column>
<p:column>
<f:facet name="header">
Has Error
</f:facet>
#{lst.hasError}
</p:column>
<p:column>
<f:facet name="header">
Error Description
</f:facet>
#{lst.errorDescription}
</p:column>
<p:column>
<f:facet name="header">
Row State
</f:facet>
#{lst.rowState}
</p:column>
</p:dataTable>
<h:outputLabel value="Enter Country Name:"/>
<h:inputText id="country" binding="#{testing.country}"
valueChangeListener="#{testing.findCapitalListener}"
immediate="true"
onchange="document.getElementById('findcapital').click();" />
<br/>
<br/>
<h:outputLabel value="Capital is: " />
<h:inputText id="capital" binding="#{testing.capital}" immediate="true"/>
<br/>
<br/>
<h:commandButton value="Submit" partialSubmit="true" />
<div style="visibility: hidden" >
<h:commandButton id="findcapital" value="findcapital" partialSubmit="true" immediate="true" />
</div>
</h:form>
</h:body>
</html>
I want entry made in text box named country to update datatable named ListSites. The associated listener is called (system.out.println made) but the primeface update is not made. Here is the listener:
```
public void findCapitalListener(ValueChangeEvent cdl) {
String country = cdl.getNewValue().toString();
System.out.println("Country is : " + country);
StringBuilder capitalCountry = new StringBuilder();
findCapital(country, capitalCountry);
capital.setValue(capitalCountry.toString());
siteDto = listSiteDto.get(0);
siteDto.setStDescription(capitalCountry.toString());
listSiteDto.set(0, siteDto);
PrimeFaces.current().ajax().update("FrmTest:ListSites");
//System.out.println("Capital is : " + capital.getValue());
//System.out.println("New DTO Description : " + siteDto.getStDescription());
System.out.println("New list Description : " + listSiteDto.get(0).getStDescription());
}
```
The problem was due to the fact that the function populating the datatable (SiteSearch()) was retrieving data from the database. At that stage I wanted to refresh the page display before updating the database. I replaced the function by the list getter, things are working properly now.

Delete Rows Using Checkbox in JSF

I am trying to delete multiple rows of employee data using checkboxes. However i am having a hard time finding a way to do this. The following is some code:
DeleteEmployees.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<f:loadBundle basename="resources.application" var="msg"/>
<head>
<title><h:outputText value="#{msg.welcomeTitle}" /></title>
</head>
<h:body>
<h:dataTable value="#{empController.list}" var="emp" border="2">
<h:column>
<f:facet name="header">
<h:outputText value="First Name"/>
</f:facet>
<h:outputText value="#{emp.firstName}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Last Name"/>
</f:facet>
<h:outputText value="#{emp.lastName}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Email"/>
</f:facet>
<h:outputText value="#{emp.email}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Phone"/>
</f:facet>
<h:outputText value="#{emp.phone}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Hire Date"/>
</f:facet>
<h:outputText value="#{emp.hireDate}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Manager ID"/>
</f:facet>
<h:outputText value="#{emp.managerId}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Department ID"/>
</f:facet>
<h:outputText value="#{emp.departmentId}"/>
</h:column>
<h:column>
<f:facet name="header">Delete</f:facet>
<h:form>
<h:selectBooleanCheckbox value="#{empController.checked[emp.id]}"/>
</h:form>
</f:facet>
</h:column>
</h:dataTable>
<h:commandButton value="Delete Employees" action="#{empController.delEmp}"/>
</h:body>
</html>
In my Managed bean i have this method in order to delete the ID. However the objects are not being deleted. I need some guidance here thank you!
public void delEmp(){
list = em.getAllEmployees();
for(Employee e : list){
if(checked.get(e.getId())){
em.deleteEmployee(e.getId());
}
}
checked.clear();
}
Your h:commandButton is not nested within the h:form. It needs to be nested for the form data to submit. Note that this is not a JSF limitation, but an HTML limitation.
See also
Call another form from the command button

JSF Method is called always two times

Hi I have a jsf datatabel using view scope, which allows sorting and pagination.
My problem is, that my BackingBean method for sorting is always called two times which would not be a big problem if not for sorting ascending/descending when sorting for the same row (which makes it obsolete).
Any ideas how to solve this problem? I've already read several blocks about this problem, but non was helping me in my case yet…
I also tried to change it to request scope but this just made my pagination disappear…
This is the BackingBean Methode which is only called from my facelet link:
/**
* Changing sorting of list of events by columns.
*
* #param event
* ActionListener for the sorting field.
*/
public void sort(String sortingAttribute) {
System.out.println("you called sort: " + ++x);
if (sortField.equalsIgnoreCase(sortingAttribute)) {
boolean sortAscHelp = (sortAsc) ? false : true;
sortAsc = sortAscHelp;
} else {
sortField = sortingAttribute;
}
try {
events = (eventListType.equalsIgnoreCase("search")) ?EventManager.getSearchResults(searchTitle, searchDate, searchLocation, sortField, sortAsc, offset, limit) : EventManager.getEventList(eventListType, offset, limit, sortField, sortAsc);
} catch (DatabaseException e) {
FacesContext fcxt = FacesContext.getCurrentInstance();
fcxt.addMessage(component.getClientId(),
new FacesMessage(e.toString()));
logger.error("Error while loading the sorted list of searched events.");
}
}
And here comes my facelet:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">
<ui:composition template="../../templates/basicTemplate.xhtml">
<ui:define name="metadata">
<f:metadata>
<f:viewParam name="title" value="#{listEventsBean.searchTitle}"/>
<f:viewParam name="location" value="#{listEventsBean.searchLocation}"/>
<f:viewParam name="date" value="#{listEventsBean.searchDate}"/>
<f:viewParam name="eventListType" value="#{listEventsBean.eventListType}"/>
<f:viewParam name="page" value="#{listEventsBean.page}"/>
<f:viewParam name="sorting" value="#{listEventsBean.sortField}"/>
<f:viewAction action="#{listEventsBean.init}"/>
</f:metadata>
</ui:define>
<ui:define name="content">
<h:form>
<p style="color:#808080; font-weight:bold; font-size:large">#{msgs.listEvents_events}</p>
<br/>
<h:outputText style="color:green" value="#{msgs.listEvents_deleted}" rendered="#{listEventsBean.deleted}"/>
<h:dataTable id="eventTable" value="#{listEventsBean.getEvents()}" var="event" binding="#{listEventsBean.component}">
<h:column>
<f:facet name="header">
<h:commandLink value="#{msgs.listEvents_title}" action="#{listEventsBean.sort('title')}">
<f:attribute name="sortField" value="title"/>
</h:commandLink>
</f:facet>
<h:outputText value="#{event.title}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:commandLink value="#{msgs.listEvents_dateStart}" action="#{listEventsBean.sort('startofevent')}">
<f:attribute name="sortField" value="startOfEvent"/>
</h:commandLink>
</f:facet>
<h:outputText value="#{event.startOfEvent}">
<f:convertDateTime pattern="#{msgs.longDate}"/>
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:commandLink value="#{msgs.listEvents_dateEnd}" action="#{listEventsBean.sort('endofevent')}">
<f:attribute name="sortField" value="endOfEvent"/>
</h:commandLink>
</f:facet>
<h:outputText value="#{event.endOfEvent}">
<f:convertDateTime pattern="#{msgs.longDate}"/>
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:commandLink value="#{msgs.listEvents_price}" action="#{listEventsBean.sort('ticketprice')}">
</h:commandLink>
</f:facet>
<h:outputText value="#{event.ticketPrice}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{msgs.listEvents_action}"/>
</f:facet>
<h:button id="showDetails" value="#{msgs.listEvents_showDetails}"
outcome="showEvent">
<f:param name="eventID" value="#{event.eventID}"/>
</h:button>
<h:commandButton id="deleteEvent" value="#{msgs.listEvents_delete}"
action="#{listEventsBean.deleteEvent(event.eventID)}"
rendered="#{sessionBean.ld.systemAdmin}"
onclick="return confirm('#{msgs.listEvents_deleteMsg}')"/>
</h:column>
</h:dataTable>
<h:outputText style="color:blue" value="#{msgs.listEvents_emptyResult}" rendered="#{listEventsBean.notEmpty}"/>
<br />
<h:outputLink id="backToSearchLink" value="#{request.contextPath}/facelets/allUsers/searchEvents.xhtml" rendered="#{listEventsBean.notEmpty}">
<h:outputText value="#{msgs.listEvents_searchAgain}"/>
</h:outputLink>
<ui:repeat id="paginationEvent" var="p" value="#{listEventsBean.getPageNumbers()}">
<h:outputLink value="#{request.contextPath}/facelets/allUsers/listEvents.xhtml">
<h:outputText value="#{p.toString()}" />
<f:param name="page" value="#{p.toString()}" />
<f:param name="sorting" value="#{listEventsBean.sortField}"/>
<f:param name="eventListType" value="#{listEventsBean.eventListType}" />
</h:outputLink>
</ui:repeat>
</h:form>
</ui:define>
</ui:composition>
</ui:composition>
Damn it! I just found my bug!
I still had a binding attached to my dataTable (beginning of dataTable).
Because of my view scope binding causes errors. One seems to be to call my method in dataTable twice (Tanks to BalusC for this info). Deleted this and added messages by rendering them as h:outputText.
I am still open for any suggestions how to change my scope to request without loosing my pagination or how to add messages from my BackingBean differently to my application without rendering h:outputText and bindings.

Jsf 2, Displaying validation messages inside dataTable

I have a problem displaying validation errors that are triggered by ui components which are
nested inside a dataTable.
Here is the xhtml page, which contains a form with a static upper part, where an address can be entered.
Below that it shows order items where users can enter amounts of items they would like to order.
These items are being retrieved from a database table and are diplayed inside a dataTable.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<ui:composition template="../templates/_standard.xhtml">
<ui:define name="pageHeadline">
#{msg['supplies.module_headline']}
</ui:define>
<ui:define name="pageContent">
<h:form id="supplies" styleClass="editForm" rendered="#{!suppliesHandler.sent}">
<h:panelGrid
columns="2"
columnClasses="tdLabel,tdValue"
rowClasses="row"
styleClass="leftPane"
>
<!-- row 1 -->
#{msg['supplies.account']}:
<h:panelGroup>
<h:inputText id="account" value="#{supply.contact.account}" tabindex="1" styleClass="text"/>
<h:message for="account" styleClass="error"/>
</h:panelGroup>
<!-- row 2 -->
#{msg['supplies.company']}:
<h:panelGroup>
<h:inputText id="company" value="#{supply.contact.company}" tabindex="2" styleClass="text"/>
<h:message for="company" styleClass="error"/>
</h:panelGroup>
<!-- row 3 -->
#{msg['supplies.street']}:
<h:panelGroup>
<h:inputText id="street" value="#{supply.contact.street}" tabindex="3" styleClass="text"/>
<h:message for="street" styleClass="error"/>
</h:panelGroup>
<!-- row 4 -->
#{msg['supplies.postcode']}:
<h:panelGroup>
<h:inputText id="postcode" value="#{supply.contact.postcode}" tabindex="4" styleClass="text"/>
<h:message for="postcode" styleClass="error"/>
</h:panelGroup>
<!-- row 5 -->
#{msg['supplies.city']}:
<h:panelGroup>
<h:inputText id="city" value="#{supply.contact.city}" tabindex="5" styleClass="text"/>
<h:message for="city" styleClass="error"/>
</h:panelGroup>
</h:panelGrid>
<h:panelGrid
columns="2"
columnClasses="tdLabel,tdValue"
rowClasses="row"
styleClass="rightPane"
>
<!-- row 2 -->
#{msg['supplies.contact']}:
<h:panelGroup>
<h:inputText id="contact" value="#{supply.contact.contact}" tabindex="6" styleClass="text"/>
<h:message for="contact" styleClass="error"/>
</h:panelGroup>
<!-- row 3 -->
#{msg['supplies.phone']}:
<h:panelGroup>
<h:inputText id="phone" value="#{supply.contact.phone}" tabindex="7" styleClass="text"/>
<h:message for="phone" styleClass="error"/>
</h:panelGroup>
<!-- row 4 -->
#{msg['supplies.email']}:
<h:panelGroup>
<h:inputText id="email" value="#{supply.contact.email}" tabindex="8" styleClass="text">
<f:validator validatorId="com.abc.myproduct.be.ui.validator" />
</h:inputText>
<h:message for="email" styleClass="error"/>
</h:panelGroup>
<!-- row 5 -->
#{msg['supplies.fax']}:
<h:panelGroup>
<h:inputText id="fax" value="#{supply.contact.fax}" tabindex="9" styleClass="text"/>
<h:message for="fax" styleClass="error"/>
</h:panelGroup>
</h:panelGrid>
<div class="spacer"></div>
<h:dataTable id="items"
styleClass="listing_large"
value="#{supply.supplyItems}"
headerClass="heading"
var="item">
<h:column>
<f:facet name="header">
#{msg['supplies.id']}
</f:facet>
<h:outputText value="#{item.supply_id}" />
</h:column>
<h:column>
<f:facet name="header">
#{msg['supplies.amount']}
</f:facet>
<h:inputText value="#{item.amount}" id="amount" styleClass="text" size="3" maxlength="3" style="width:50px"/>
</h:column>
<h:column>
<f:facet name="header">
#{msg['supplies.description']}
</f:facet>
<h:outputText value="#{item.description}" />
</h:column>
</h:dataTable>
<div><br/>
<h:messages globalOnly="true" layout="table" styleClass="error"/>
</div>
<h:panelGrid
columns="1"
columnClasses="tdLabel,tdValue"
rowClasses="row">
<!-- row 2 -->
<h:panelGroup>
<h:commandButton value="#{msg['general.submit']}" action="#{suppliesHandler.submitMessage}" styleClass="button"/>
</h:panelGroup>
</h:panelGrid>
</h:form>
<h:messages globalOnly="true" layout="table" rendered="#{suppliesHandler.sent}"/>
</ui:define>
</ui:composition>
</html>
Validation for the address part of the form works perfect.
Only the messages for this part of the form are not being displayed:
<h:dataTable id="items"
styleClass="listing_large"
value="#{supply.supplyItems}"
headerClass="heading"
var="item">
<h:column>
<f:facet name="header">
#{msg['supplies.id']}
</f:facet>
<h:outputText value="#{item.supply_id}" />
</h:column>
<h:column>
<f:facet name="header">
#{msg['supplies.amount']}
</f:facet>
<h:inputText value="#{item.amount}" id="amount" styleClass="text" size="3" maxlength="3" style="width:50px"/>
</h:column>
<h:column>
<f:facet name="header">
#{msg['supplies.description']}
</f:facet>
<h:outputText value="#{item.description}" />
</h:column>
</h:dataTable>
Validation is being carried out through BeanValidation:
public class SupplyItem implements Serializable {
private static final long serialVersionUID = 1L;
#Id
private long supply_id;
private String description;
private int orderNo;
#Transient
#Max(value=200)
private int amount;
/*
* constructor
*/
public SupplyItem() {
super();
}
public long getSupply_id() {
return supply_id;
}
public void setSupply_id(long supply_id) {
this.supply_id = supply_id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getOrderNo() {
return orderNo;
}
public void setOrderNo(int orderNo) {
this.orderNo = orderNo;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
}
It gets actually being validated, however the messages are not being displayed...
12:29:45,860 Information [javax.enterprise.resource.webcontainer.jsf.renderkit] (http--127.0.0.1-8080-2) WARNUNG: FacesMessage(s) wurde(n) in die Warteschlange gestellt, aber möglicherweise nicht angezeigt.
sourceId=supplies:items:0:amount[severity=(ERROR 2), summary=(Allowed maximum is 200), detail=(Allowed maximum is 200)]
sourceId=supplies:items:1:amount[severity=(ERROR 2), summary=(supplies:items:1:amount: 'a' must be a number consisting of one or more digits.), detail=(supplies:items:1:amount: 'a' must be a number between -2147483648 and 2147483647 Example: 9346)]
Trying to set the id of the input field dynamically in conjunction with a
h:message for="" did not work,displaying it through h:messages globalOnly="true" neither.
Any help would be highly appreciated.
You have not put a <h:message> for the input field anywhere in the datatable. You need to put a
<h:message for="amount" />
somewhere in the datatable exactly there where you'd like to display them.
The <h:messages globalOnly="true"> only displays messages with a null client ID, so that surely won't work at all for messages with a non-null client ID. You'd need to remove globalOnly="true" in order to display messages which are not shown anywhere else.

Resources