用ajax点击后selectOneListbox组件:如何隐藏H +组件、ajax、selectOneListbox

2023-09-10 21:01:52 作者:谁的年少不轻狂@

我有一个< H:命令> 点击:selectOneListbox> H; ,一个&LT时,将出现。当用户从列表框中选择我要出现在所选择的值< H:inputText的> 和隐藏列表框

我不能让< H:selectoneListbox> 停止一旦出现渲染。该渲染属性工作正常视图第一次出现的时候,却会被忽略后,我点击列表和监听器调用。

任何想法?

下面是一个facelet:

 < H:panelGroup中>
    < H:inputText的ID =TitleText值=#{bindingScheduleHandler.title}/>
    < H:的commandButton值=客户的ActionListener =#bindingScheduleHandler.clientList}/>

    < H:selectOneListbox ID =列表框值=#{bindingScheduleHandler.clients}大小=5
        渲染=#{bindingScheduleHandler.showClients}>
        < F:selectItems的值=#{bindingScheduleHandler.clientLabelsValues​​}/>
        < F:Ajax事件=点击监听器=#{bindingScheduleHandler.clickListener}
            渲染=TitleText/>
    < / H:selectOneListbox>
< /小时:panelGroup中>
 

下面是支持bean:

 公共无效clickListener(AjaxBehaviorEvent事件){
    this.title =客户;
    showClients = FALSE;
    renderClientList = FALSE;
}
 
下载office2013后 里面的组件可以直接用 这样还需要激活吗

解决方案

< F:AJAX渲染> ,你不能参考这是有条件地渲染组件由JSF。相反,你需要参考父组件是总是渲染。最简单的解释是,< F:AJAX> 是使用JavaScript来更新由JSF psented的HTML元素的重新$ P $的内容(节点值)零件。这是不可能的显示/隐藏在HTML元素本身。

只需更新父组件代替。

 < H:panelGroup中的id =组>
    < H:inputText的ID =TitleText值=#{bindingScheduleHandler.title}/>
    < H:的commandButton值=客户的ActionListener =#bindingScheduleHandler.clientList}/>

    < H:selectOneListbox ID =列表框值=#{bindingScheduleHandler.clients}大小=5
        渲染=#{bindingScheduleHandler.showClients}>
        < F:selectItems的值=#{bindingScheduleHandler.clientLabelsValues​​}/>
        < F:Ajax事件=点击监听器=#{bindingScheduleHandler.clickListener}
            渲染=组/>
    < / H:selectOneListbox>
< /小时:panelGroup中>
 

这会顺便也立即修复不显示所选项目的问题< H:inputText的> :)

I have a <h:selectOneListbox> that appears when a <h:commandbutton> is clicked. When the user selects from the listbox I want the selected value to appear in a <h:inputText> and hide the listbox.

I can't make the <h:selectoneListbox> stop rendering once it appears. The rendered attribute works fine when the view first appears, but is ignored after I click the list and the listener is invoked.

Any ideas?

Here is the Facelet:

<h:panelGroup>
    <h:inputText id="TitleText" value="#{bindingScheduleHandler.title}"/>
    <h:commandButton value="Clients" actionListener= #bindingScheduleHandler.clientList}" />

    <h:selectOneListbox id="listBox" value="#{bindingScheduleHandler.clients}" size="5"  
        rendered="#{bindingScheduleHandler.showClients}">
        <f:selectItems value="#{bindingScheduleHandler.clientLabelsValues}" />
        <f:ajax event="click" listener="#{bindingScheduleHandler.clickListener}"  
            render="TitleText" />
    </h:selectOneListbox>
</h:panelGroup>

Here is the backing bean:

public void clickListener(AjaxBehaviorEvent event) {
    this.title = clients;
    showClients = false;
    renderClientList = false;
}

解决方案

In the <f:ajax render>, you can't refer components which are conditionally rendered by JSF. Instead, you need to refer a parent component which is always rendered. The simple explanation is that the <f:ajax> is using JavaScript to update the content (the node value) of the HTML element as represented by the JSF component. It isn't possible to show/hide the HTML element itself.

Just update a parent component instead.

<h:panelGroup id="group">
    <h:inputText id="TitleText" value="#{bindingScheduleHandler.title}"/>
    <h:commandButton value="Clients" actionListener= #bindingScheduleHandler.clientList}" />

    <h:selectOneListbox id="listBox" value="#{bindingScheduleHandler.clients}" size="5"  
        rendered="#{bindingScheduleHandler.showClients}">
        <f:selectItems value="#{bindingScheduleHandler.clientLabelsValues}" />
        <f:ajax event="click" listener="#{bindingScheduleHandler.clickListener}"  
            render="group" />
    </h:selectOneListbox>
</h:panelGroup>

This will by the way also instantly fix the problem of the selected item not being displayed in the <h:inputText> :)