I want to generate selecOneMenu content when the user types in an inputText field, and respond to combo box selection changes.
The below code updates the contents of the selecOneMenu as the user types. (The typed and the next 9 numbers gets added to the combo box. This is just a simplified example code.)
When the page is loaded, the change event of the selecOneMenu correctly gets fired.
However after typing in the inputValue field, content of selecOneMenu is changed, and the change event is not fired when I select an item.
The code works if ComboBean is session scoped, but I want to avoid this solution if possible.
Is it possible at all to do this?
What is the reason if it is not possible with request scope?
PrimeFaces 2.2
Mojarra 2.0.2
GlassFish 3.0.1
Browser: Chrome, Firefox, IE
combo.xhtml:
<h:head>
<title>Combo box example</title>
</h:head>
<h:body>
<h:form>
<p:panel id="mainPanel">
<h:panelGroup id="formToSubmit" layout="block">
<p:messages id="messages" />
<h:panelGrid columns="2">
<h:outputLabel value="Enter a number" />
<h:inputText id="inputValue" value="#{comboBean.inputValue}">
<p:ajax event="keyup" update="combo"
listener="#{comboBean.onKeyUp}" />
</h:inputText>
<h:outputLabel value="Select a value:" />
<h:selectOneMenu id="combo" value="#{comboBean.selectedValue}">
<f:selectItem itemLabel="Select a value..."
noSelectionOption="true" />
<f:selectItems value="#{comboBean.values}" />
<p:ajax event="change" update="selectedValue"
listener="#{comboBean.valueSelected}" />
</h:selectOneMenu>
<h:outputLabel value="Selected value:" />
<h:inputText id="selectedValue" value="#{comboBean.selectedValue}" />
</h:panelGrid>
</h:panelGroup>
</p:panel>
</h:form>
</h:body>
</html>
ComboBean.java
package x;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
#Named
#RequestScoped
public class ComboBean implements Serializable
{
private static final long serialVersionUID = 1L;
private String inputValue;
private String selectedValue;
private List<String> values;
#PostConstruct
void init()
{
System.out.println("init");
setValues(new LinkedList<String>());
for(int i = 0; i<10 ; i++)
{
getValues().add(""+i);
}
}
public void onKeyUp()
{
System.out.println("onkeyUp " + getInputValue());
setValues(new LinkedList<String>());
if (inputValue != null)
{
try
{
int v = Integer.parseInt(inputValue);
for(int i = 0; i<10 ; i++)
{
getValues().add(""+(v+i));
}
}
catch (NumberFormatException ne)
{
//doesn't matter
}
}
}
public void valueSelected()
{
System.out.println("valueSelected " + getSelectedValue());
}
public void submit()
{
System.out.println("submit " + getInputValue());
}
public void setInputValue(String inputValue)
{
this.inputValue = inputValue;
}
public String getInputValue()
{
return inputValue;
}
public void setSelectedValue(String selectedValue)
{
this.selectedValue = selectedValue;
}
public String getSelectedValue()
{
return selectedValue;
}
public void setValues(List<String> values)
{
this.values = values;
}
public List<String> getValues()
{
return values;
}
}
The problem is that you reset your list during each request in the init() method. So your selected element will no longer be there.
If you don't want to use SessionScope, maybe the ViewScope would be a solution: then the bean won't be reset if the same page is reloaded.
Related
In SQL Server, I have a schema (ade) with some tables, which two of them are:
I'm using Eclipselink ORM and Primefaces 6.2; I have a CRUD for both tables, which works fine.
In a ListDemandas.jsf, I have a datatable where the user can insert a new Demandas registry by clicking in a button. Then, a Dialog (located in the
CreateDemandas.jsf) is displayed to input data in some fields. After clicking on a save button, such Dialog is hidden and the datatable is updated, showing this new Demandas record; the same action occurs to the Anotacoes entity, using a ListAnotacoes.jsf and a CreateAnotacoes.jsf .
What I want is to insert Anotacoes registries through the ListDemandas.jsf page and, right after saving that new Anotacoes registry, it would be displayed in the Demandas datatable (which is in the ListDemandas.jsf page).
What I achieved so far to do it: I put a button in the ListDemandas.jsf to invoke the Dialog (located in CreateAnotacoes.jsf). After clicking on a save button in such Dialog, this (Anotacoes) Dialog is hidden and the data is correctly persisted in the database.
The problem is that this new Anotacoes record is not being displayed in the Demandas datatable, even updating as below:
<p:commandButton actionListener="#{anotacoesController.saveNew}" value="Save" update="display,:DemandasListForm:datalist,:DemandasListForm:DemandasDataTableContextMenu,:growl" oncomplete="handleSubmit(xhr,status,args,PF('AnotacaoCreateDialog'));" >
The ListDemandas.jsf:
<h:form id="DemandasListForm">
<p:panel id="PanelListForm" header="#{adeBundle.ListDemandasTitle}">
<p:commandButton id="createButton" value="Create Demanda" update=":DemandasCreateForm" oncomplete="PF('DemandasCreateDialog').show()" actionListener="#{demandasController.prepareCreate}" />
<p:commandButton id="createAnotacaoButton" value="Create Anotacao" update=":AnotacaoCreateForm, datalist" oncomplete="PF('AnotacaoCreateDialog').show()" />
<p:dataTable id="datalist"
value="#{demandasController.items}"
lazy="false"
rowKey="#{item.id}"
var="item"
selection="#{demandasController.selected}"
widgetVar="demandasTable">
<p:ajax event="rowSelect" update="#form:createAnotacaoButton, #form:createButton" listener="#{demandasController.resetParents}"/>
<p:ajax event="rowUnselect" update="#form:createAnotacaoButton, #form:createButton" listener="#{demandasController.resetParents}"/>
<p:ajax event="contextMenu" update="#form:createAnotacaoButton, #form:createButton" listener="#{demandasController.resetParents}"/>
<p:column id="idCod" >
<f:facet name="header">
<h:outputText value="id"/>
</f:facet>
<h:outputText value="#{item.id}"/>
</p:column>
<!-- some columns ommited -->
<p:rowExpansion>
<p:panelGrid>
<p:column>
<p:row>
<p:accordionPanel value="Mais informacoes da Demanda" multiple="true">
<p:tab title="Anotacoes}" >
<p:dataList value="#{item.anotacoesCollection}" var="anotacoesCollectionItem" itemType="none" emptyMessage="-" >
<h:outputText value="#{anotacoesCollectionItem.anotacao.toString()}" />
</p:dataList>
</p:tab>
</p:accordionPanel>
</p:row>
</p:column>
</p:panelGrid>
</p:rowExpansion>
</p:dataTable>
</p:panel>
<ui:include src="/WEB-INF/include/confirmation.xhtml"/>
</h:form>
The CreateAnotacao.jsf:
<p:dialog id="AnotacaoCreateDlg" widgetVar="AnotacaoCreateDialog" modal="true" appendTo="#(body)" header="Create Anotacoes" >
<h:form id="AnotacaoCreateForm" >
<h:panelGroup id="display" >
<p:panelGrid columns="2" columnClasses="column">
<p:outputLabel value="CreateAnotacoesLabel_anotacao" for="anotacao" />
<h:panelGroup>
<p:inputTextarea id="anotacao" value="#{anotacoesController.selected.anotacao}" title="CreateAnotacoesTitle_anotacao" />
</h:panelGroup>
<p:outputLabel value="CreateAnotacoesLabel_date" for="date" />
<h:panelGroup>
<p:calendar id="date" value="#{demandasController.currentDate}" title="CreateAnotacoesTitle_date" />
</h:panelGroup>
<!-- some other input fields ommited -->
</p:panelGrid>
</h:panelGroup>
<p:commandButton actionListener="#{anotacoesController.saveNew}" value="Save" update="display, :DemandasListForm:datalist, :growl" oncomplete="handleSubmit(xhr,status,args,PF('AnotacaoCreateDialog'));" >
<p:confirm header="Confirmation" message="Are you sure ?" />
</p:commandButton>
<p:commandButton value="Cancel" oncomplete="PF('AnotacaoCreateDialog').hide()" update="display" process="#this" immediate="true" resetValues="true"/>
</h:form>
</p:dialog>
Excerpts of the AbstractController.java class:
public abstract class AbstractController<T> implements Serializable {
private static final long serialVersionUID = 1L;
private Class<T> itemClass;
private T selected;
private Collection<T> items;
private List<T> filteredItems;
private enum PersistAction {
CREATE,
DELETE,
UPDATE
}
public AbstractController() {
}
public AbstractController(Class<T> itemClass) {
this.itemClass = itemClass;
}
public void setSelected(T selected) {
if (selected != null) {
if (this.selected == null || !this.selected.equals(selected)) {
this.selected = this.ejbFacade.findWithParents(selected);
this.setChildrenEmptyFlags();
}
} else {
this.selected = null;
}
}
protected void setEmbeddableKeys() {
}
protected void initializeEmbeddableKey() {
}
public Collection<T> getItems() {
if (itemClass.getSimpleName().equals("Demandas")) {
if (sessionPrefixo == 9600) {
items = this.ejbFacade.findAll();
} else {
items = this.ejbFacade.findAllVenceHojeByNomeUorPos(uorPosDiageJurisdiciona);
}
}
return items;
}
public void save(ActionEvent event) {
String msg = ResourceBundle.getBundle("/adeBundle").getString(itemClass.getSimpleName() + "Updated");
persist(PersistAction.UPDATE, msg);
if (!isValidationFailed()) {
// Update the existing entity inside the item list
List<T> itemList = refreshItem(this.selected, this.items);
// If the original list has changed (it is a new object)
if (this.items != itemList) {
this.setItems(itemList);
}
// Also refresh the filteredItems list in case the user has filtered the DataTable
if (filteredItems != null) {
refreshItem(this.selected, this.filteredItems);
}
}
}
public void saveNew(ActionEvent event) {
String msg = ResourceBundle.getBundle("/adeBundle").getString(itemClass.getSimpleName() + "Created");
persist(PersistAction.CREATE, msg);
if (!isValidationFailed()) {
items = null; // Invalidate list of items to trigger re-query.
lazyItems = null; // Invalidate list of lazy items to trigger re-query.
}
}
private void persist(PersistAction persistAction, String successMessage) {
if (selected != null) {
this.setEmbeddableKeys();
try {
if (persistAction != PersistAction.DELETE) {
this.ejbFacade.edit(selected);
} else {
this.ejbFacade.remove(selected);
}
this.setChildrenEmptyFlags();
JsfUtil.addSuccessMessage(successMessage);
} catch (EJBException ex) {
Throwable cause = JsfUtil.getRootCause(ex.getCause());
if (cause != null) {
if (cause instanceof ConstraintViolationException) {
ConstraintViolationException excp = (ConstraintViolationException) cause;
for (ConstraintViolation s : excp.getConstraintViolations()) {
JsfUtil.addErrorMessage(s.getMessage());
}
} else {
String msg = cause.getLocalizedMessage();
if (msg.length() > 0) {
JsfUtil.addErrorMessage(msg);
} else {
JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
}
}
}
} catch (Exception ex) {
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
JsfUtil.addErrorMessage(ex, ResourceBundle.getBundle("/adeBundle").getString("PersistenceErrorOccured"));
}
}
}
public T prepareCreate(ActionEvent event) {
T newItem;
try {
newItem = itemClass.newInstance();
this.selected = newItem;
initializeEmbeddableKey();
return newItem;
} catch (InstantiationException | IllegalAccessException ex) {
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
}
return null;
}
public boolean isValidationFailed() {
return JsfUtil.isValidationFailed();
}
public String getComponentMessages(String clientComponent, String defaultMessage) {
return JsfUtil.getComponentMessages(clientComponent, defaultMessage);
}
#PostConstruct
public void initParams() {
Object paramItems = FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get(itemClass.getSimpleName() + "_items");
if (paramItems != null) {
setItems((Collection<T>) paramItems);
}
}
private List<T> refreshItem(T item, Collection<T> items) {
List<T> itemList;
if (this.items instanceof List) {
itemList = (List<T>) items;
} else {
itemList = new ArrayList<>(items);
}
int i = itemList.indexOf(item);
if (i >= 0) {
try {
itemList.set(i, item);
} catch (UnsupportedOperationException ex) {
return refreshItem(item, new ArrayList<>(items));
}
}
return itemList;
}
public AbstractFacade<T> getEjbFacade() {
return ejbFacade;
}
public void setEjbFacade(AbstractFacade<T> ejbFacade) {
this.ejbFacade = ejbFacade;
}
}
Excerpt of the AbstractFacade.java class:
[...]
public void edit(T entity) {
getEntityManager().merge(entity);
}
[...]
As mentioned in the comments, this is the reference for Demandas table:
Please, can someone help me to resolve it ?
PrimeFaces 6.1.
I have a SelectOneListBox with letters. Upon change, ajax event is triggered and fills PickList with words starting with selected letter. The PickList is valid if it contains the word XX, where X is the selected letter.
If the PickList is valid, everything works fine. If it gets invalidated, everything works fine (ajax is fired, messages are rerendered, etc.), only the PickList is not refreshed upon letters change, unless it is valid again.
Is there a way how to rerender the PickList, even if it not valid?
The code: Web.xhtml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE composition 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 />
<h:body>
<f:view>
<h:form>
<p:selectOneListbox value="#{Web.letter}" required="true">
<f:selectItems value="#{Web.letters}" var="letter"
itemValue="#{letter}" />
<p:ajax event="change" update="words"
listener="#{Web.letterChanged}" />
</p:selectOneListbox>
<h:panelGrid columns="2" id="words">
<p:pickList id="pickList" value="#{Web.words}" var="word"
itemLabel="#{word}" itemValue="#{word}"
validator="#{Web.validateWords}" showSourceFilter="true"
filterMatchMode="startsWith" showTargetControls="true">
<p:ajax event="reorder" update="pickListMessages" />
<p:ajax event="transfer" update="pickListMessages" />
</p:pickList>
<p:message id="pickListMessages" for="pickList" />
</h:panelGrid>
</h:form>
</f:view>
</h:body>
</html>
Web.java:
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.validator.ValidatorException;
import org.primefaces.model.DualListModel;
#ManagedBean (name = "Web")
#ViewScoped
#SuppressWarnings (
{ "javadoc", "nls", "unused" })
public class WebBean implements Serializable
{
private static final long serialVersionUID = 4067529596686991391L;
private Set<String> letters = new TreeSet<> (Arrays.asList ("A", "B", "C"));
private String letter = "A";
private DualListModel<String> words = new DualListModel<> (new ArrayList<> (),
new ArrayList<> ());
public Set<String> getLetters ()
{
return letters;
}
public String getLetter ()
{
return letter;
}
public void setLetter (String letter)
{
this.letter = letter;
}
public DualListModel<String> getWords ()
{
return words;
}
public void setWords (DualListModel<String> words)
{
this.words = words;
}
private void refreshWordsList ()
{
List<String> source = words.getSource ();
source.clear ();
source.addAll (Arrays.asList (letter + 'A', letter + 'B', letter + 'C'));
words.getTarget ().clear ();
}
public void letterChanged (AjaxBehaviorEvent ajaxEvent)
{
refreshWordsList ();
}
public void validateWords (FacesContext ctx, UIComponent component,
Object value) throws ValidatorException
{
#SuppressWarnings ("unchecked")
DualListModel<String> dualListModel = (DualListModel<String>) value;
List<String> validatedWords = dualListModel.getTarget ();
for (String word : validatedWords)
{
// OK?
if (word.charAt (0) == word.charAt (1))
{
return;
}
}
throw new ValidatorException (
new FacesMessage (FacesMessage.SEVERITY_ERROR, "No double", null));
}
}
There is a list that is dynamically generated at runtime. I am using a dataTable to represent it. Inside each row is a dropdown list. As soon as the user selects a value from the drop down list in a row, then all the other rows must be disabled.?
<h:dataTable value="#{user.orderList}" var="item">
<h:column>
<h:selectOneMenu value="#{user.sometuff}" >
<f:selectItems value="#{user.someItems}" />
</h:selectOneMenu>
</h:column>
</h:dataTable>
How can I achieve this with <f:ajax>?
here is a working example.
imho, it's way easier to implement with ajax4jsf (richfaces), using a4j:repeat and a4j:ajax tags.
xhtml code:
<h:form id="form">
<h:dataTable id="tableId" value="#{user.orderList}" var="item">
<h:column>
<h:selectOneMenu value="#{item.selectedItem}" disabled="#{user.oneItemSelected and (item.selectedItem == null || item.selectedItem == '')}">
<f:selectItems value="#{user.selectItemList}" />
<f:ajax execute="#this" render="#form" listener="#{user.updateSelectionFlag}"></f:ajax>
</h:selectOneMenu>
</h:column>
</h:dataTable>
</h:form>
order item code:
public class Order implements Serializable
{
private static final long serialVersionUID = 1L;
private String selectedItem;
public String getSelectedItem() {
return selectedItem;
}
public void setSelectedItem(String selectedItem) {
this.selectedItem = selectedItem;
}
}
managed bean code:
#Named
#ViewScoped
public class User implements Serializable {
private static final long serialVersionUID = 1L;
private List<Order> orderList;
private List<SelectItem> selectItemList;
private boolean oneItemSelected;
public List<SelectItem> getSelectItemList() {
if (selectItemList == null)
{
selectItemList = new ArrayList<SelectItem>();
selectItemList.add(new SelectItem("", "---Please Choose---"));
selectItemList.add(new SelectItem("1", "Item 1"));
selectItemList.add(new SelectItem("2", "Item 2"));
selectItemList.add(new SelectItem("3", "Item 3"));
selectItemList.add(new SelectItem("4", "Item 4"));
}
return selectItemList;
}
public List<Order> getOrderList() {
if (orderList == null)
{
orderList = new ArrayList<Order>();
for (int i=0 ; i<4 ; i++)
{
orderList.add(new Order());
}
}
return orderList;
}
public boolean isOneItemSelected() {
return oneItemSelected;
}
public void updateSelectionFlag()
{
oneItemSelected = false;
for (int i=0 ; i<getOrderList().size() ; i++)
{
Order order = getOrderList().get(i);
if (order.getSelectedItem() != null && !order.getSelectedItem().equals(""))
{
oneItemSelected = true;
break;
}
}
}
}
by the way, instead of checking the whole array in updateSelectionFlag, it's better to check only the submitted item's value. but i couldn't figure out how to get the clicked row index of h:dataTable. doing a binding prevents combo values from being submitted, and datatable does not provide a varStatus attribute like ui:repeat does.
I have table Providers.I am displaying the table contents in primefaces datatable and performing create,edit and delete operations on it using Jdbc and Tomcat 7.0.
In the edit dialog there are save and cancel buttons. When I click the cancel button and click on the edit button of another row the values of previous row are getting displayed.
I am getting the following warnings when I click on the cancel button:
com.sun.faces.application.view.FaceletPartialStateManagementStrategy saveDynamicActions
WARNING: Unable to save dynamic action with clientId 'editproviderform:btnCancelProviders' because the UIComponent cannot be found
Providers table structure:
ProviderId,
ProviderFirstName and
ProviderLastName
Providers.java
public class Providers implements Serializable {
private static final long serialVersionUID = 1L;
private Integer providerId;
private String providerFirstName;
private String providerLastName;
public Providers() {
}
public Providers(Integer providerId) {
this.providerId = providerId;
}
public Providers(Integer providerId, String providerFirstName, String providerLastName) {
this.providerId = providerId;
this.providerFirstName = providerFirstName;
this.providerLastName = providerLastName;
}
public Integer getProviderId()
{
return providerId;
}
public void setProviderId(Integer providerId)
{
this.providerId=providerId;
}
public String getProviderFirstName()
{
return providerFirstName;
}
public void setProviderFirstName(String providerFirstName)
{
this.providerFirstName=providerFirstName;
}
public String getProviderLastName()
{
return providerLastName;
}
public void setProviderLastName(String providerLastName)
{
this.providerLastName=providerLastName;
}
}
ProvidersBean.java
#ManagedBean(name = "providersBean")
#SessionScoped
public class ProvidersBean implements Serializable {
private Providers selectedProvider;
public Providers getSelectedProvider() {
return selectedProvider;
}
public void setSelectedProvider(Providers selectedProvider) {
this.selectedProvider = selectedProvider;
}
private Connection con;
#Resource(name = "jdbc/abc")
private DataSource ds;
public ProvidersBean() {
try {
Context ctx = new InitialContext();
ds = (DataSource) ctx.lookup("java:comp/env/jdbc/ClinicalStudy");
} catch (NamingException e) {
e.printStackTrace();
}
}
public void updateProvider() {
try {
con = ds.getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE Providers SET
ProviderFirstName=?,ProviderLastName=? WHERE ProviderId=?");
ps.setString(1, selectedProvider.getProviderFirstName());
ps.setString(2, selectedProvider.getProviderLastName());
ps.setInt(3, selectedProvider.getProviderId());
ps.executeUpdate();
clearSelectedProvider();
ps.close();
con.close();
} catch (SQLException e) {
System.out.println("SQLException:" + e.getMessage());
}
}
#PostConstruct
public void init()
{
selectedProvider=new Providers();
}
public void clearSelectedProvider()
{
selectedProvider = null;
}
public void close(CloseEvent event)
{
event.getComponent().getChildren().clear();
clearSelectedProvider();
}
}
Edit dialog code
<p:dialog id="_EditProvider" header="Edit Provider" widgetVar="EditProvider" modal="true"
showEffect="fade" hideEffect="fade" resizable="false" position="center"
appendToBody="true">
<p:ajax event="close" listener="#{providersBean.close}"
update=":editproviderform" global="false"/>
<h:form id="editproviderform">
<p:panelGrid columns="2" rendered="#{not empty providersBean.selectedProvider}">
<h:outputLabel for="EdtProviderFirstName" value="ProviderFirstName*:"/>
<p:inputText id="EdtProviderFirstName" value="#{providersBean.selectedProvider.providerFirstName}"
required="true" requiredMessage="FirstName must be entered" maxlength="30"
validatorMessage="FirstName must be an alphanumeric value">
<f:validateRegex pattern="[a-zA-Z0-9\s]+"/>
</p:inputText>
<h:outputLabel for="EdtProviderLastName" value="ProviderLastName*:"/>
<p:inputText id="EdtProviderLastName" value="#{providersBean.selectedProvider.providerLastName}"
required="true" requiredMessage="LastName must be entered" maxlength="30"
validatorMessage="LastName must be an alphanumeric value">
<f:validateRegex pattern="[a-zA-Z0-9\s]+"/>
</p:inputText>
<p:commandButton id="btnUpdateProvider" value="Save" actionListener="#{providersBean.updateProvider()}"
update=":providersform:providersdt :providersmessages:messages" oncomplete="handleEditProviders(xhr,status,args)"/>
<p:commandButton id="btnCancelProviders" value="Cancel" actionListener="#{providersBean.clearSelectedProvider()}"
oncomplete="EditProvider.hide()"/>
</p:panelGrid>
</h:form>
</p:dialog>
Below is the code for the edit button in datatable:
<p:column style="text-align: center;">
<p:commandButton id="btneditproviders" value="Edit" update=":editproviderform" oncomplete="EditProvider.show()" title="Edit">
<f:setPropertyActionListener value="#{item[0]}" target="#{providersController.selectedProvider}"/>
</p:commandButton>
</p:column>
I have the following dataTable:
<p:dataTable var="indentifier" value="#{identifierBean.identifiers}">
<p:column>
<f:facet name="header">
<h:outputText value="#{indentifier.key}" />
</f:facet>
<h:outputText value="#{indentifier.key}" />
<p:inputText id="userValue" required="true" value="#{identifier.userValue}">
</p:inputText>
</p:column>
</p:dataTable>
and the commandButton
<p:commandButton
value="Search" ajax="false" action="#{identifierBean.saveIdentifiers}">
</p:commandButton>
The identifierBean is the following:
public class IdentifierBean {
private List<Identifier> identifiers;
private String country;
private List<Patient> patients;
public IdentifierBean() {
identifiers = new ArrayList<Identifier>();
}
public IdentifierBean(List<Identifier> identifiers) {
this.identifiers = identifiers;
}
public List<Identifier> getIdentifiers() {
return identifiers;
}
public void saveIdentifiers(){
try {
System.out.println("-"+this.identifiers.size()+"-");
} catch (Exception ex) {
//ex.printStackTrace();
}
}
public void setIdentifiers(List<Identifier> identifiers) {
this.identifiers = identifiers;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
Vector vec = Service.getCountryIdsFromCS(this.country);
for (int i = 0; i < vec.size(); i++) {
Identifier id = new Identifier();
id.setKey(Service.getPortalTranslation(
((SearchMask) vec.get(i)).getLabel(),
LiferayUtils.getPortalLanguage()));
id.setDomain("");
this.identifiers.add(id);
}
System.out.println("-"+this.identifiers.size()+"-");
}
public List<Patient> getPatients() {
return patients;
}
public void setPatients(List<Patient> patients) {
this.patients = patients;
}
}
The table has one row (that means that identifierBean has one element in identifiers list), but when I try to use the identifiers list in the saveIdentifiers method it is empty.
Any help?
Thank you very much!!!
RequestScope is too narrow. See BalusC's description of scopes.