访问 rowselector 时会重置 selectOneMenu 值
嗨,我遇到了这种情况,我不知道为什么会发生。
我有一个像这样的选择菜单
<ice:selectOneMenu id="ddlProfesion" value="#{FrmClientes.profesionSeleccionado}" style="width:230px">
<f:selectItems value="#{SessionBean1.listaProfesion}"/>
<f:converter converterId="DefaultSelectItemConverter" />
</ice:selectOneMenu>
,现在我有一个数据表
public List getListaProfesion() {
if (listaProfesion == null) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
listaProfesion = new ArrayList<SelectItem>();
List<Profesion> profesionList = session.getNamedQuery("Profesion.findAll").list();
for (Profesion c : profesionList) {
listaProfesion.add(new SelectItem(c, c.getNombre()));
}
return listaProfesion;
}
return listaProfesion;
}
,当我连续单击一个面板弹出窗口时,会打开一个包含对象专业数据的面板弹出窗口
。 rowSelector 中的 SelectionListener 的代码是这样的:
public void seleccionaTerceros(RowSelectorEvent event) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Query query = session.getNamedQuery("Clientes.findByTercero");
query.setParameter("tercero", "12332454");
// I send a parameter value for example
if (!query.list().isEmpty()) {
cliente = (Clientes) query.list().get(0);
profesionSeleccionado=cliente.getProfesionID();
} else {
cliente = null;
profesionSeleccionado=null;
}
setMostrarModal(true);
}
我将 profesionSeleccionado 设置为 objetc 的值并且不起作用,我将此代码放在另一个位置,例如托管 bean 的构造函数或按钮操作中..并且它可以工作.. 我已经调试
并看到属性的 getter 和 setter 被访问了两次,为什么,我不知道
我需要一些指导,我是新的。谢谢
pd:用于列出对象的转换器的代码在选择菜单中是这样的
public class DefaultSelectItemConverter implements Converter {
/**
* Not explicitly documented.
*
* @see javax.faces.convert.Converter#getAsObject(javax.faces.context.FacesContext,
* javax.faces.component.UIComponent, java.lang.String)
*/
public Object getAsObject(FacesContext fcontext, UIComponent comp, String valueString) {
List<UIComponent> children = comp.getChildren();
for (UIComponent child : children) {
if (child instanceof UISelectItem) {
UISelectItem si = (UISelectItem) child;
if (si.getValue().toString().equals(valueString)) {
return si.getValue();
}
}
if (child instanceof UISelectItems) {
UISelectItems sis = (UISelectItems)child;
List<SelectItem> items = (List)sis.getValue();
for (SelectItem si : items) {
if (si.getValue().toString().equals(valueString)) {
return si.getValue();
}
}
}
}
throw new ConverterException("no conversion possible for string representation: " + valueString);
}
/**
* Not explicitly documented.
*
* @see javax.faces.convert.Converter#getAsString(javax.faces.context.FacesContext,
* javax.faces.component.UIComponent, java.lang.Object)
*/
public String getAsString(FacesContext fcontext, UIComponent comp, Object value) {
return value.toString();
}
}
Hi I've this situation and I dont know why it's happening..
I have a selectonemenu like this
<ice:selectOneMenu id="ddlProfesion" value="#{FrmClientes.profesionSeleccionado}" style="width:230px">
<f:selectItems value="#{SessionBean1.listaProfesion}"/>
<f:converter converterId="DefaultSelectItemConverter" />
</ice:selectOneMenu>
the list of items
public List getListaProfesion() {
if (listaProfesion == null) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
listaProfesion = new ArrayList<SelectItem>();
List<Profesion> profesionList = session.getNamedQuery("Profesion.findAll").list();
for (Profesion c : profesionList) {
listaProfesion.add(new SelectItem(c, c.getNombre()));
}
return listaProfesion;
}
return listaProfesion;
}
now I have a datatable and when I click in a row a panelPopup open with the data of the object Profesion..
the code of the selectionListener in the rowSelector is this:
public void seleccionaTerceros(RowSelectorEvent event) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Query query = session.getNamedQuery("Clientes.findByTercero");
query.setParameter("tercero", "12332454");
// I send a parameter value for example
if (!query.list().isEmpty()) {
cliente = (Clientes) query.list().get(0);
profesionSeleccionado=cliente.getProfesionID();
} else {
cliente = null;
profesionSeleccionado=null;
}
setMostrarModal(true);
}
I set profesionSeleccionado to the Value of the objetc and doesnt work, I put this code in another location, like the constructor of the managed bean or in a button action.. and IT WORKS...
I have debbuged and see that the getter and the setter of the atribute are accesed twice, why, i dont know
please I need some guide, I'am new with this.. Thanks
pd: the code of the converter used to list objects in the selectonemenu is this
public class DefaultSelectItemConverter implements Converter {
/**
* Not explicitly documented.
*
* @see javax.faces.convert.Converter#getAsObject(javax.faces.context.FacesContext,
* javax.faces.component.UIComponent, java.lang.String)
*/
public Object getAsObject(FacesContext fcontext, UIComponent comp, String valueString) {
List<UIComponent> children = comp.getChildren();
for (UIComponent child : children) {
if (child instanceof UISelectItem) {
UISelectItem si = (UISelectItem) child;
if (si.getValue().toString().equals(valueString)) {
return si.getValue();
}
}
if (child instanceof UISelectItems) {
UISelectItems sis = (UISelectItems)child;
List<SelectItem> items = (List)sis.getValue();
for (SelectItem si : items) {
if (si.getValue().toString().equals(valueString)) {
return si.getValue();
}
}
}
}
throw new ConverterException("no conversion possible for string representation: " + valueString);
}
/**
* Not explicitly documented.
*
* @see javax.faces.convert.Converter#getAsString(javax.faces.context.FacesContext,
* javax.faces.component.UIComponent, java.lang.Object)
*/
public String getAsString(FacesContext fcontext, UIComponent comp, Object value) {
return value.toString();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在此页面找到了解决方案
http://jira.icefaces.org/browse/ICE-2297< /a>
问题已得到纠正,将immediate="false" 放在 RowSelector 上
:)
I found the solution in this page
http://jira.icefaces.org/browse/ICE-2297
the problem was corrected putting immediate="false" on the RowSelector
:)