【问题标题】:f:ajax does not update ui:repeatf:ajax 不更新 ui:repeat
【发布时间】:2012-09-19 09:14:27
【问题描述】:

我的 JSF 页面是这样的,<f:ajax> 部分现在可以工作了。

<h:selectOneListbox value="#{category.categoryId}">
    <f:selectItems value="#{category.allSubCategories}" var="c" itemLabel="#{c.title}" itemValue="#{c.categoryId}" />
    <f:ajax execute="@form" render="projects" />
</h:selectOneListbox>

<h:panelGroup id="projects">
    <ul>
        <ui:repeat items="#{category.allItems}" var="o" id="itemTable">
            <li><h:graphicImage value="#{o.imageUrl}" id="itemImage" /></li>
            <li><h:outputText value="#{o.title}" /></li>
            <li><label>Price: $ </label><h:outputText value="#{o.price}" /></li>
        </ui:repeat>
    </ul>       
</h:panelGroup>

我的豆子是:

@ManagedBean(name = "category")
@SessionScoped
public class CategoryServiceBean extends BaseService implements Serializable {

    private static final long serialVersionUID = -12082902292711980L;    
    private Integer categoryId;
    private Integer parentCategoryId;
    private Integer locationId;

    @ManagedProperty(value="#{categorySupport}")
    private CategorySupport categorySupport;

    public List<RestCategory> getAllSubCategories() {
        return getCategorySupport().getCategoriesByParent(locationId, parentCategoryId);            
    }

    public List<RestItem> getAllItems() {
        return response = getCategorySupport().getCategoryItems( locationId, categoryId);               
    }

    // ...
}

我的问题是&lt;f:ajax execute="@form" render="projects" /&gt; 没有将值填充到&lt;h:panelGroup id="projects"&gt;。这是如何引起的,我该如何解决?如果我使用&lt;h:dataTable&gt; 而不是&lt;ui:repeat&gt;,那么它可以正常工作。

【问题讨论】:

  • 我建议您在您的 ajax 中使用侦听器,并在侦听器内部填充 allItems 中的适当值(将逻辑从侦听器代码中的 allItems getter 移动),然后尝试.. .
  • 如果您根本不使用Ajax4jsf,请不要标记[ajax4jsf]

标签: ajax jsf-2 uirepeat


【解决方案1】:
<ui:repeat items="#{category.allItems}" var="o" id="itemTable">

items 属性在 &lt;ui:repeat&gt; 中不存在。您显然将它与&lt;c:forEach&gt; 混淆了。使用value 属性。

<ui:repeat value="#{category.allItems}" var="o" id="itemTable">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-02
    • 1970-01-01
    • 2011-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多