在我选择h:selectOneMenu中的项目后,不会调用commandButton中的mi actionListener,只有当我按下按钮而没有选择selectOneMenu中的任何选项时它才有效 您可以在下面看到我的代码:
<h:form id="formBtnBusquedaAnomalias">
<table>
<tr>
<td>
<h:outputLabel id="idEstatusAnomalias" value="Estatus anomalias." />
<h:selectOneMenu id="selectOneMenuEstatusAnomalias"
value = "#{busquedaAnomaliasManageBean.selectedEstatusAnomaliaVO}" >
<f:converter converterId="estatusAnomaliaConverter"/>
<f:selectItem itemLabel="Select one" />
<f:selectItems value="#{busquedaAnomaliasManageBean.lstEstatusAnomaliaVOs}" var="estatusAnomalia"
itemLabel="#{estatusAnomalia.descripcionEstatusAnomalia}" />
</h:selectOneMenu>
</td>
</tr>
<tr>
<td>
<p:commandButton value="Buscar anomalias."
actionListener="#{busquedaAnomaliasManageBean.buscarAnomalias()}" />
</td>
</tr>
</table>
</h:form>
转换器类:
@FacesConverter(value = "estatusAnomaliaConverter")
public class EstatusAnomaliaConverter implements Converter{
@Override
public Object getAsObject(FacesContext ctx, UIComponent component, String value) {
EstatusAnomaliaVO estatusAnomaliaVO = new EstatusAnomaliaVO();
estatusAnomaliaVO.seDescripcionEstatusAnomalia(value);
return estatusAnomaliaVO;
}
@Override
public String getAsString(FacesContext ctx, UIComponent component, Object object) {
String temp = "";
if(!object == null)
{
temp = object.toString();
}
return temp;
}
}
ManageBean:
@ManagedBean(name=ConstantesManageBeans.MANAGE_BEAN_BUSQUEDA_ANOMALIAS)
@RequestScoped
public class BusquedaAnomaliasManageBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = -1955257440354260445L;
public void buscarAnomalias(){
//...some code here
}
]
答案 0 :(得分:0)
您的buscarAnomalias
方法不遵循ActionListener方法的签名。这是签名:
public void actionListener(ActionEvent event) {
// ...
}
为了使其有效,只需将ActionEvent
参数添加到您的方法中:
public void buscarAnomalias(ActionEvent event) {
//...some code here
}
如果我是你,我会使用action
代替actionListener
来执行托管bean操作:
<p:commandButton value="Buscar anomalias."
action="#{busquedaAnomaliasManageBean.buscarAnomalias()}" />
请注意,使用此方法,您无需在方法中添加ActionEvent event
参数。
更多信息:
代码中的另一个问题是,检索所选项目的值时,FacesConverter
失败。这是因为您尚未在itemValue
中设置<f:selectItems>
:
<h:selectOneMenu id="selectOneMenuEstatusAnomalias"
value="#{busquedaAnomaliasManageBean.selectedEstatusAnomaliaVO}">
<f:converter converterId="estatusAnomaliaConverter"/>
<f:selectItem itemLabel="Select one" />
<f:selectItems value="#{busquedaAnomaliasManageBean.lstEstatusAnomaliaVOs}"
var="estatusAnomalia" itemValue="#{estatusAnomalia}"
itemLabel="#{estatusAnomalia.descripcionEstatusAnomalia}" />
</h:selectOneMenu>