I have a composite component (collapsiblePanel). The component uses the "collapsible" bean to provide the toggle function. When I use the same component multiple times on a page, each instance of the component is bound to the same bean instance. How Can I achieve something like a component scoped bean?
collapsibleTemp.xhtml:
<cc:interface>
<cc:attribute name="model" required="true">
<cc:attribute name="collapsed" required="true" />
<cc:attribute name="toggle" required="true"
method-signature="java.lang.String f()" />
</cc:attribute>
<cc:actionSource name="toggle" />
<cc:facet name="header" />
<cc:facet name="body" />
</cc:interface>
<cc:implementation>
<h:panelGroup layout="block" styleClass="collapsiblePanel-header">
<h:commandButton id="toggle" action="#{cc.attrs.model.toggle}"
styleClass="collapsiblePanel-img"
image="#{cc.attrs.model.collapsed ? '/resources/images/plus.png' : '/resources/images/minus.png'}" />
<cc:renderFacet name="header" />
</h:panelGroup>
<h:panelGroup layout="block" rendered="#{!cc.attrs.model.collapsed}">
<cc:insertChildren />
<cc:renderFacet name="body"></cc:renderFacet>
</h:panelGroup>
<h:outputStylesheet library="css" name="components.css" />
</cc:implementation>
The backing bean:
#ManagedBean
#ViewScoped
public class Collapsible {
private boolean collapsed = false;
public boolean isCollapsed() {
return collapsed;
}
public void setCollapsed(boolean collapsed) {
this.collapsed = collapsed;
}
public String toggle() {
collapsed = !collapsed;
return null;
}
}
Using Page
<h:form id="someid">
<jl:collapsibletemp id="collapsiblePanel1" model="#{collapsible}">
<f:facet name="header">
<h3>
<h:outputText value="Collapsible information" />
</h3>
</f:facet>
<f:facet name="body">
<h:outputText value="do something....." />
</f:facet>
<p />
</jl:collapsibletemp>
<jl:collapsibletemp id="collapsiblePanel2" model="#{collapsible}">
<f:facet name="header">
<h3>
<h:outputText value="Collapsible information" />
</h3>
</f:facet>
<f:facet name="body">
<h:outputText value="do some tabbing" />
</f:facet>
<p />
</jl:collapsibletemp>
<jl:collapsibletemp id="collapsiblePanel3" model="#{collapsible}">
<f:facet name="header">
<h3>
<h:outputText value="Collapsible information" />
</h3>
</f:facet>
<f:facet name="body">
<h:outputText value="notice board" />
</f:facet>
<p />
</jl:collapsibletemp>
</h:form>
You can use the componentType attribute of the <cc:interface> to define a "backing component".
E.g.
<cc:interface componentType="collapsiblePanel">
...
</cc:interface>
<cc:implementation>
...
<h:commandButton action="#{cc.toggle}" ... />
...
<h:panelGroup rendered="#{!cc.collapsed}" ...>
...
</cc:implementation>
with just a com.example.components.CollapsiblePanel
#FacesComponent(value="collapsiblePanel") // To be specified in componentType attribute.
public class CollapsiblePanel extends UINamingContainer { // Important! Must extend UINamingContainer.
private boolean collapsed;
public void toggle() {
collapsed = !collapsed;
}
public boolean isCollapsed() {
collapsed;
}
}
However, when you want to have multiple of those components, then you should declare physically separate instances of them in the view. If this needs to happen dynamically, then you need to use <c:forEach> to generate physically separate instances of them instead of <ui:repeat> with a single component. Otherwise you have to map all collapsed states by the client ID inside a Map<String, Boolean>. See for an example and more background information also Getting same instance of `componentType` in composite component on every use
Related
I want to render a button after upload a file, I have selectOneMenuto chose options, when I upload the file with the first option, the button didn't rendered but it rendered after I chose the second option.
ManagedBean.java
private boolean viewImport;
public boolean isViewImport() {
return viewImport;
}
public void setViewImport(boolean viewImport) {
this.viewImport = viewImport;
}
public void processFiless(FileUploadEvent event) {
setViewImport(true);
}
import.xhtml
<ui:composition template="./../../../../template.xhtml">
<ui:define name="content">
<h:form id="form1" prependId="false">
<p:growl id="messages"/>
<h1><h:outputText value="#{customerData.importBatchTitle}" /></h1>
<div class="formSection">
<p:panel header="#{app['import.fileSelectionForm']}" id="importFile" toggleable="true" toggleSpeed="300">
<h:graphicImage styleClass="formimg" url="/images/orange/fleche2.gif"/><h:outputText value="#{app['import.contract.parameter.primal']}" />
<h:selectOneMenu value="#{customerData.parameterType}">
<f:selectItems value="#{customerData.parameterTypeItems}" />
<p:ajax actionListener="#{customerData.selectionParameterType}" event="change" update="form1"/>
</h:selectOneMenu>
<br/>
<br/>
<h:panelGroup rendered="#{customerData.viewUpload}">
<p:fileUpload update="form1" fileUploadListener="#{customerData.processFiless}" >
<p:ajaxStatus>
<f:facet name="start">
<h:graphicImage value="/images/ajaxloading.gif" />
</f:facet>
<f:facet name="complete" >
<h:outputText value="" />
</f:facet>
</p:ajaxStatus>
</p:fileUpload>
</h:panelGroup>
</p:panel>
<br/>
<f:subview id="modifyCustt" rendered="#{customerData.viewImport}">
<p:commandButton value="ok"></p:commandButton>
</f:subview>
</div>
</h:form>
</ui:define>
</ui:composition>
I'm using <ui:include> to load a data table (I'm using Primefaces). I want use <ui:param> in the listener into the tag <p:ajax>. I tested the code that is down, but not trigger the event onRowEdit or onRowCancel.
This is my page:
...
<ui:include src="../Componentes/tablaEditable.xhtml">
<ui:param name="columnas" value="#{tabla2FuentesHL7.dataTableColumns}" />
<ui:param name="bean" value="#{tabla2FuentesHL7.listTabla2FuenteDTO}" />
<ui:param name="aceptarEdicion" value="#{tabla2FuentesHL7.onRowEdit}" />
<ui:param name="cancelarEdicion" value="#{tabla2FuentesHL7.onRowCancel}" />
</ui:include>
...
My data table:
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:form >
<p:dataTable value="#{bean}" scrollable="true" scrollHeight="100" var="dato" editable="true">
<p:ajax event="rowEdit" listener="#{aceptarEdicion}" />
<p:ajax event="rowEditCancel" listener="#{cancelarEdicion}" />
<c:forEach items="#{columnas}" var="column" varStatus="loop">
<p:column headerText="#{column.header}" sortBy="#{dato[column.property]}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{dato[column.property]}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{dato[column.property]}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
</c:forEach>
<p:column style="width:32px">
<p:rowEditor />
</p:column>
</p:dataTable>
</h:form>
My bean:
#ManagedBean(name = "tabla2FuentesHL7")
#ViewScoped
enter code herepublic class Tabla2FuentesHL7 {
private static final long serialVersionUID = 1L;
private List<DataTableColumn> dataTableColumns = new ArrayList<DataTableColumn>();
private List<Tabla2FuenteDTO> listTabla2FuenteDTO = new ArrayList<Tabla2FuenteDTO>();
#PostConstruct
public void init() {
listTabla2FuenteDTO = Test.getFuenteTabla2();
dataTableColumns = CargarTablas.getTabla2FuenteHL7();
}
public List<Tabla2FuenteDTO> getListTabla2FuenteDTO() {
return listTabla2FuenteDTO;
}
public List<DataTableColumn> getDataTableColumns() {
return dataTableColumns;
}
public void onRowEdit(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Elemento modificado");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onRowCancel(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Modificación cancelada");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onCellEdit(CellEditEvent event) {
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
if (newValue != null && !newValue.equals(oldValue)) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed", "Old: " + oldValue + ", New:" + newValue);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
}
This is the error:
javax.el.PropertyNotFoundException: /Componentes/tablaEditable.xhtml #12,76 listener="#{cancelarEdicion}": /Modulos/hl7.xhtml #31,104 value="#{tabla2FuentesHL7.onRowCancel}": The class 'com.queres.xedoc.consola.componentes.Tabla2FuentesHL7' does not have the property 'onRowCancel'.
If I change this:
<p:ajax event="rowEdit" listener="#{aceptarEdicion}" />
<p:ajax event="rowEditCancel" listener="#{cancelarEdicion}" />
for this:
<p:ajax event="rowEdit" listener="#{tabla2FuentesHL7.onRowEdit}" />
<p:ajax event="rowEditCancel" listener="#{tabla2FuentesHL7.onRowCancel}" />
my code works fine, but I need a dynamic data table. Is there any way to pass a parameter to the listener?
Thanks!
The <ui:param> can only pass value expressions, not method expressions.
Better make use of the ability of EL to parameterize method names via brace [] notation. Then you can just declare the method names as plain vanilla String.
<ui:include src="../Componentes/tablaEditable.xhtml">
...
<ui:param name="beanEdicion" value="#{tabla2FuentesHL7}" />
<ui:param name="aceptarEdicion" value="onRowEdit" />
<ui:param name="cancelarEdicion" value="onRowCancel" />
</ui:include>
<p:ajax event="rowEdit" listener="#{beanEdicion[aceptarEdicion]()}" />
<p:ajax event="rowEditCancel" listener="#{beanEdicion[cancelarEdicion]()}" />
Update as per the comments, it appears to still not work in PrimeFaces 5.1 even though the related issue says that it's already fixed in 3.5. You'd basically need to reopen the issue.
In the meanwhile, you can workaround this with help of <o:methodParam> tag of JSF utility library OmniFaces. This basically converts a value expression to a method expression:
<ui:include src="../Componentes/tablaEditable.xhtml">
...
<ui:param name="aceptarEdicion" value="#{tabla2FuentesHL7.onRowEdit}" />
<ui:param name="cancelarEdicion" value="#{tabla2FuentesHL7.onRowCancel}" />
</ui:include>
<o:methodParam name="aceptarEdicionParam" value="#{aceptarEdicion}" />
<o:methodParam name="cancelarEdicionParam" value="#{cancelarEdicion}" />
...
<p:ajax event="rowEdit" listener="#{aceptarEdicionParam}" />
<p:ajax event="rowEditCancel" listener="#{cancelarEdicionParam}" />
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.
I have got some problems with my JSF page, and (probably) with backing bean. I have got own template and I fill the content area with some pages. I have got search page with commandbutton and I would like to get data from database (JPA) and than fill the datatable.
Look at my searchpeople.xhtml:
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
template="template.xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<ui:define name="content">
<h:form id="sampleform">
<p:accordionPanel activeIndex="-1" id="accordingpanle">
<p:tab title="User options" >
<p:growl id="growl" showDetail="true" showSummary="true"/>
<p:commandButton id="searchbutton" action="#{mb_person.search}" value="Szukaj" update="personsearchresulttable" />
</p:tab>
</p:accordionPanel>
<p:dataTable id="personsearchresulttable" var="person" value="#{mb_person.people}" widgetVar="personTable" style="margin-top: 10px" >
<p:column headerText="Id" style="width:10%">
<h:outputText value="#{person.id}" />
</p:column>
<p:column headerText="Name" style="width:20%">
<h:outputText value="#{person.name}" />
</p:column>
<p:column headerText="Surname" style="width:20%">
<h:outputText value="#{person.surname}" />
</p:column>
<p:column headerText="Company">
<h:outputText value="#{person.companyName}" />
</p:column>
<p:column style="width:4%" headerText="Open">
<h:link outcome="persondetails" value="Open">
<!--<f:param name="personid" value="#{person.id}"/>-->
<f:param name="personid" value="10076"/>
</h:link>
</p:column>
</p:dataTable>
</h:form>
</ui:define>
</ui:composition>
And my backingbean with EJB injection.
#ManagedBean(name="mb_person")
public class MB_Person implements Serializable{
#EJB
private PersonFacade personFacade;
private List<PersonAndCompany> people = new ArrayList<PersonAndCompany>();
public MB_Person() {
}
public List<PersonAndCompany> getPeople() {
return people;
}
public void setPeople(List<PersonAndCompany> people) {
this.people = people;
}
public void search() {
int[] range = {0,5};
setPeople(personFacade.findPersonWithMoreThanXProjects(20));
setPeople(personFacade.findPersonAndCompanyName(range));
for(PersonAndCompany p:people){
System.out.println(p.getName());
}
}
public String goToPersonDatailPage(int id){
return "persondetails.jsf?personid="+id;
}
}
I tried small test and printout all data in method search and I received good results.
Someone can help me how to update dataTable using ajax? In this form I have got an exception
Cannot find component with identifier "personsearchresulttable" referenced from "sampleform:accordingpanle:searchbutton".
Relative client IDs are searched relative to parent NamingContainer component. The <p:accordionPanel> is by itself a NamingContainer. So the relative client ID personsearchresulttable would be searched inside the context of the <p:accordionPanel>. However, it's actually outside the panel, inside the <h:form>.
You need to change the relative client ID to be an absolute client ID.
update=":sampleform:personsearchresulttable"
See also:
How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"
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.