Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 从其他下拉列表中选择值时显示包含值的下拉框_Jsf_Jsf 2_Richfaces - Fatal编程技术网

Jsf 从其他下拉列表中选择值时显示包含值的下拉框

Jsf 从其他下拉列表中选择值时显示包含值的下拉框,jsf,jsf-2,richfaces,Jsf,Jsf 2,Richfaces,我需要在从另一个下拉框中选择一个值时显示一个新的下拉框,该下拉框在页面中已经可用。第一个下拉列表已经在页面中可用,第二个下拉列表将根据我从Bean类获得的布尔值隐藏 问题是隐藏下拉列表在我刷新页面之前不可见。当我刷新页面时,只有我才能看到隐藏的下拉框。当我从第一个下拉框中取消选择另一个值时,第二个下拉框也会被隐藏,但我必须刷新页面 请参见下面的“我的代码”以供参考: instrumentDetails.xhtml 我已经用“监听器”完成了 我已经在listener的第一个下拉列表中添加了代码。请

我需要在从另一个下拉框中选择一个值时显示一个新的下拉框,该下拉框在页面中已经可用。第一个下拉列表已经在页面中可用,第二个下拉列表将根据我从Bean类获得的布尔值隐藏

问题是隐藏下拉列表在我刷新页面之前不可见。当我刷新页面时,只有我才能看到隐藏的下拉框。当我从第一个下拉框中取消选择另一个值时,第二个下拉框也会被隐藏,但我必须刷新页面

请参见下面的“我的代码”以供参考:

instrumentDetails.xhtml


我已经用“监听器”完成了

我已经在listener的第一个下拉列表中添加了代码。请参阅以下更新代码:

<!-- Product Group -->

<h:outputText id="product_Group"
    value="#{msg.instrument_add_edit_product_group}" escape="false" />
<a4j:region>
    <h:selectOneMenu
        value="#{instrumentBean.instrumentData.productGroupId}"
        valueChangeListener="#{instrumentBean.populateProductTypeByServiceProvider}"
        style="width:140px" styleClass="dropDown" >
        <f:selectItem itemValue="0"
            itemLabel="#{msg['gobal.select.default.label']}" />
        <f:selectItems var="productGroupItem"
            itemValue="#{productGroupItem.id}"
            itemLabel="#{productGroupItem.label}"
            value="#{referenceMaster.productGroupLabelKeyList}" />
        <a4j:ajax event="valueChange"   render="productTypeListInstrument,servList" execute="@this" />
        <a4j:ajax event="change"  listener="#{instrumentBean.onChangeProductGroup}" />
    </h:selectOneMenu>
</a4j:region>

谢谢你们的回答。

你们已经实现了当第一个框中的值发生变化时重新呈现第二个下拉框的机制。您只需检查第二个下拉框的父级的呈现条件是否正常工作:rendered={instrumentBean.showService}a可能会修复它。@VasilLukach。。亲爱的瓦西里,谢谢你的回答。正如您在我的代码中看到的,我已经在第二个下拉列表中使用了:rendered={instrumentBean.showService}。但只有在刷新页面后才会显示。这就是问题所在。请给出建议。与ValueChangeListener相关的仅在提交时调用。您需要使用AJAX来更改服务器端的值。
private boolean showService;

    public void populateProductTypeByServiceProvider(ValueChangeEvent event) {
        try {
            Integer rowindex = new Integer(event.getNewValue().toString());
            if (!CommonUtil.isBlankInteger(instrumentData
                    .getServiceProviderId())
                    && !CommonUtil.isBlankInteger(rowindex)) {

                int productGroupId = rowindex.intValue();

                List<LabelKeyTO> labelKeyTOList = findProductsByGroupAndServiceProvider(
                        productGroupId, instrumentData.getServiceProviderId());

                Collections.sort(labelKeyTOList);
                this.productTypeDetailList = labelKeyTOList;
                setDefaultDetailsListSerRate();
                defaultServiceTable();

            } else {
                if (CommonUtil.isBlankInteger(instrumentData
                        .getServiceProviderId())) {
                    this.instrumentData.setProductGroupId(0);
                }
                this.instrumentData.setProductTypeId(0);
                setDefaultDetailsListProdSerRate();
                defaultServiceTable();
            }

            if(rowindex == 1){
                showService = true;
            }else if(rowindex == 2){
                showService = true;
            }else{
                showService = false;
            }



        } catch (Exception e) {
            this.instrumentData.setProductTypeId(0);
            setDefaultDetailsListProdSerRate();
            defaultServiceTable();
            String reasonFailure = e.getMessage();
            validationMessage(reasonFailure, reasonFailure, reasonFailure,
                    FacesMessage.SEVERITY_ERROR);
        }
    }
<!-- Product Group -->

<h:outputText id="product_Group"
    value="#{msg.instrument_add_edit_product_group}" escape="false" />
<a4j:region>
    <h:selectOneMenu
        value="#{instrumentBean.instrumentData.productGroupId}"
        valueChangeListener="#{instrumentBean.populateProductTypeByServiceProvider}"
        style="width:140px" styleClass="dropDown" >
        <f:selectItem itemValue="0"
            itemLabel="#{msg['gobal.select.default.label']}" />
        <f:selectItems var="productGroupItem"
            itemValue="#{productGroupItem.id}"
            itemLabel="#{productGroupItem.label}"
            value="#{referenceMaster.productGroupLabelKeyList}" />
        <a4j:ajax event="valueChange"   render="productTypeListInstrument,servList" execute="@this" />
        <a4j:ajax event="change"  listener="#{instrumentBean.onChangeProductGroup}" />
    </h:selectOneMenu>
</a4j:region>