小编Ale*_*ama的帖子

如何根据其他选定的值更新选择菜单?

我在尝试制作我的selectOneMenu内容时遇到了麻烦,这取决于另一个选择的值。第一个的内容来自我的数据库中的一个表并且运行良好,但第二个应该来自另一个表,但我无法使其工作。这是我的index.html,我只是想证明这是如何工作的:


        <h:outputLabel value="Estado" styleClass="requiredLbl"/>
        <p:selectOneMenu id="Estado" value="#{beanInscripcion.id_estado}" valueChangeListener="#{beanInscripcion.buscarMunicipios(event)}" >  
            <f:selectItem itemLabel="Elegir Estado" itemValue="" />
            <f:selectItems value="#{beanInscripcion.estados}"  
                           var="edo" itemLabel="#{edo.nombre_estado}" itemValue="#{edo.id_estado}" />  
            <p:ajax update="Municipio"  listener="#{beanInscripcion.buscarMunicipios(event)}" />
        </p:selectOneMenu> 
        <p:separator /> 
        <h:outputLabel value="Municipio" styleClass="requiredLbl"/>
        <p:selectOneMenu id="Municipio" value="municipio">  
            <f:selectItems value="#{beanInscripcion.municipios}"  
                           var="mun" itemLabel="#{mun.nombre_municipio}" itemValue="#{mun.nombre_municipio}" />  
        </p:selectOneMenu>
Run Code Online (Sandbox Code Playgroud)

这是我的 Bean 部分,我应该在其中获取第二个菜单的内容:


@ManagedBean(name = "beanInscripcion")
@ViewScoped
public class BeanInscripcion implements Serializable {

    static String strURL;
    private List<Estado> estados; 
    private List<Municipio> municipios;
    private int id_estado;
    public BeanInscripcion() throws SQLException{
            estados = new ArrayList<Estado>();
            buscarEstados();
    }

    public …
Run Code Online (Sandbox Code Playgroud)

java jsf selectonemenu dynamic-content primefaces

5
推荐指数
2
解决办法
3万
查看次数

标签 统计

dynamic-content ×1

java ×1

jsf ×1

primefaces ×1

selectonemenu ×1