Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.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 2 h:inputText在更改h:SelectOne菜单值时不重新显示,不按预期工作_Jsf 2_Rendering_Show Hide - Fatal编程技术网

Jsf 2 h:inputText在更改h:SelectOne菜单值时不重新显示,不按预期工作

Jsf 2 h:inputText在更改h:SelectOne菜单值时不重新显示,不按预期工作,jsf-2,rendering,show-hide,Jsf 2,Rendering,Show Hide,我有一个h:selectOne菜单,当它的值变为特定值(比如“2”)时,它假设会显示隐藏字段(尚未渲染)。注意,它们链接到托管bean中属性的相同值 <h:outputText value="Function:"></h:outputText> <h:selectOneMenu id="funDrp" converter="FunctionConv" value="#{cardBean.card.functionId}"> <f:selectIt

我有一个h:selectOne菜单,当它的值变为特定值(比如“2”)时,它假设会显示隐藏字段(尚未渲染)。注意,它们链接到托管bean中属性的相同值

<h:outputText value="Function:"></h:outputText>
<h:selectOneMenu id="funDrp" converter="FunctionConv" value="#{cardBean.card.functionId}">
    <f:selectItems value="#{commonData.functions}" var="c" itemLabel="#{c.description}" itemValue="#{c.functionId}" />
    <f:ajax render="@form" execute="@form" event="valueChange" />
</h:selectOneMenu>

<h:outputText value=" Profile Id:" rendered="#{(cardBean.card.functionId.functionId==2)}"></h:outputText>
<h:inputText id="card_refillProfileId"rendered="#{(cardBean.card.functionId.functionId==2)}" label="Refill Profile Id" required="true" value="#{cardBean.card.refillProfileId}"></h:inputText>

<h:outputText value="Origin Type:" rendered="#{(cardBean.card.functionId.functionId==2)}"></h:outputText>
<h:inputText id="card_originType" rendered="#{(cardBean.card.functionId.functionId==2)}" label="Origin Node Type" required="true" value="#{cardBean.card.originType}"></h:inputText>

如果将“卡片”对象分配给现有实体,则它们可以正常工作,但如果是新实体,则无法按预期工作。

尝试

<f:ajax render="card_refillProfileId card_originType" execute="@form" event="valueChange" />

您的


应该是(事件可以省略)


selectOneMenu.value、转换器和渲染EL之间似乎不匹配。
有两个
functionId.functionId
。然后将
selectOneMenu.value
绑定到
cardBean.card.functionId
。如果
functionId
是一个函数,我可能会错。

这是一个完全可以预料到的行为。使用
可以重新渲染DOM中存在的HTML元素,但是通过在JSF组件中指定
rendered=“false”
,它们不会出现在DOM中。而且,由于ajax需要根据元素的id找到元素,然后替换它,所以这项工作显然无法完成

但是,可以通过在容器中包含组件(所有组件都使用
呈现的
属性)来处理您的作业,例如在
中,该容器始终呈现,但其子组件不呈现。因此,如果满足条件,ajax将能够使用
rendered=“true”
重新启动面板,该面板将包含所有组件,并且它们将出现在您的视图中


另外,如果视图/表单增长,ajax行为可能会非常昂贵。因此,如果您只想重新渲染某些组件,请在
标记中指定它:
(要渲染的组件的以空格分隔的ID列表)。

问题是,附加到select one菜单的值为空“card.functionId”.所以在检查它之前初始化它。正如我在构建bean之前尝试初始化它,但它没有帮助

为此,初始化是通过为selectOneMenu附加一个“ValueChangeListener”来完成的

<h:selectOneMenu id="funDrp" converter="FunctionConv" valueChangeListener="#     {cardBean.changeCardFunc}"
                                            value="#{cardBean.card.functionId}">
                                            <f:selectItems value="#{commonData.functions}" var="c"
                                            itemLabel="#{c.description}" itemValue="#{c.functionId}" />
                                            <f:ajax render="@form" execute="funDrp" event="change" />
                                          </h:selectOneMenu>

我无法渲染不存在的东西。如果将“卡片”对象分配给现有实体,它们工作正常。但是,如果它是一个新实体,它工作正常。如果将“卡片”对象分配给现有实体,你说的
是什么意思?你的意思是如果
cardBean.card
被初始化了吗?我在@PostConstructor中声明它时,到处都初始化了它,但这并没有解决它
valueChange
事件是有效的。更重要的是,它是
的默认事件。它甚至可以被省略。另请参见@Marwadosky我没有足够的代码上下文信息来帮助您。OP正在使用
render=“@form”
,因此我看不出有问题。@BalusC我不是说这是个问题,但我想让Marwa注意避开不必要的渲染,因为它不必要地增加了ajax响应大小。请详细说明用开发人员的话来说,“没有按预期工作”。到底发生了什么(没有)?您的支持bean的范围是什么?
<f:ajax render="@form" execute="@form" event="change" />
<h:selectOneMenu id="funDrp" converter="FunctionConv" valueChangeListener="#     {cardBean.changeCardFunc}"
                                            value="#{cardBean.card.functionId}">
                                            <f:selectItems value="#{commonData.functions}" var="c"
                                            itemLabel="#{c.description}" itemValue="#{c.functionId}" />
                                            <f:ajax render="@form" execute="funDrp" event="change" />
                                          </h:selectOneMenu>
public void changeCardFunc(ValueChangeEvent e) {
//  object newFunc= e.

    if(card!=null){
    card.setFunctionId((Function)e.getNewValue());
    }else {
        card= new Card();
        card.setFunctionId((Function)e.getNewValue());
        System.err.println(e.getNewValue());
    }
}