本文介绍了selectOneMenu用于更新等selectOneMenu用于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,当我选择的第一个SelectOnMenu的任何项目,以更新第二selectOneMenu用于。因为它是现在,我得到的值从ManagedBean的SelectOneMenus。我想我已经使用AJAX(jQuery的),以将参数传递给ManagedBean。

 < H:形式GT;
    < D​​IV CLASS =中心>
        &所述; H:panelGrid的ID =editTable列=2的styleClass =中心>
            ...
            < H:的outputText值=#{msg.timetable_list_category}/>
            < H:selectOneMenu用于类=类别>
                < F:selectItems的值=#{categoryBackingBean.categorys}VAR =C
                    itemLabel =#{c.category_Name}itemValue =#{c.id}/>
            < / H:selectOneMenu用于>

                < H:的outputText值=#{msg.timetable_list_seminarblock}/>
            < H:selectOneMenu用于类=seminarblock>
                < F:selectItems的值=#{seminarblockBackingBean.seminarblocks}VAR =S
                    itemLabel =#{s.seminarblock_Name}itemValue =#{s.seminarblock_Id}/>
            < / H:selectOneMenu用于>
            ...
        < / H:panelGrid的>
        ...
    < / DIV>
< /小时:形式GT;
 

解决方案

其实你可以使用所调用的ValueChangeListener当您selectOneMenu用于更改值:

 < H:selectOneMenu用于类=类别valueChangeListener =#{yourBean.selectOneMenuListener}>
    < F:selectItems的值=#{categoryBackingBean.categorys}VAR =C
        itemLabel =#{c.category_Name}itemValue =#{c.id}/>
< / H:selectOneMenu用于>
 

然后,在你豆你有这样的方法:

 公共无效selectOneMenuListener(ValueChangeEvent事件){
    //新选择这将返回您
    //值作为对象。你必须投它。
    对象为newValue = event.getNewValue();
    //你的处理逻辑的其余部分放在这里?
}
 

要更新的页面,您可以添加的onchange =提交()< H:selectOneMenu用于/> 。对于一些局部的渲染,你可以尝试添加该< F:AJAX /> 而不是的onchange =提交()

 < H:selectOneMenu用于类=类别valueChangeListener =#{yourBean.selectOneMenuListener}>
    < F:selectItems的值=#{categoryBackingBean.categorys}VAR =C
        itemLabel =#{c.category_Name}itemValue =#{c.id}/>
    < F:Ajax事件=变执行=@形式呈现=theIdOfTheComponentYouWantToReRender/>
< / H:selectOneMenu用于>
 

如果我没有记错,你会想在第一个菜单中选择元素的ID和填充第二个照吧。然后,你可以使对方selectOneMenu用于或者,如果需要的话,面板包裹的窗体的一部分。

I want to update the second SelectOneMenu when I select any item of the first SelectOnMenu. As it is now, I get the values for the SelectOneMenus from a ManagedBean. I guess I've to use AJAX (jquery) to send parameters to the ManagedBean.

<h:form>
    <div class="center">
        <h:panelGrid id="editTable" columns="2" styleClass="center">
            ...
            <h:outputText value="#{msg.timetable_list_category}" />
            <h:selectOneMenu class="category">
                <f:selectItems value="#{categoryBackingBean.categorys}" var="c"
                    itemLabel="#{c.category_Name}" itemValue="#{c.id}" />
            </h:selectOneMenu>

                <h:outputText value="#{msg.timetable_list_seminarblock}" />
            <h:selectOneMenu class="seminarblock">
                <f:selectItems value="#{seminarblockBackingBean.seminarblocks}" var="s"
                    itemLabel="#{s.seminarblock_Name}" itemValue="#{s.seminarblock_Id}" />
            </h:selectOneMenu>
            ...
        </h:panelGrid>
        ...
    </div>
</h:form>
解决方案

Actually you can use a ValueChangeListener that is invoked when the value of your selectOneMenu changes:

<h:selectOneMenu class="category" valueChangeListener="#{yourBean.selectOneMenuListener}">
    <f:selectItems value="#{categoryBackingBean.categorys}" var="c"
        itemLabel="#{c.category_Name}" itemValue="#{c.id}" />
</h:selectOneMenu>

Then, in your bean you have this method:

public void selectOneMenuListener(ValueChangeEvent event) {
    //This will return you the newly selected
    //value as an object. You'll have to cast it.
    Object newValue = event.getNewValue(); 
    //The rest of your processing logic goes here...
}

To update the page you can either add onchange="submit()" to your <h:selectOneMenu/>. For some partial rendering you can try adding this <f:ajax/> instead of onchange="submit()":

<h:selectOneMenu class="category" valueChangeListener="#{yourBean.selectOneMenuListener}">
    <f:selectItems value="#{categoryBackingBean.categorys}" var="c"
        itemLabel="#{c.category_Name}" itemValue="#{c.id}" />
    <f:ajax event="change" execute="@form" render="theIdOfTheComponentYouWantToReRender"/>
</h:selectOneMenu>

If I'm not mistaken you'll want to get the id of the element selected in the first menu and populate the second one according to it. Then you can render the other selectOneMenu or, if needed, a panel wrapping a part of your form.

这篇关于selectOneMenu用于更新等selectOneMenu用于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 21:46