When I click the commandButton, it never goes in the binded method in the managed bean but an exception come:
javax.el.PropertyNotWritableException: /configuration.xhtml #22,73
value="#{configurationBean.maxResUse}": The class
'ch.morphean.videoaid.lb.managedBean.ConfigurationBean' does not have
a writable property 'maxResUse'.
ManagedBean:
public class ConfigurationBean {
private List<String> policy = new ArrayList<String>();
private int timeOut;
private String email;
private boolean secondary;
private short maxResUse;
private String selectedPolicy;
public String getSelectedPolicy() {
return selectedPolicy;
}
public void setSelectedPolicy(String selectedPolicy) {
this.selectedPolicy = selectedPolicy;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public boolean isSecondary() {
return secondary;
}
public void setSecondary(boolean secondary) {
this.secondary = secondary;
}
public int getMaxResUse() {
return maxResUse;
}
public void setMaxResUse(short maxResUse) {
this.maxResUse = maxResUse;
}
public int getTimeOut() {
return timeOut;
}
public void setTimeOut(int timeOut) {
this.timeOut = timeOut;
}
public List<String> getPolicy() {
return policy;
}
public void setPolicy(List<String> policy) {
this.policy = policy;
}
#PostConstruct
public void init() {
List<PolicyDTO> p = getPolicies();
for (PolicyDTO pdto : p) {
policy.add(pdto.getName());
}
ConfigurationResponse conf = getConfig();
this.email = conf.getEmailAlert();
this.maxResUse = conf.getMaxResUse();
this.timeOut = conf.getTimeOut();
}
public String saveConfig() {
System.out.println("action");
configuration.xhtml:
<f:view>
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="Balancing policy" />
<h:selectOneListbox value="#{configurationBean.selectedPolicy}">
<f:selectItems value="#{configurationBean.policy}" />
</h:selectOneListbox>
<h:outputLabel value="Time out (ms)" />
<h:inputText value="#{configurationBean.timeOut}" />
<h:outputLabel value="maximum use ressource %" />
<h:inputText maxlength="2" value="#{configurationBean.maxResUse}" />
<h:outputLabel value="Secondary" />
<h:selectBooleanCheckbox value="#{configurationBean.secondary}" />
<h:outputLabel value="Email alert" />
<h:inputText value="#{configurationBean.email}" />
<h:commandButton action="#{configurationBean.saveConfig}"
value="start" />
</h:panelGrid>
</h:form>
</f:view>
faces-config:
<managed-bean>
<managed-bean-name>configurationBean</managed-bean-name>
<managed-bean-class>ch.morphean.videoaid.lb.managedBean.ConfigurationBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
thanks for the help
Related
i have one datatable with multiple selection (checkboxes). Every time this checkboxes are marked, are executed the select of the datatable again.
XHTML:
<p:dataTable id="dtUsuarios"
widgetVar="usuarios" value="#{configGruposUsuariosMB.usuarios}"
var="usuario" paginator="true" rows="10"
paginatorPosition="bottom" scrollable="true" scrollHeight="82%"
rowsPerPageTemplate="5,10,15,30,50,100"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
emptyMessage="#{i18n.datatableVazia}" lazy="true"
currentPageReportTemplate="{currentPage}/{totalPages} #{i18n.paginas} - {startRecord} #{i18n.a} {endRecord} #{i18n.de} {totalRecords}"
filteredValue="#{configGruposUsuariosMB.usuarioFiltered}"
resizableColumns="true" rowIndexVar="rowIx"
selection="#{configGruposUsuariosMB.usuariosSelecionados}"
rowKey="#{usuario.id}" style="float: right; width: 99%; overflow: hidden;" >
<p:ajax event="rowSelectCheckbox" />
<p:ajax event="rowUnselectCheckbox"/>
<f:facet name="header">
<p:outputLabel value="#{i18n.usuarios}" style="float: left;" />
</f:facet>
<f:facet name="header">
<p:outputPanel>
<h:outputText value="#{i18n.pesquisaGlobal}:" />
<p:inputText id="globalFilter" onkeyup="usuarios.filter()"
style="width:70px" />
<p:watermark value="#{i18n.filtroGlobal}" for="globalFilter" />
</p:outputPanel>
</f:facet>
<p:column id="cbx" selectionMode="multiple" style="width:17px" />
<p:column id="nome" headerText="#{i18n.nomeCompleto}"
sortBy="#{usuario.nome}" style="width:35%;">
<h:outputText value="#{usuario.nome}" />
</p:column>
<p:column id="email" headerText="#{i18n.email}"
sortBy="#{usuario.email}" style="width:35%;">
<h:outputText value="#{usuario.email}" />
</p:column>
<p:column id="grupoAtual" headerText="#{i18n.grupoAtual}"
sortBy="#{usuario.grupoUsuario.descricao}" style="width:30%;">
<h:outputText value="#{usuario.grupoUsuario.descricao}" />
</p:column>
</p:dataTable>
MB (#ViewScoped):
#ManagedBean(name = "configGruposUsuariosMB")
#ViewScoped
public class ConfigGruposUsuariosMB {
#EJB
private GrupoUsuarioService grupoUsuarioservice;
#EJB
private UsuarioService usuarioService;
#Inject
private MessagesController messages;
private GrupoUsuario grupoUsuarioSelecionado;
private List<GrupoUsuario> gruposUsuarios;
private LazyDataModel<Usuario> usuarios;
private LazyDataModel<Usuario> usuariosGrupo;
private Usuario usuarioFiltered;
private Usuario usuarioGrupoFiltered;
private List<Usuario> usuariosSelecionados;
private List<Usuario> usuariosGrupoSelecionados;
private ETipoUsuario tipoUsuarioSelecionado;
// Buscar palavras da base de internacionalização
ResourceBundle i18n = ResourceBundle.getBundle("br.com.sales.messages.msg",
FacesContext.getCurrentInstance().getViewRoot().getLocale());
public GrupoUsuario getGrupoUsuarioSelecionado() {
return grupoUsuarioSelecionado;
}
public void setGrupoUsuarioSelecionado(GrupoUsuario grupoUsuarioSelecionado) {
this.grupoUsuarioSelecionado = grupoUsuarioSelecionado;
}
public List<GrupoUsuario> getGruposUsuarios() {
return gruposUsuarios;
}
public void setGruposUsuarios(List<GrupoUsuario> gruposUsuarios) {
this.gruposUsuarios = gruposUsuarios;
}
public LazyDataModel<Usuario> getUsuarios() {
if (usuarios == null) {
usuarios = new GenericLazyDataModel<Usuario>(
usuarioService.findAll());
}
return usuarios;
}
public void setUsuarios(LazyDataModel<Usuario> usuarios) {
this.usuarios = usuarios;
}
public ETipoUsuario getTipoUsuarioSelecionado() {
if (tipoUsuarioSelecionado == null)
tipoUsuarioSelecionado = ETipoUsuario.A;
if (gruposUsuarios == null || gruposUsuarios.isEmpty())
carregarListaGrupos(tipoUsuarioSelecionado);
return tipoUsuarioSelecionado;
}
public void setTipoUsuarioSelecionado(ETipoUsuario tipoUsuarioSelecionado) {
this.tipoUsuarioSelecionado = tipoUsuarioSelecionado;
carregarListaGrupos(tipoUsuarioSelecionado);
}
public List<SelectItem> getTiposUsuarios() {
List<SelectItem> tipos = new ArrayList<SelectItem>();
for (ETipoUsuario tipoUsuario : ETipoUsuario.getAll()) {
tipos.add(new SelectItem(tipoUsuario, i18n.getString(tipoUsuario
.getTipo())));
}
return tipos;
}
public void carregarListaGrupos(ETipoUsuario tipo) {
gruposUsuarios = grupoUsuarioservice
.findByTipoUsuario(tipoUsuarioSelecionado);
grupoUsuarioSelecionado = getGrupoUsuarioPadrao();
}
public GrupoUsuario getGrupoUsuarioPadrao() {
for (GrupoUsuario grupo : gruposUsuarios) {
if (grupo.isPadrao())
return grupo;
}
return new GrupoUsuario();
}
public LazyDataModel<Usuario> getUsuariosGrupo() {
List<Usuario> users = usuarioService
.findByGrupoUsuario((grupoUsuarioSelecionado != null ? grupoUsuarioSelecionado
: new GrupoUsuario()));
usuariosGrupo = new GenericLazyDataModel<Usuario>(users);
return usuariosGrupo;
}
public void setUsuariosGrupo(LazyDataModel<Usuario> usuariosGrupo) {
this.usuariosGrupo = usuariosGrupo;
}
public Usuario getUsuarioFiltered() {
return usuarioFiltered;
}
public void setUsuarioFiltered(Usuario usuarioFiltered) {
this.usuarioFiltered = usuarioFiltered;
}
public Usuario getUsuarioGrupoFiltered() {
return usuarioGrupoFiltered;
}
public void setUsuarioGrupoFiltered(Usuario usuarioGrupoFiltered) {
this.usuarioGrupoFiltered = usuarioGrupoFiltered;
}
public List<Usuario> getUsuariosGrupoSelecionados() {
return usuariosGrupoSelecionados;
}
public void setUsuariosGrupoSelecionados(
List<Usuario> usuariosGrupoSelecionados) {
this.usuariosGrupoSelecionados = usuariosGrupoSelecionados;
}
public List<Usuario> getUsuariosSelecionados() {
return usuariosSelecionados;
}
public void setUsuariosSelecionados(List<Usuario> usuariosSelecionados) {
this.usuariosSelecionados = usuariosSelecionados;
}
public void reset() {
usuariosSelecionados = null;
usuariosGrupoSelecionados = null;
usuarios = null;
getUsuarios();
usuariosGrupo = null;
getUsuariosGrupo();
}
public void adicionarUsuarios() {
List<Usuario> usersAtuais = ((GenericLazyDataModel<Usuario>) usuariosGrupo)
.getDatasource();
for (Usuario user : usuariosSelecionados) {
if (!user.getGrupoUsuario().equals(grupoUsuarioSelecionado)) {
user.setGrupoUsuario(grupoUsuarioSelecionado);
usersAtuais.add(user);
}
}
// teste...
usuarioService.merge(usuariosSelecionados);
// reset();
if (usuariosSelecionados != null)
usuariosSelecionados.clear();
if (usuariosGrupoSelecionados != null)
usuariosGrupoSelecionados.clear();
usuariosGrupo = null;
usuariosGrupo = new GenericLazyDataModel<Usuario>(usersAtuais);
messages.addInfo("msgSucessoParcial");
}
public void removerUsuarios() {
boolean error = false;
for (Usuario user : usuariosGrupoSelecionados) {
if (user.getGrupoUsuario().equals(usuariosGrupoSelecionados)) {
error = true;
continue;
} else {
user.setGrupoUsuario(getGrupoUsuarioPadrao());
}
}
reset();
if (error)
messages.addWarn("msgAvisoUsuarioGrupo");
messages.addInfo("msgSucessoParcial");
}
public void save() {
usuarioService.merge(usuariosSelecionados);
messages.addInfo("msgSucesso");
}
}
If i remove the <p:ajax event="rowSelectCheckbox" /> or change to <p:ajax event="rowSelectCheckbox" process="#none"/>, the method "setUsuariosSelecionados(List usuariosSelecionados)" is not invoked.
I Just need call the "setUsuariosSelecionados(List usuariosSelecionados)" when a checkbox are marked.
I'm using JSF2, Primefaces 3.5
Sorry about my english (googleTranslate =D)
I am using PrimeFaces DataTable with Radiobuttons inside a one wizard tab. Is possible to somehow set Radiobuttons like required?
User shouldn't go to the next wizard tab until he will choose one option in DataTable with Radiobuttons.
Or have you any ideas how to resolve this problem? Thanks for any replies!
JSP page
<p:tab id="test" title="Test">
<p:panel header="Term page">
<p:dataTable id="collection" value="#{register.dataList}" var="dl" rowKey="#{dl.c_id}" selection="#{register.selectedTerm}"">
<p:column selectionMode="single" style="width:2%" />
<p:column>
#{dl.c_id}
</p:column>
</p:dataTable>
</p:panel>
</p:tab>
You can check for data selection in flowListener of <p:wizard> tag that is triggered when next/previous buttons are clicked and conditionally add FacesMessage:
public String onFlowProcess(FlowEvent event) {
String current = event.getOldStep();
String next = event.getNewStep();
boolean proceed = true;
if(current.equals("first") && next.equals("second") && (selectedData == null)) {
//proceed only when data was selected and user is moving to the next step
FacesMessage facesMessage = new FacesMessage("You need to make a selection in a datatable to proceed!");
FacesContext.getCurrentInstance().addMessage("form:selection", facesMessage);
proceed = false;
}
return proceed ? next : current;
}
The full example is provided below.
The view:
<h:form id="form">
<p:wizard widgetVar="wiz" flowListener="#{q16439053Bean.onFlowProcess}">
<p:tab id="first" title="First">
<p:message for="selection"/>
<p:panel id="selection" header="Term page">
<p:dataTable id="collection" value="#{q16439053Bean.list}" var="data" rowKey="#{data.name}" selection="#{q16439053Bean.selectedData}">
<p:column selectionMode="single" style="width:2%" />
<p:column>
#{data.name}
</p:column>
</p:dataTable>
</p:panel>
</p:tab>
<p:tab id="second" title="Second">
Done!
</p:tab>
</p:wizard>
</h:form>
The bean:
#ManagedBean
#ViewScoped
public class Q16439053Bean implements Serializable {
private List<Data> list;
private Data selectedData;
public List<Data> getList() {
return list;
}
public void setList(List<Data> list) {
this.list = list;
}
public Data getSelectedData() {
return selectedData;
}
public void setSelectedData(Data selectedData) {
this.selectedData = selectedData;
}
public class Data {
private String name;
private String value;
public Data() {
}
public Data(String name, String value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
public Q16439053Bean() {
list = new ArrayList<Data>();
Data d;
d = new Data("name", "value");
list.add(d);
d = new Data("name1", "value1");
list.add(d);
d = new Data("name2", "value2");
list.add(d);
d = new Data("name3", "value3");
list.add(d);
}
public String onFlowProcess(FlowEvent event) {
String current = event.getOldStep();
String next = event.getNewStep();
boolean proceed = true;
if(current.equals("first") && next.equals("second") && (selectedData == null)) {
FacesMessage facesMessage = new FacesMessage("You need to make a selection in a datatable to proceed!");
FacesContext.getCurrentInstance().addMessage("form:selection", facesMessage);
proceed = false;
}
return proceed ? next : current;
}
}
i want to create dynamic textbox in jsf2 in datatable having textboxes based on clicking add row button. Iam a newbie for jsf programming.Can someone tell me a basic example for dynamic for generation . I have read ui:repeatand c:foreach but i need some practical example.
For your sample,
xhtml code:
<?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">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
</h:head>
<h:body>
<h:form id="form1">
<h:commandButton value="Add new Row" actionListener="#{myBean.addNewEmployee}"/>
<h:dataTable value="#{myBean.employeeList}" var="emp">
<h:column>
<f:facet name="header">
Employee Id
</f:facet>
#{emp.empId}
</h:column>
<h:column>
<h:inputText value="#{emp.empName}"/>
</h:column>
</h:dataTable>
</h:form>
</h:body>
</html>
jsf manged bean
#ManagedBean
#ViewScoped
public class MyBean implements Serializable {
List<Employee> employeeList;
public List<Employee> getEmployeeList() {
return employeeList;
}
public void setEmployeeList(List<Employee> employeeList) {
this.employeeList = employeeList;
}
public void addNewEmployee(ActionEvent event) {
employeeList.add(new Employee(employeeList.size(), null));
}
#PostConstruct
public void init() {
employeeList = new ArrayList<Employee>();
employeeList.add(new Employee(1, "Emp1"));
employeeList.add(new Employee(2, "Emp2"));
}
public MyBean() {
}
}
Employee Class(You can use your entity class)
public class Employee {
Integer empId;
String empName;
public Integer getEmpId() {
return empId;
}
public void setEmpId(Integer empId) {
this.empId = empId;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public Employee(Integer empId, String empName) {
this.empId = empId;
this.empName = empName;
}
#Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Employee other = (Employee) obj;
if (this.empId != other.empId && (this.empId == null || !this.empId.equals(other.empId))) {
return false;
}
return true;
}
#Override
public int hashCode() {
int hash = 5;
hash = 41 * hash + (this.empId != null ? this.empId.hashCode() : 0);
return hash;
}
}
You can directly use above code. And also I suggest to use PrimeFaces component for advanced manipulations
I filled my rightList of the PickList with Objects from a web service, but when i select some elements, i want to get these elements in myManagedBean, because i'll affect them to an Object.
JSF :
<h:form>
<rich:panel>
<h:panelGrid columns="2" styleClass="criteresSaisie"
rowClasses="critereLigne" columnClasses="titreColonne,">
<h:outputLabel for="libelleCoplement" value=" "
size="20" />
<rich:pickList d="libelleCoplement" sourceCaption="Compléments"
targetCaption="Compléments sélectionnés"
value="#{listeCmpltDispoModel.listeCmpltSelect}" size="15"
addText=">" addAllText=">>" removeText="<"
removeAllText="<<" listWidth="270px" listHeight="110px"
orderable="true">
<f:converter converterId="cmpltsTitresConcerter" />
<f:selectItems value="#{listeCmpltDispoModel.listeCmpltDispo}"
var="liste" itemLabel="#{liste.libelleComplement}"
itemValue="#{liste.cdComplement}"/>
</rich:pickList>
</h:panelGrid>
<h:panelGroup>
<div align="right">
<h:panelGrid columns="8">
<h:commandButton value="Valider"
action="#{saisieCmpltsTitreCtrl.valider}" />
</h:panelGrid>
</div>
</h:panelGroup>
</rich:panel>
</h:form>
The bean :
#ManagedBean(name = "listeCmpltDispoModel")
#SessionScoped
public class ListeCmpltDispoModel implements Serializable {
private static final long serialVersionUID = 1L;
private Long cdComplement;
private String libelleComplement;
private int nbCompl;
private List<ComplementsDispoSortieDTO> listeCmpltDispo ;
private List<ComplementsDispoSortieDTO> listeCmpltSelect ;
public ListeCmpltDispoModel() {
}
public Long getCodeComplement() {
return cdComplement;
}
public void setCodeComplement(Long cdComplement) {
this.cdComplement = cdComplement;
}
public String getLibelleComplement1() {
return libelleComplement;
}
public void setLibelleComplement1(String libelleCoplement) {
this.libelleComplement = libelleCoplement;
}
public Long getCdComplement() {
return cdComplement;
}
public void setCdComplement(Long cdComplement) {
this.cdComplement = cdComplement;
}
public String getLibelleComplement() {
return libelleComplement;
}
public void setLibelleComplement(String libelleComplement) {
this.libelleComplement = libelleComplement;
}
public List<ComplementsDispoSortieDTO> getListeCmpltDispo() {
return listeCmpltDispo;
}
public void setListeCmpltDispo(List<ComplementsDispoSortieDTO> listeCmpltDispo) {
this.listeCmpltDispo = listeCmpltDispo;
}
public int getNbCompl() {
return nbCompl;
}
public void setNbCompl(int nbCompl) {
this.nbCompl = nbCompl;
}
public List<ComplementsDispoSortieDTO> getListeCmpltSelect() {
return listeCmpltSelect;
}
public void setListeCmpltSelect(List<ComplementsDispoSortieDTO> listeCmpltSelect) {
this.listeCmpltSelect = listeCmpltSelect;
}
}
Converter :
#FacesConverter(value="cmpltsTitresConcerter")
public class CmpltsTitresConcerter implements Converter {
#SuppressWarnings("null")
public Object getAsObject(FacesContext context, UIComponent component,
String value){
ComplementsDispoSortieDTO cmpltSelect = null;
cmpltSelect.setCdComplement(Long.parseLong(value));
return cmpltSelect;
}
public String getAsString(FacesContext arg0, UIComponent arg1, Object obj) {
return String.valueOf(((ComplementsDispoSortieDTO) obj).getCdComplement());
}
}
Any help is greatly apprectiated!
Roughtly you need 3 things :
Custom converter for your object (Object to String, String to Object)
Getter/Setter with the List of your Objects choices
Getter/Setter with the List of your Objects selected
Everything is perfectly described here : RichFaces Showcase - pickList
EDIT :
Adding this should fix your problem :
<rich:pickList ...>
<f:converter converterId="cmpltsTitresConcerter" />
</rich:pickList>
also the converter property in <f:selectItems /> is not valid : f:selectItems
EDIT :
You should modify your converter like that to remove converting exceptions :
#FacesConverter(value="cmpltsTitresConcerter")
public class CmpltsTitresConcerter implements Converter
{
public Object getAsObject(FacesContext context, UIComponent component, String value)
{
ComplementsDispoSortieDTO cmpltSelect = null;
if(value != null)
{
cmpltSelect = new ComplementsDispoSortieDTO();
cmpltSelect.setCdComplement(Long.parseLong(value));
}
return cmpltSelect;
}
public String getAsString(FacesContext arg0, UIComponent arg1, Object obj)
{
String result = null;
if(obj != null)
{
result = String.valueOf(((ComplementsDispoSortieDTO) obj).getCdComplement());
}
return result;
}
}
Your selected objects are bound to the value attribute which must have a getter and setter.
i have a datatable with one row , i need to edit the fields of this row so i have a few inputText with the values, but when i edit them and click on the commandbutton(that calls the method "actualizarUsuario" the values are passed as null.
this is my bean code:
#ManagedBean(name = "user")
#ViewScoped
public class userDetalles implements Serializable {
private Usuario u;
private usuarioController controlador;
Rol rol;
private long selection;
private long selectionrol;
Agrupacion agrupacion;
private Privilegio privilegio;
private RolController controladorRol;
private ControladorAgrupaciones controladorAgrup;
private String nombres;
private String apellidoP;
private String apellidoM;
private Boolean check;
#PostConstruct
public void init() {
rol= new Rol() ;
u=new Usuario();
agrupacion=new Agrupacion();
privilegio=new Privilegio();
controlador= new usuarioController();
controladorRol=new RolController();
controladorAgrup=new ControladorAgrupaciones();
Usuario u=new Usuario();
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
//Obtener parametros del request
Map<String, String> parameterMap = (Map<String, String>) externalContext.getRequestParameterMap();
long iduser = Long.valueOf(parameterMap.get("id_usuario"));
this.u=controlador.getUser(iduser);
}
public Usuario getU() {
return u;
}
public void setU(Usuario u) {
this.u = u;
}
public long getSelection() {
System.out.println("selection value----------->"+selection);
return selection;
}
public void setSelection(long selection) {
this.selection = selection;
}
public long getSelectionrol() {
return selectionrol;
}
public void setSelectionrol(long selectionrol) {
this.selectionrol = selectionrol;
}
public String getNombres() {
return nombres;
}
public void setNombres(String nombres) {
this.nombres = nombres;
}
public String getApellidoP() {
return apellidoP;
}
public void setApellidoP(String apellidoP) {
this.apellidoP = apellidoP;
}
public String getApellidoM() {
return apellidoM;
}
public void setApellidoM(String apellidoM) {
this.apellidoM = apellidoM;
}
public Boolean getCheck() {
return check;
}
public void setCheck(Boolean check) {
this.check = check;
}
public void actualizarUsuario(){
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
Map<String, String> parameterMap = (Map<String, String>) externalContext.getRequestParameterMap();
nombres=parameterMap.get("nombres");
apellidoP=parameterMap.get("apellidoP");
apellidoM=parameterMap.get("apellidoM");
check=Boolean.parseBoolean(parameterMap.get("check"));
//test
System.out.println(nombres+" "+apellidoP+" "+apellidoM+" "+check);
u.setNombres(nombres);
u.setApellidoPaterno(apellidoP);
u.setApellidoMaterno(apellidoM);
u.setActive(check);
controlador.saveUsuario(u);
}
}
and this is my view:
<?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:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<div class="container">
<h:panelGroup id="Users">
<h:form id="Form">
<h2>Detalles Usuario</h2>
<h:dataTable id="users" value="#{user.u}" styleClass="table table-striped table-bordered" headerClass="sorting_asc"
rowClasses="odd,even">
<h:column>
<f:facet name="header">#</f:facet>
#{user.u.id}
</h:column>
<h:column>
<f:facet name="header">Identificador</f:facet>
<h:inputText id="identificador" value="#{user.u.identificador}" />
</h:column>
<h:column>
<f:facet name="header">Nombre</f:facet>
<h:inputText id="nombres" value="#{user.u.nombres}"/>
<h:inputText id="apellidoP" value="#{user.u.apellidoPaterno}"/>
<h:inputText id="apellidoM" value="#{user.u.apellidoMaterno}"/>
</h:column>
<h:column>
<f:facet name="header">Active</f:facet>
<h:selectBooleanCheckbox id="check" value="#{user.u.active}"></h:selectBooleanCheckbox>
</h:column>
</h:dataTable>
<h:commandButton value="Actualizar" type="submit" styleClass="btn-primary" actionListener="#{user.actualizarUsuario}">
</h:commandButton>
</h:form>
<script type="text/javascript" src="js/paging-bootstrap.js"></script>
<script type="text/javascript" src="js/contenidoc.datatable.init.js"></script>
</h:panelGroup>
</div>
</ui:composition>
Your concrete problem is caused because you used the wrong parameter names. Look in the generated HTML output and the HTTP traffic monitor for the right parameter names.
However, your actual problem is bigger: your view/model approach is completely wrong. You shouldn't be using a <h:dataTable> at all. It is intented for a collection of entities like List<User>, not for a single entity like User. You should be using <h:panelGrid>. You don't need to explode/flatten model properties in controller at all. You have those properties already in the model itself. You don't need to manually traverse the request parameter map. JSF will already do all the job for you.
I won't rewrite this mess for you, but to the point you should follow the following kickoff example:
Model:
public class User {
private Long id;
private String username;
private String firstname;
private String lastname;
// ...
// Autogenerate standard getters/setters.
}
Controller:
#ManagedBean
#ViewScoped
public class EditUser {
private User user; // Initialize it in postconstruct or as viewparam.
private UserService service; // Initialize it as #EJB or in postconstruct.
public void save() {
service.save(user); // That's all. Really.
}
public User getUser() {
return user;
}
// No other getters/setters! They are all already in User class.
}
View:
<h:panelGrid>
<h:inputText value="#{editUser.user.username}" />
<h:inputText value="#{editUser.user.firstname}" />
<h:inputText value="#{editUser.user.lastname}" />
<h:commandButton value="save" action="#{editUser.save}" />
</h:panelGrid>
That's all. See also among others this JSF 2.0 tutorial. As to your attempt to get the user by ID, you should rather use <f:viewParam>, see also What can <f:metadata>, <f:viewParam> and <f:viewAction> be used for? and communication in JSF 2.0.