【问题标题】:JSF Ajax CommandButton different levelJSF Ajax CommandButton 不同级别
【发布时间】:2014-12-01 15:16:26
【问题描述】:

我有一个 ajax 请求,它向我输出一个数据表并形成每一行,我还想执行一个按钮。遗憾的是,没有调用任何事件,我认为这是因为第二个按钮与第一个搜索按钮处于不同的级别。 JSF 看起来像这样:

<h:from>
   <h:inputText id="search" 
                value="#{profileController.searchName}"/>
   <h:commandButton value="Search by name" 
                    action="#{profileController.searchProfileWithName(profileController.searchName)}">
      <f:ajax execute="search" 
              render="output">
      </f:ajax>
   </h:commandButton>

   <h:dataTable  id="output" 
                 value="#{profileController.searchResultList}" 
                 var="p">
                <h:column>
                    <f:facet name="header">Name</f:facet>
                    <h:outputText value="#{p.name}"/>
                </h:column>
                <h:column>
                    <f:facet name="header">Action</f:facet>
                    <h:commandButton value="Invite"
                                     action="#{trainingController.inviteProfile(p)}">
                                <f:ajax/>
                     </h:commandButton>
                </h:column>
   </h:dataTable
</h:form>

JSF 托管 Bean(requestScoped):

public String searchProfileWithName(String name) {
    searchResultList = profileBean.findProfilesWithName(name);
    return null;
}

ProfileBean(无状态):

public List<Profile> findProfilesWithName(String name) {
    Query query = em.createNamedQuery("findProfilesWithName");
    query.setParameter("name", "%" + name.replace(" ", "%") + "%");
    return query.getResultList();
}

有人对此有想法吗?

【问题讨论】:

  • 是的,我查过了。对我没有帮助
  • 如果currentTraining已经在backing bean中,你为什么要通过EL传递trainingController.currentTraining?为什么不直接从 backing bean 使用它并仅通过 p 呢?您还应该在此处发布您的支持 bean,以显示您如何填充该列表。 @Smutje 发布的列表中的某些东西 必须适用于您。该帖子涵盖了所有可能的内容。
  • 第一个问题:因为我想稍后在不同的培训中使用函数inviteProfile。见编辑
  • 您不能在@RequestScoped bean 中拥有searchResultList 并期望能够使用inviteProfile 对其进行操作。由于请求范围,数据将无法生存。您对inviteProfile 的解释没有意义:变量已经在支持bean 中,为什么要从EL 传递它?为什么不能重载方法并在视图中使用适当的方法?

标签: ajax jsf glassfish-4


【解决方案1】:

这个问题的答案是数据源。这是问题的链接:

h:commandButton not working inside h:dataTable

【讨论】:

    猜你喜欢
    • 2014-06-11
    • 1970-01-01
    • 2018-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-28
    相关资源
    最近更新 更多