1

我到处搜索,但找不到我的问题的答案,所有大多数问题和答案都与 selectOneMenu 有关。我在我的页面中使用 selectOneListbox 组件,如下所示

<h:selectOneListbox id="basic" value="#{location.selectedCategory}" style="width: 400px; border: none;" >                                                                                   
    <f:selectItems value="#{location.categories}" var="y" itemLabel="#{y.title} (#{y.itemCount})" itemValue="#{y}" />
    <f:ajax listener="#{location.onNodeSelect}"/>
    <f:ajax render="itemsPanel" execute="@this"/>
</h:selectOneListbox>  

我的豆子

  @ManagedBean(name = "location")    
  @SessionScoped    
  public class LocationServiceBean extends BaseService implements Serializable{

    public void onNodeSelect(AjaxBehaviorEvent event) {  
       log.info("Entering method : onNodeSelect : ");
       if(null != selectedCategory){
        GetCategoriesAndItemsResponse response =getLocationSupport().getItemsByCategoryAndLocation(selectedCategory.getId(), selectedLocationId);
            if(response.getStatusCode().equals("0"))
            {
                items = response.getData().getItems();
                log.info("Items size: " + items.size());
            }
        }
    } 
}

这里的问题是,当我在列表框中选择项目时,selectOneListBox 中的上述侦听器不会被触发。也尝试使用 primeface (3.5) 组件,但没有运气。

更新:添加了更多代码

<h:form id="venuForm" prependId="false">
                                                    <legend>2. Choose Venue</legend>
                                                    <div class="control-group">
                                                        <label class="span3" for="Country">Venue</label>

                                                        <div class="controls">
                                                            <h:selectOneMenu value="#{location.selectedLocationId}" id="select01" required="true"
                                                                requiredMessage="Location is a mandatory field" styleClass="span8">
                                                                <f:selectItem itemValue="#{null}" itemLabel="Select Location" noSelectionOption="true" />
                                                                <f:selectItems value="#{location.allLocations}" var="c" itemLabel="#{c.title}" itemValue="#{c.locationId}" />
                                                                <f:ajax listener="#{location.loadCategoriesListner}" render=":itemForm:categoriesPanel" execute="@this" />
                                                                <f:ajax execute="@this" render=":itemForm:itemsPanel" />
                                                            </h:selectOneMenu>
                                                        </div>
                                                    </div>
                                                </h:form>
                                                <h:form id="itemForm" prependId="false">
                                                    <legend>3. Choose Gift</legend>
                                                    <div class="control-group">

                                                        <p:outputPanel id="panel" autoUpdate="true">
                                                            <div style="padding-left: 5px; padding-right: 5px; padding-bottom: 5px; border: none;">
                                                                <p:panel id="categoriesPanel" rendered="#{location.categories != null}" autoUpdate="true" style=" border: none;">
                                                                    <h:selectOneListbox id="basic"  value="#{location.selectedCategory}" style="width: 400px; border: none;">

                                                                        <f:selectItems value="#{location.categories}" var="y" itemLabel="#{y.title} (#{y.itemCount})" itemValue="#{y}" />
                                                                        <f:ajax listener="#{location.onNodeSelect}" render="itemsPanel" execute="@form" event="change"/>
                                                                    </h:selectOneListbox>

                                                                </p:panel>
                                                            </div>
                                                        </p:outputPanel>
                                                        <div class="clear" style="height: 30px;"></div>

                                                        <div style="padding-bottom: 5px; padding-top: 5px;">
                                                            <p:panel id="itemsPanel" style="float: left;" header="Items">
                                                                <ui:repeat value="#{location.items}" var="o" id="itemTable">

                                                                    <div style="width: 170px; height: 200px; margin: auto; float: left; border-style: solid; border-color: #ECE5B6; border-width: thin;">
                                                                        <div style="margin: 5px; padding: 5px;">
                                                                            <div style="margin-bottom: 5px;">
                                                                                <h:outputText value="#{fnc:getTitleTruncateText(o.title)}"  style="margin: 0 auto;  padding: 0 0 20px; color: #9A1326; width: 100px; font-size: 14px; text-align: center;" />
                                                                                <BR />
                                                                            </div>

                                                                            <div style="padding-left: 45px; margin-bottom: 5px;">
                                                                                <h:graphicImage value="http://dev.cdn.abc.com/#{o.imageId}_3.png" id="itemImage" alt="#{o.title}" />
                                                                            </div>
                                                                            <div
                                                                                style="padding: 5px 10px; background-color: #FFC200; margin: 15px auto 0 auto; width: 100px; text-align: center; color: #29000F; border: 1px solid #F2BD00;">
                                                                                <h:outputText value="$ #{fnc:formatDoubleValue(o.salePrice)}" />
                                                                            </div>

                                                                            <div class="clear" style="height: 5px;"></div>
                                                                            <div style="float: left;">
                                                                                <div style="float: left; margin-right: 50px;">
                                                                                    <p:spinner id="itemQty" value="#{o.selectedQty}" size="3" min="1" max="#{o.qtyAvailable}" style="width: 20px;" />
                                                                                </div>

                                                                                <div style="float: right;">
                                                                                    <h:commandButton value="Add" id="addToCartBtn"  rendered="#{o.qtyAvailable > 0 }" actionListener="#{location.addItemToCart(o)}" />
                                                                                </div>
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                </ui:repeat>
                                                            </p:panel>
                                                        </div>

                                                        <div class="clear" style="height: 30px;"></div>
                                                        <div style="float: right;">
                                                            <h:commandButton action="#{location.gotoUserDetails}" value="Next" onclick="return(validate());" rendered="#{!empty location.selectedItems}" />
                                                        </div>

                                                    </div>
                                                </h:form>
4

1 回答 1

1

问题出在转换器上。可以通过从 jsf 组件获取原始类型值(即整数、字符串...),或者为类创建自定义转换器并在组件中引用它(属性:转换器)来解决问题。

于 2013-06-19T08:18:31.300 回答