使用表单中的数据动态更新a4j:repeat [英] Dynamically updating a4j:repeat using data from form

查看:158
本文介绍了使用表单中的数据动态更新a4j:repeat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,用户可以在其中将文件上传到服务器.他可以设置哪些组/用户可以读取/写入文件.

I have a page where the user can upload a file to the server. He can set which groups/users can read/write (to) the file.

这是通过选择来完成的.一个选择保存用户当前所在的组的名称,同一行上是一个带有读取"和写入"选项的选择.第二行是用于选择用户的相应内容.

This is done by selects. One select holds the names of the groups the user is currently in, and on the same row is a select with options Read and Write. On the second row is the corresponding stuff for selecting users.

当用户选择一个组并对该组进行读取"或写入"时,然后按下按钮.按下按钮后,我想向用户显示选择项下方的权限列表.该列表将具有一个组名,该组的访问设置以及一个删除权限项的按钮.

When the user selects a group and either Read or Write for said group, he then presses a button. After pressing the button I would like to show the user a list of permissions below the select. The list would have a group name, access setting for said group and a button to remove the permission item.

我的问题是,我无法更新页面并显示权限列表.服务器端将权限添加到ArrayList中,但是我无法将内容显示在a4j:repeat中.如何获取重复标签?

My problem is, I'm not able to update the page and show the list of permissions. Server side the permissions are added to an ArrayList, but I can't get the contents to show in a4j:repeat. How can I get the repeat tag to update?

这是到目前为止我一直在尝试的事情:

Here is what I've been trying to do so far:

        <h:form>
        <h:selectOneMenu value="#{assetUploadForm.currentGroupName}" valueChangeListener="#{assetUploadForm.groupNameChanged}">
            <f:selectItem itemValue="users" itemLabel="users" />
            <f:selectItem itemValue="foobar" itemLabel="Foobar" />
            <a4j:ajax event="valueChange" render="second" execute="@this" />
        </h:selectOneMenu>

        <h:selectOneMenu value="#{assetUploadForm.currentGroupRW}" valueChangeListener="#{assetUploadForm.groupRWChanged}">
            <f:selectItem itemValue="R" itemLabel="Read"/>
            <f:selectItem itemValue="W" itemLabel="Write"/>
            <a4j:ajax event="valueChange" render="second" execute="@this" />
         </h:selectOneMenu>

        <a4j:commandButton action="#{assetUploadForm.addGroupRights}" value="add group" render="groupList"/>
        <ul>
        <a4j:repeat value="#{assetUploadForm.groupPermissions}" var="permission" id="groupList">
            <li><h:outputText value="#{permission.permissionSetItemId}"/></li>
        </a4j:repeat> 
        </ul>
        </h:form>

因此,问题是a4j:repeat从未更新.如果我将重复重复替换为输出文本,并设置命令按钮以呈现它,则页面将正确"更新.

So, the problem is a4j:repeat is never updated. If I replace the repeat with an outputtext, and set the commandbutton to render it, the page is updated "correctly".

推荐答案

<a4j:repeat>不会向响应呈现任何HTML.但是,<a4j:ajax>render属性需要一个具有该ID的组件,该组件实际存在于HTML DOM树中(即使用JavaScript document.getElementById()填充物在后台获取需要在ajax响应后进行更新的元素)已返回).因此,与<a4j:repeat>结合使用是不可能的.您需要指定其最父级的JSF HTML组件,或者至少将其包装到新组件中.

The <a4j:repeat> does not render any HTML to the response. The render attribute of <a4j:ajax> however expects a component with that ID being physically present in the HTML DOM tree (it is namely behind the scenes using JavaScript document.getElementById() stuff to get the element which needs to be updated after the ajax response has returned). This is thus not possible in combination with <a4j:repeat>. You would need to specify its parentmost JSF HTML component instead, or at least to wrap it in a new one.

例如

<a4j:commandButton action="#{assetUploadForm.addGroupRights}" value="add group" render="groupList"/>
<h:panelGroup id="groupList">
  <ul>
    <a4j:repeat value="#{assetUploadForm.groupPermissions}" var="permission">
      <li><h:outputText value="#{permission.permissionSetItemId}"/></li>
    </a4j:repeat> 
  </ul>
</h:panelGroup>

作为另一种选择,您也可以只使用

As a different alternative, you can also just use the <rich:list> component instead which renders the complete <ul><li> for you already. You're then basically updating the <ul> directly.

<a4j:commandButton action="#{assetUploadForm.addGroupRights}" value="add group" render="groupList"/>
<rich:list id="groupList">
  <h:outputText value="#{permission.permissionSetItemId}"/>
</rich:list>

要了解所有可用组件以及如何使用它们,请在展示站点和组件参考.

To learn about which components all are available and how to use them, peek around in the showcase site and the component reference.

这篇关于使用表单中的数据动态更新a4j:repeat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆