1

I need to make a panelGrid (one of man that are populated from a list of objects) clickable, and then send the item associated with it to the backing bean.

My HTML so for:

<ui:repeat var="searchItem" value="#{bean.filteredSearchItems}" varStatus="searchResult">
    <h:panelGrid>
        <!-- I get some info here from the searchResult object -->
    </h:panelGrid>
    <f:ajax event="click" listener="{bean.clickFlight}" />
    <f:param name="lfi" value="#{searchResult.index}" />
</ui:repeat>

I know that (in my backing bean) I need a function called clickSearchItem() that can handle the ajax call, so to test all of this, I did the following in my backing bean:

public void clickFlight()
{
    HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
String lfi = req.getParameter("lfi");

if (lfi == null)
    log.info("LFI WAS RETURNED AS NULL :(");

    log.info("HOPEFULLY AN INDEX OF SOME SORT!: " + lfi);
}

Nothing is getting logged - the click doesn't register. Has anyone else had this problem? Does anyone know how to solve it?

4

1 回答 1

3

<f:ajax>需要嵌套到实现的组件中ClientBehaviorHolder。如果您打算为此使用<h:panelGrid>(生成 HTML <table>),那么您应该将 嵌套<f:ajax>在组件本身中。

<h:panelGrid>
    <f:ajax event="click" listener="{bean.clickFlight}" />

    <!-- I get some info here from the searchResult object -->
</h:panelGrid>

<f:param>仅由 和 的渲染<h:outputFormat>器识别<h:commandXxx>。如果您的目标是支持 EL 2.2 的 Servlet 3.0 兼容容器(Tomcat 7、Glassfish 3、JBoss 6/7 等),那么您可以将其作为方法参数传递:

<h:panelGrid>
    <f:ajax event="click" listener="{bean.clickFlight(searchResult.index)}" />

    <!-- I get some info here from the searchResult object -->
</h:panelGrid>

如果愿意,您甚至可以传递整个对象:

<h:panelGrid>
    <f:ajax event="click" listener="{bean.clickFlight(searchResult)}" />

    <!-- I get some info here from the searchResult object -->
</h:panelGrid>

如果您<f:param>本身需要,另一种选择是使用<h:commandLink>

<h:commandLink>
    <f:ajax event="click" listener="{bean.clickFlight(searchResult)}" />
    <f:param name="lfi" value="#{searchResult.index}" />

    <h:panelGroup>
        <!-- I get some info here from the searchResult object -->
    </h:panelGroup>
</h:commandLink>
于 2013-08-30T10:49:20.317 回答