I'm using primefaces 4.0.7 .I used selectonemenu,this menu showed the variables however value was null in Bean.Is there any configuration can i do?
Here is part of xhtml code;
<h:outputText value="#{etiketler.kullaniciTipi} : " />
<p:selectOneMenu id="kullaniciTipi" style="width:200px" value="#{kullaniciIslemleriBean.userRole}" >
<f:selectItems value="#{enumBean.kullaniciTipiValues}" var="kullaniciTipi"
itemLabel="#{kullaniciTipi.name}" itemValue="#{kullaniciTipi}" />
</p:selectOneMenu>
here is part of kullaniciIslemleriBean code;
private EnumBase.KullaniciTipi userRole;
public void Kaydet() {
if (userRole == null) {
System.out.println("null value");
return;
}
...
}
public EnumBase.KullaniciTipi getUserRole() {
return userRole;
}
public void setUserRole(EnumBase.KullaniciTipi userRole) {
this.userRole = userRole;
}
Try storing it as String, it will work fine. If you want to store it
as Enum then try converter
<h:outputText value="#{etiketler.kullaniciTipi} : " />
<p:selectOneMenu id="kullaniciTipi" style="width:200px" value="#{kullaniciIslemleriBean.userRole}" >
<f:selectItems value="#{enumBean.kullaniciTipiValues}" var="kullaniciTipi"
itemLabel="#{kullaniciTipi.name}" itemValue="#{kullaniciTipi.name}" />
</p:selectOneMenu>
private String userRole;
public void Kaydet() {
if (userRole == null) {
System.out.println("null value");
return;
}
...
}
public String getUserRole() {
return userRole;
}
public void setUserRole(String userRole) {
this.userRole = userRole;
}
Related
This question already has answers here:
Validation Error: Value is not valid
(3 answers)
Closed 6 years ago.
In my JSF application using RichFaces, I have a screen with rich:dataTable
that displays my objects, and a column that refers to another page, with the details of the selected record so that it can be used.
In this second page, after completing the requested data, when running submit, the validation returns the message:
:Value is not a valid option.
Look that, unlike the problem cited in this post, the name of the problem field is not being displayed.
During debugging, I noticed that in the selecionarEmitente() method, the object localidade is null. If I made the set on the dataTable page and the name of the selected object appears on the secondPage, what is missing?
I already researched other posts about this problem. For example, according to this post, my javabeans involved have the equals() and hashCode() methods. Unlike this other post, I'm using custom converters.
Where is my mistake?
I'm using RichFaces 4.5.1.Final, MyFaces 2.2.10, Spring 3.1.1 .
dataTable.xhtml
<h:selectOneMenu id="estado"
immediate="true" validator="#{validadorMB.validarEstado}"
converter="estadoConverter">
<f:selectItem itemLabel="---" />
<f:selectItems value="#{localidadeMB.estados}"
var="est" itemValue="#{est}" itemLabel="#{est.uf}" />
<a4j:ajax event="change" actionListener="#{localidadeMB.filtrarUF}" render="table" />
</h:selectOneMenu>
<a4j:region id="region" immediate="true">
<rich:dataTable id="tabela"
value="#{localidadeMB.getLocalidadesPorUF()}" var="loc"
rowKeyVar="row" rows="20" width="800px" render="scroller">
<rich:column id="col_localidade" sortBy="#{loc.nome}" filterBy="#{loc.nome}">
<h:outputText id="nomeLocalidade" value="#{loc.nome}" />
</rich:column>
...
<rich:column>
<h:commandLink id="declaracaolink" action="#{localidadeMB.carregarLocalidade}">
<h:graphicImage url="/img/declaracao.png" />
<f:setPropertyActionListener value="#{loc}" target="#{localidadeMB.localidade}" />
</h:commandLink>
</rich:column>
</rich:dataTable>
</a4j:region>
secondPage.xhtml
<h:body>
<h:form id="formDeclaracao" focus="estado">
<h:panelGrid columns="2" columnClasses="labelFormulario">
<h:outputLabel value="UF" for="estado" />
<h:selectOneMenu id="estado"
value="#{localidadeMB.localidade.estado}"
label="#{localidadeMB.localidade.estado.uf}"
valueChangeListener="#{localidadeMB.selecionarEstado}"
validator="#{validadorMB.validarEstado}" immediate="true"
converter="estadoConverter"
style="width: 45px;" styleClass="listbox">
<f:selectItems value="#{localidadeMB.estados}"
var="est" itemValue="#{est}" itemLabel="#{est.uf}" />
<a4j:ajax event="change" render="nomeLocalidade" />
</h:selectOneMenu>
<h:outputLabel value="Nome da localidade:" for="nomeLocalidade" />
<h:selectOneMenu id="nomeLocalidade"
value="#{localidadeMB.localidade}"
label="#{localidadeMB.localidade.nome}" immediate="true"
valueChangeListener="#{localidadeMB.selecionarLocalidade}"
validator="#{validadorMB.validarLocalidade}"
converter="localidadeConverter"
style="width: 220px;" styleClass="listbox">
<f:selectItems value="#{localidadeMB.localidades}"
var="loc" itemValue="#{loc}" itemLabel="#{loc.nome}" />
</h:selectOneMenu>
<h:outputLabel value="Interessado:" for="interessado" />
<h:inputText id="interessado" value="" required="true"
requiredMessage="xxxxxxxxx" immediate="true"
styleClass="listbox" style="width: 215px;">
</h:inputText>
<h:outputLabel value="Solicitante:" for="solicitante" />
<h:inputText id="solicitante" value="" required="true"
requiredMessage="xxxxxxxxxxxxx" immediate="true">
</h:inputText>
<h:outputLabel value="Documento apresentado:" for="documento" />
<h:inputText id="documento" value="" required="true"
requiredMessage="xxxxxxxxxxxxx" immediate="true">
</h:inputText>
<h:outputLabel value="Emitente:" for="emitente" />
<h:selectOneMenu id="emitente"
value="#{localidadeMB.emitente}"
label="#{localidadeMB.emitente.descricaoReduzida}"
valueChangeListener="#{localidadeMB.selecionarEmitente}"
validator="#{validadorMB.validarEmitente}"
converter="emitenteConverter">
<f:selectItem itemLabel="---" />
<f:selectItems value="#{localidadeMB.emitentes}" var="em" itemValue="#{em}" itemLabel="#{em.descricaoReduzida}" />
</h:selectOneMenu>
<h:commandButton id="btnGerarDeclaracao" value="Get PDF"
action="#{localidadeMB.getPDF()}" style="width: 84px;" />
</h:panelGrid>
</h:form>
</h:body>
ManagedBean
#ManagedBean
public class LocalidadeMB{
private Emitente emitente;
private Estado estado;
private Localidade localidade;
public String carregarLocalidade() {
estado = localidade.getEstado();
localidade = getLocalidade();
getLocalidades();
carregarLocalidadePorUF(estado);
return "secondPage.xhtml";
}
public void filtrarUF(ActionEvent action) {
try {
String uf = JSFHelper.getRequestParameter("formConsulta"
+ UINamingContainer.getSeparatorChar(JSFHelper
.getFacesContext()) + "estado");
estado = estadoFacade.getEstado(Integer.parseInt(uf));
} catch (Exception e) {
...
}
}
public List<Emitente> getEmitentes() {
try {
return emitenteFacade.getEmitentes();
} catch (Exception e) {
...
}
}
public List<Emitente> getEstados() {
try {
return estadoFacade.getEstados();
} catch (...) {
...
}
}
public List<Localidade> getLocalidades() {
try {
return localidadeFacade.getLocalidades();
} catch (Exception e) {
...
}
}
public List<Localidade> getLocalidadesPorUF() {
try {
String uf = JSFHelper.getRequestParameter("formConsulta"
+ UINamingContainer.getSeparatorChar(JSFHelper
.getFacesContext()) + "estado");
if ((uf != null) && (!uf.equals("---"))) {
estado = estadoFacade.getEstado(Integer.parseInt(uf));
return localidadeFacade.getLocalidadesPorEstado(estado);
} else {
return null;
}
} catch (Exception e) {
...
}
}
public void selecionarEmitente(ValueChangeEvent evento) {
emitente = (Emitente)evento.getNewValue();
}
public void selecionarEstado(ValueChangeEvent evento) {
estado = (Estado)evento.getNewValue();
}
public void selecionarLocalidade(ValueChangeEvent evento) {
localidade = (Localidade)evento.getNewValue();
}
}
Validator
#ManagedBean(name = "validadorMB")
public class ValidadorLocalidadeMB {
public void validarEmitente(FacesContext context, UIComponent componentToValidate, Object value) throws ValidatorException {
if (((Emitente) value).getEmitenteId() == 0) {
FacesMessage msg = new FacesMessage(null, "Selecione o emitente");
throw new ValidatorException(msg);
}
}
public void validarEstado(FacesContext context, UIComponent componentToValidate, Object value) throws ValidatorException {
if (((Estado) value).getEstadoId() == 0) {
FacesMessage msg = new FacesMessage(null, "Selecione uma UF");
throw new ValidatorException(msg);
}
}
public void validarLocalidade(FacesContext context, UIComponent componentToValidate, Object value) throws ValidatorException {
if (((Localidade) value).getLocalidadeId() == 0) {
FacesMessage msg = new FacesMessage(null, "Selecione uma localidade");
throw new ValidatorException(msg);
}
}
}
Converters
#FacesConverter(value = "emitenteConverter")
public class EmitenteConverter implements Converter {
#Override
public Object getAsObject(FacesContext context, UIComponent ui, String value) throws ConverterException {
ValueExpression vex = context
.getApplication()
.getExpressionFactory()
.createValueExpression(context.getELContext(),
"#{emitenteFacade}", EmitenteFacadeImpl.class);
EmitenteFacadeImpl fac = (EmitenteFacadeImpl) vex.getValue(context
.getELContext());
try {
return fac.getEmitentePorId(Integer.valueOf(value));
} catch (NumberFormatException | DAOException e) {
....
}
}
#Override
public String getAsString(FacesContext context, UIComponent ui, Object value) throws ConverterException {
if (value == null) {
return "";
}
if (value instanceof Emitente) {
return String.valueOf(((Emitente) value).getEmitenteId());
}
}
}
#FacesConverter(value = "estadoConverter")
public class EstadoConverter implements Converter {
#Override
public Object getAsObject(FacesContext context, UIComponent ui, String value) throws ConverterException {
ValueExpression vex = context
.getApplication()
.getExpressionFactory()
.createValueExpression(context.getELContext(),
"#{estadoFacade}", EstadoFacadeImpl.class);
EstadoFacadeImpl fac = (EstadoFacadeImpl) vex.getValue(context
.getELContext());
try {
return fac.getEstadoPorId(Integer.valueOf(value));
} catch (NumberFormatException | DAOException e) {
....
}
}
#Override
public String getAsString(FacesContext context, UIComponent ui, Object value) throws ConverterException {
if (value == null) {
return "";
}
if (value instanceof Estado) {
return String.valueOf(((Estado) value).getEstadoId());
}
}
}
#FacesConverter(value = "localidadeConverter")
public class LocalidadeConverter implements Converter {
#Override
public Object getAsObject(FacesContext context, UIComponent ui, String value) throws ConverterException {
ValueExpression vex = context
.getApplication()
.getExpressionFactory()
.createValueExpression(context.getELContext(),
"#{localidadeFacade}", LocalidadeFacadeImpl.class);
LocalidadeFacadeImpl fac = (LocalidadeFacadeImpl) vex.getValue(context.getELContext());
try {
return fac.getLocalidadePorId(Integer.valueOf(value));
} catch (NumberFormatException | DAOException e) {
....
}
}
#Override
public String getAsString(FacesContext context, UIComponent ui, Object value) throws ConverterException {
if (value == null) {
return "";
}
if (value instanceof Localidade) {
return String.valueOf(((Localidade) value).getLocalidadeId());
}
}
}
Your problem might be with this line:
value="#{(localidadeMB.localidade.localidadeId != null) ? localidadeMB.localidade.localidadeId :localidadeMB.localidade}"
The value of a <h:selectOneMenu> should be a simple property, not an expression, as it has to set.
Edit:
There could be another problem with your code:
You construct those SelectItems with the entity's ID as the value property, and then use converter to convert String to/from the entity itself.
Thus there are a few possibilities for you:
Use the converter, and the "whole" entity as the value of SelectItem.
Or don't use Selectitems, but a List of the entities themselves, as your first link does.
The other possibility is to use a dummy entity, set its id property, and in your valueChangeListener retrieve the entity by the ID.
I have a dataTable, containing Package objects with id and phaseList attributes. I would like this dataTable to display package id and its five phases status with some graphicImages like colored circles.
For example: If a package's phase one is completed, the first circle rendered in a progress column is a green one, other four are red ones.
So basically I need to render a circle based on a value from phaseList element attribute. I already accomplished all of this, but it seems to me that there should be some other way. The problem is that I must have five phase color attributes in a backing bean and five getters and setters for those attributes (see code below). In those getters there is very similar code for all five attributes, so I thought I should have just one color attribute and one getter and there should somehow get an information which circle is currently rendered.
Is there any other way (with less duplicated code) to render those circles?
public class Package implements Serializable {
private static final long serialVersionUID = 1L;
private BigDecimal id;
private List<PhaseStatus> phaseList;
public BigDecimal getId() {
return id;
}
public void setId(BigDecimal id) {
this.id = id;
}
public void setPhaseList(List<PhaseStatus> phaseList) {
this.phaseList= phaseList;
}
public List<PhaseStatus> getPhaseList() {
return phaseList;
}
}
PhaseStatus class:
public class PhaseStatus implements Serializable {
private static final long serialVersionUID = 1L;
private BigDecimal phaseId;
private BigDecimal phaseStatus;
private String hint;
public void setPhaseId(BigDecimal phaseId) {
this.phaseId = phaseId;
}
public BigDecimal getPhaseId() {
return phaseId;
}
public void setPhaseStatus(BigDecimal phaseStatus) {
this.phaseStatus = phaseStatus;
}
public BigDecimal getPhaseStatus() {
return phaseStatus;
}
public void setHint(String hint) {
this.hint = hint;
}
public String getHint() {
return hint;
}
}
Xhtml code:
<p:column headerText="Id">
<p:outputLabel value="#{item.id}" />
</p:column>
<p:column headerText="Progress">
<p:commandLink id="lnkPhase1">
<p:graphicImage library="icons" name="#{bean.phaseOneColor}" width="24px" height="24px" />
</p:commandLink>
<p:tooltip id="hint1" for="lnkPhase1" value="#{bean.phaseOneHint}" />
<p:commandLink id="lnkPhase2">
<p:graphicImage library="icons" name="#{bean.phaseTwoColor}" width="24px" height="24px" />
</p:commandLink>
<p:tooltip id="hint2" for="lnkPhase2" value="#{bean.phaseTwoHint}" />
<p:commandLink id="lnkPhase3">
<p:graphicImage library="icons" name="#{bean.phaseThreeColor}" width="24px" height="24px" />
</p:commandLink>
<p:tooltip id="hint3" for="lnkPhase3" value="#{bean.phaseThreeHint}" />
<p:commandLink id="lnkPhase4">
<p:graphicImage library="icons" name="#{bean.phaseFourColor}" width="24px" height="24px" />
</p:commandLink>
<p:tooltip id="hint4" for="lnkPhase4" value="#{bean.phaseFourHint}" />
<p:commandLink id="lnkPhase5">
<p:graphicImage library="icons" name="#{bean.phaseFiveColor}" width="24px" height="24px" />
</p:commandLink>
<p:tooltip id="hint5" for="lnkPhase5" value="#{bean.phaseFiveHint}" />
</p:column>
Part of my backing bean:
private String phaseOneColor;
private String phaseTwoColor;
private String phaseThreeColor;
private String phaseFourColor;
private String phaseFiveColor;
private DataTable dtPackages;
one of the getter's:
public String getPhaseOneColor() {
Package myPackage = (Package) getDtPackages().getRowData();
List<PhaseStatus> list = myPackage.getPhaseList();
BigDecimal status = list.get(0).getPhaseStatus();
if (status != null) {
switch (status.intValue()) {
case 1:
phaseOneColor = "green.png";
break;
default:
phaseOneColor = "red.png";
break;
}
} else {
phaseOneColor = "red.png";
}
return phaseOneColor;
}
I'm using PrimeFaces 5.1.
What about something like this
public String getPhaseColor(int phase) {
Package package = (Package) getDtPackages().getRowData();
List<PhaseStatus> list = package.getPhaseList();
BigDecimal status = list.get(phase).getPhaseStatus();
if (status != null) {
switch (status.intValue()) {
case 1:
phaseColor = "green.png";
break;
default:
phaseColor = "red.png";
break;
}
} else {
phaseColor = "red.png";
}
return phaseColor;
}
Similar for tooltips
public String getPhaseTooltip(int phase) {
Package package = (Package) getDtPackages().getRowData();
List<PhaseStatus> list = package.getPhaseList();
BigDecimal status = list.get(phase).getPhaseStatus();
String tooltip = null;
if (status != null) {
switch (status.intValue()) {
case n:
tooltip = "Phase " + phase + " tooltip";
break;
default:
}
} else {
tooltip = "probably error";
}
return tooltip;
}
And you use this in page like this
<p:column headerText="Progress">
<ui:repeat var="phase" value="#{item.phaseList}" varStatus="status">
<p:commandLink id="lnkPhase#{status.index + 1}">
<p:graphicImage library="icons" name="#{bean.getPhaseColor(status.index + 1)}" width="24px" height="24px" />
</p:commandLink>
<p:tooltip id="hint#{status.index + 1}" for="lnkPhase#{status.index + 1}" value="#{bean.getPhaseTooltip(status.index + 1)}" />
</ui:repeat>
</p:column>
There might be some errors in the code since I'm typing it in here directly, but you'll get the idea.
UPDATE
For Java 5 (method invocations with parameters doesn't work), you could do something like this
public Map<Integer, String> getPhaseColors() {
Package package = (Package) getDtPackages().getRowData();
Map<Integer, String> phaseColors = new HashMap<Integer, String>();
if (package != null) {
List<PhaseStatus> list = package.getPhaseList();
for (int i = 0; i < list.size(); i++;) {
BigDecimal ps = list.get(i).getPhaseStatus();
if (ps != null) {
phaseColors.put(i, ps.intValue() == 1 ? "green.png" : "red.png");
} else {
phaseColors.put(i, "red.png");
}
}
}
return phaseColor;
}
<p:graphicImage library="icons" name="#{bean.phaseColors[status.index + 1]}" width="24px" height="24px" />
Similar for tooltips.
I want to delete selected row from data table when click on GraphicImage under CommandLink.
but it is don't work for me.
it gives error :-
/privilegepage.xhtml #66,21 action="#{privilegeManagedBean.deleteAction(p)}" Failed to parse the expression [#{privilegeManagedBean.deleteAction(p)}]
Bean:-Privilege
public class Privilege {
private int id;
private String privilege;
public Privilege() {
}
public Privilege(int id, String privilege) {
this.id = id;
this.privilege = privilege;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getPrivilege() {
return privilege;
}
public void setPrivilege(String privilege) {
this.privilege = privilege;
}
}
bean:- PrivilegeDao.java
public int deletePrivilege(int id) {
PreparedStatement preparedStatement = null;
String sqlprivilege;
Connection dbConnection = null;
int pinsert = 0;
try {
sqlprivilege = "delete privilege from privilege where id=?";
dbConnection = ConnectionDao.getDBConnection();
preparedStatement = dbConnection.prepareStatement(sqlprivilege);
preparedStatement.setInt(2, id);
if(preparedStatement.executeUpdate()==1)
pinsert=1;
else
pinsert=0;
System.out.println("privilege is delete :- ");
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
if (preparedStatement != null) {
try {
preparedStatement.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (dbConnection != null) {
try {
dbConnection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return pinsert;
}
bean :-PrivilegeManagedBean
#ManagedBean(name = "privilegeManagedBean", eager = true)
#SessionScoped
/* #ManagedProperty(value="#param.id") */
public class PrivilegeManagedBean {
private int id;
private String privilege;
private PrivilegeDao pdao;
#SuppressWarnings("unused")
private List<Privilege> privilegeData;
private static int srno;
private int selectedRowIndex = -1;
public PrivilegeManagedBean() {
privilegeData = new ArrayList<Privilege>();
pdao = new PrivilegeDao();
srno = 0;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getPrivilege() {
return privilege;
}
public void setPrivilege(String privilege) {
this.privilege = privilege;
}
public void setPrivilegeData(List<Privilege> privilegeData) {
this.privilegeData = privilegeData;
}
public List<Privilege> getPrivilegeData() {
return this.privilegeData = pdao.getUserList();
}
public int getSelectedRowIndex() {
return selectedRowIndex;
}
public void setSelectedRowIndex(int selectedRowIndex) {
this.selectedRowIndex = selectedRowIndex;
}
public void addDataTableRow() {
pdao.addRow(this.id, this.privilege);
}
private static ArrayList<Privilege> privilegeList = new ArrayList<Privilege>();
public ArrayList<Privilege> getPrivilegeList() {
return privilegeList;
}
public void setPrivilegeList(ArrayList<Privilege> privilege) {
privilegeList = (ArrayList<Privilege>) pdao.getUserList();
}
public int addAction() {
Privilege privilegeitem = new Privilege(this.id, this.privilege);
privilegeList.add(privilegeitem);
return pdao.addPrivilege(this.privilege);
}
public int deleteAction() {
Privilege privilegeitem = new Privilege(this.id, this.privilege);
privilegeList.remove(privilegeitem);
System.out.println("delete Action...");
return pdao.deletePrivilege(this.id);
}
public int onEdit(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Privilege Edited",
((Privilege) event.getObject()).getPrivilege());
FacesContext.getCurrentInstance().addMessage(null, msg);
int pid = pdao.getPrivilegeId(this.privilege);
System.out.println("Privilege Name For Id :- " + this.privilege);
System.out.println("Privilege Id :- " + pid);
return pdao.updatePrivilege(pid, this.privilege);
}
public void onCancel(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Privilege Cancelled");
FacesContext.getCurrentInstance().addMessage(null, msg);
privilegeList.remove((Privilege) event.getObject());
}
public String deletePrivilege(Privilege privilege) {
privilegeList.remove(privilege);
return null;
}
public int getSrno() {
return ++srno;
}
}
Privilege.xhtml
<p:growl id="messages" showDetail="true" />
<p:dataTable value="#{privilegeDao.userList}" var="p"
id="datatbldispprivilege" style="width:500px" editable="true" lazy="true">
<f:facet name="header">
Privilege List
</f:facet>
<p:ajax event="rowEdit" listener="#{privilegeManagedBean.onEdit}"
update=":form1:messages" />
<p:ajax event="rowEditCancel"
listener="#{privilegeManagedBean.onCancel}" update=":form1:messages" />
<p:column headerText="Privileges Name">
<p:cellEditor>
<f:facet name="output">
<p:outputLabel value="#{p.privilege}" name="privilegeoutputname" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{privilegeManagedBean.privilege}"
name="privilegeinputname" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Options" style="width:100px">
<p:rowEditor>
</p:rowEditor>
</p:column>
<p:column headerText="Delete" style="width:100px">
<p:commandLink action="#{privilegeManagedBean.deleteAction(p)}"
update="#form">
<p:graphicImage value="/images/deleteicon.png" library="images"
onclick="if (!confirm('Are you sure you want to delete the current record?')) return false"
width="20px" height="20px" />
<f:param name="pname" value="#{p.name}" />
</p:commandLink>
</p:column>
</p:dataTable>
Your PrivilegeManagedBean#deleteAction don't accepts any arguments, but your JSF code passes the current iteration of the data table value to the method. So either don't pass anything to the method:
<p:commandLink action="#{privilegeManagedBean.deleteAction()}" update="#form">
or change the method signature of PrivilegeManagedBean#deleteAction.
you're trying to call the wrong method. action should be like this:
<p:commandLink action="#{privilegeManagedBean.deletePrivilege(p)}" update="#form">
i know that this is quetion is already answered here but i don't know why my code didn't work
i have two list and i want that when the first one changes that's the others update
here's my code
<h:selectOneMenu id="e4" styleClass="col-md-5" value="#{categoryModel.selectedMenu}">
<f:selectItem />
<f:selectItems value="#{categoryModel.catFinanceVect}" var="catFinance"itemLabel="#{catFinance.designation}" itemValue="#{catFinance.ligne}" />
<!-- <a4j:ajax event="valueChange" render="e3" execute="#this" />-->
<f:ajax event="valueChange" execute="#this" render="e3" listener="#{categoryModel.getCatItList}"/>
</h:selectOneMenu>
<div class="col-md-1"></div>
<h:selectOneMenu id="e3" styleClass="col-md-6">
<f:selectItem />
<f:selectItems value="#{categoryModel.catItVect}" var="catIt"itemLabel="#{catIt.designation}" itemValue="#{catIt.designation}" />
</h:selectOneMenu>
and here's my backing bean :
#ManagedBean
#SessionScoped
public class CategoryModel {
private CatFinance catFinance= new CatFinance();
private Vector<CatFinance> catFinanceVect = new Vector<CatFinance>();
private CatIt catIt= new CatIt();
private Vector<CatIt> catItVect = new Vector<CatIt>();
private Integer selectedMenu;
public CategoryModel() {
super();
// TODO Auto-generated constructor stub
}
public CatFinance getCatFinance() {
return catFinance;
}
public void setCatFinance(CatFinance catFinance) {
this.catFinance = catFinance;
}
public Vector<CatFinance> getCatFinanceVect() {
return catFinanceVect;
}
public void setCatFinanceVect(Vector<CatFinance> catFinanceVect) {
this.catFinanceVect = catFinanceVect;
}
public CatIt getCatIt() {
return catIt;
}
public void setCatIt(CatIt catIt) {
this.catIt = catIt;
}
public Vector<CatIt> getCatItVect() {
return catItVect;
}
public void setCatItVect(Vector<CatIt> catItVect) {
this.catItVect = catItVect;
}
public Integer getSelectedMenu() {
return selectedMenu;
}
public void setSelectedMenu(Integer selectedMenu) {
this.selectedMenu = selectedMenu;
}
public void getCatFinanceList(){
this.setCatFinance(new CatFinance());
CatFinanceService catFinanceService = (CatFinanceService) SpringDaoCtxFactory.getDaoContext().getBean("CatFinanceService");
this.getCatFinanceVect().clear();
try {
this.getCatFinanceVect().addAll(catFinanceService.getCatFinanceList());
} catch (Exception e) {
e.printStackTrace();
}
}
public void getCatItList(AjaxBehaviorEvent event){
this.setCatIt(new CatIt());
CatItService catItService = (CatItService) SpringDaoCtxFactory.getDaoContext().getBean("CatItService");
this.getCatItVect().clear();
System.out.println("aaaa");
try {
this.getCatItVect().addAll(catItService.getCatItList(2));
} catch (Exception e) {
e.printStackTrace();
}
}
#PostConstruct
public void init(){
getCatFinanceList();
}
}
if anyone can help in this or give me a good tutoriel of how to do it i will appreciate it so much
thanks in advance
The f:ajax event is invalid. It should be change (or empty as it defaults to change for h:selectOneMenu.)
<f:ajax execute="#this" render="e3" listener="#{categoryModel.getCatItList}"/>
I'm using selectOneMenu for displaying some pictures and Strings, the pictures is for displaying purposes only i have (i.e. i have nothing to do with them on submitting) i want only to set the string next to the image, i have a conflict in setting the itemValue of the f:selectItems to the String required, when i do that the images doesn't appear at all, in a word i want to only submit the value of the string in the chosen selectItem without using converter:
JSF Code:
<p:selectOneMenu id="SkinChooser" value="#{personBean.ObjectDTO.personDescription.skin}"
panelStyle="width:150px" effect="fade" var="s"
style="width:160px" converter="#{personBean.converter}">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{missedPersonBean.selectedSkins}"
var="skin" itemLabel="#{skin.skinType}" itemValue="#{skin}" />
<p:column>
<p:graphicImage value="/resources/images/skin/#{s.skinPhoto}"
width="40" height="50" />
</p:column>
<p:column>
#{s.skinType}
</p:column>
</p:selectOneMenu>
Skin.Java
public class Skin {
String skinPhoto;
String skinType;
public Skin() {
}
public Skin(String photo, String type) {
this.skinPhoto = photo;
this.skinType = type;
}
public String getSkinPhoto() {
return skinPhoto;
}
public void setSkinPhoto(String skinPhoto) {
this.skinPhoto = skinPhoto;
}
public String getSkinType() {
return skinType;
}
public void setSkinType(String skinType) {
this.skinType = skinType;
}
}
personBean.Java
#ManagedBean(name = "personBean")
#SessionScoped
public class ReportPerson {
private Skin skin;
private static List<Skin> selectedSkins;
static {
System.err.println("Array is filled");
selectedSkins = new ArrayList<Skin>();
selectedSkins.add(new Skin("1", "Pale white"));
selectedSkins.add(new Skin("2", "Fair white"));
selectedSkins.add(new Skin("3", "Light brown"));
selectedSkins.add(new Skin("4", "Moderate brown"));
selectedSkins.add(new Skin("5", "Dark brown"));
selectedSkins.add(new Skin("6", "Deeply pigmented"));
System.err.println("Finished Filling");
}
public List<Skin> getSelectedSkins() {
return selectedSkins;
}
public void setSelectedSkins(List<Skin> selectedSkins) {
this.selectedSkins = selectedSkins;
}
public Skin getSkin() {
return skin;
}
public void setSkin(Skin skin) {this.skin = skin;}
}