PrimeFaces AutoComplete完成,并具有额外的参数

发布于 2025-01-27 14:12:39 字数 497 浏览 3 评论 0原文

我在使用完成的数据台上具有自动完成的数据。是否可以将行对象传递到完成的bean实现,或者以某种方式让bean知道我当前正在工作的行对象?谢谢。

伪代码:

<p:dataTable var="selection" value="#{bean.selections}">
    <p:column headerText="Selection">
        <p:autoComplete id="dd" dropdown="true" value="#{bean.country}"
                        completeMethod="#{bean.completeText(selection)}"> 
            <p:ajax event="itemSelect"/>
        </p:autoComplete>
    </p:column>
</p:dataTable>

I have autoComplete inside dataTable which is using completeMethod. Is it possible to pass row object to the completeMethod bean implementation or somehow let the bean know on which row object I am currently working? Thank you.

Pseudo code:

<p:dataTable var="selection" value="#{bean.selections}">
    <p:column headerText="Selection">
        <p:autoComplete id="dd" dropdown="true" value="#{bean.country}"
                        completeMethod="#{bean.completeText(selection)}"> 
            <p:ajax event="itemSelect"/>
        </p:autoComplete>
    </p:column>
</p:dataTable>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

山田美奈子 2025-02-03 14:12:39

橡皮鸭效应,很抱歉这么快回答我自己的问题。我已经将完成对象移到了选择对象上,在我的情况下,我需要所有需要的其他参数。希望有人发现它有用。

<p:dataTable var="selection" value="#{bean.selections}">
    <p:column headerText="Selection">
        <p:autoComplete id="dd" dropdown="true" value="#{bean.country}"
                        completeMethod="#{selection.completeText}">
            <p:ajax event="itemSelect"/>
        </p:autoComplete>
    </p:column>
</p:dataTable>

Rubber duck effect, sorry for answering my own question so fast. I have moved my completeMethod to selection object, which in my case holds all the additional parameters I need. Hope someone finds it useful.

<p:dataTable var="selection" value="#{bean.selections}">
    <p:column headerText="Selection">
        <p:autoComplete id="dd" dropdown="true" value="#{bean.country}"
                        completeMethod="#{selection.completeText}">
            <p:ajax event="itemSelect"/>
        </p:autoComplete>
    </p:column>
</p:dataTable>
终遇你 2025-02-03 14:12:39

您可以将命令 / ajax组件中的属性传递给您的操作 /侦听器方法,例如:

<p:autoComplete>
    <f:attribute name="foo" value="#{bean.foo}"/>`
</p:autoComplete>

在您的bean方法中,您可以访问属性,例如:

FacesContext = FacesContext.getCurrentInstance();
final UIComponent component = UIComponent.getCurrentComponent(context);

Object foo = component.getAttributes().get("foo");

根据您的要求,您可以直接传递行var实例,或者只是“ ID / ROWKEY”和手动查找。

You can pass attributes in command / ajax components to your action / listener method like:

<p:autoComplete>
    <f:attribute name="foo" value="#{bean.foo}"/>`
</p:autoComplete>

In your bean method you can access attributes like:

FacesContext = FacesContext.getCurrentInstance();
final UIComponent component = UIComponent.getCurrentComponent(context);

Object foo = component.getAttributes().get("foo");

Depending on your requirement you can either pass the row var instance directly or maybe just the "id / rowkey" and look it up manually.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文