首页 \ 问答 \ 初始化primefaces数据表rowkey(Initializing primefaces datatable rowkey)

初始化primefaces数据表rowkey(Initializing primefaces datatable rowkey)

我有一个primefaces数据表,一旦用户点击搜索按钮,我就会在ArrayList中填充对象的属性。 我需要添加一个带有单选按钮的列,以便用户可以选择要更新的表的一行。 我想将rowkey设置为我的对象的metadataKey属性,但是我收到以下错误:

rowKey =“#{result.metadataKey}”:在类型java.lang.String上找不到属性'metadataKey'

我认为这是由表格呈现时不存在的metadataKey引起的。 为了解决这个问题,我将表设置为仅在用户完成搜索后呈现,但这导致了相同的错误。

这是相关的html:

<h:form id="dataForm">
    <p:panel styleClass="centered">
        <p:messages id="message" showDetails="true" autoUpdate="true" />
        <p:outputLabel id="searchLabel" value="Search for Metadata:  " />&nbsp;&nbsp;&nbsp;
                <p:inputText id="search"
            value="#{updateMetadataItemsBean.searchTerm}" />&nbsp;&nbsp;&nbsp;
                <p:commandButton id="searchButton" value="Search" 
            action="#{updateMetadataItemsBean.search}"
            update="dataForm:metadataitems, message, dataForm:dataPanel" />
        <br />
        <br />
        <br />
    </p:panel>
    <p:panel styleClass="center" id="dataPanel" >
        <p:dataTable id="metadataitems" var="result"
            value="#{updateMetadataItemsBean.results}" styleClass="center"
            resizableColumns="true"
            selection="updateMetadataItemsBean.selectedMetadataItem"
            rowKey="#{result.metadataKey}" rendered="#{updateMetadataItemsBean.show}">              
            <p:column headerText="Select Item to Update" selectionMode="single"></p:column>
            <p:column headerText="Metadata Key">
                <h:outputText value="#{result.metadataKey}" />
            </p:column>
            <p:column headerText="Map Name">
                <h:outputText value="#{result.mapName}" />
            </p:column>
            <p:column headerText="Metadata Name">
                <h:outputText value="#{result.metadataName}" />
            </p:column>
            <p:column headerText="Metadata Value">
                <h:outputText value="#{result.metadataValue}" />
            </p:column>
            <p:column headerText="WTX Adapter">
                <h:outputText value="#{result.wtxAdapter}" />
            </p:column>
            <p:column headerText="Card Number">
                <h:outputText value="#{result.cardNumber}" />
            </p:column>
            <p:column headerText="Create Date TS">
                <h:outputText value="#{result.createDateTS}" />
            </p:column>
        </p:dataTable>
        <br />
        <br />
        <br />
    </p:panel>

这是来自bean的相关代码:

public class UpdateMetadataItemsBean implements Serializable{
public static final long serialVersionUID = 4;
private String metadataKey;
private String mapName;
private String metadataName;
private String metadataValue;
private String wtxAdapter;
private String cardNumber;
private String createDateTS;
private String searchTerm;
private String selectedDataKey;
private boolean show = false;
private MetadataItems selectedMetadataItem;
private ArrayList<MetadataItems> results = new ArrayList<MetadataItems>();

[getters and setters]

public void search() {
    Search s = new Search();
    setResults(s.search(searchTerm));

    setShow(true);
}

提前感谢任何能指出我正确方向的人。


I have a primefaces datatable that I'm populating with properties of objects in an ArrayList once the user clicks a search button. I need to add a column with a radio button so that the user can select a row of the table to update. I'd like to set the rowkey to be the metadataKey property of my objects, but I get the following error:

rowKey="#{result.metadataKey}": Property 'metadataKey' not found on type java.lang.String

I believed that this was caused by the metadataKey not existing at the time the table is rendered. To remedy it, I set the table to render only after the user had completed their search, but this resulted in the same error.

Here is the relevant html:

<h:form id="dataForm">
    <p:panel styleClass="centered">
        <p:messages id="message" showDetails="true" autoUpdate="true" />
        <p:outputLabel id="searchLabel" value="Search for Metadata:  " />&nbsp;&nbsp;&nbsp;
                <p:inputText id="search"
            value="#{updateMetadataItemsBean.searchTerm}" />&nbsp;&nbsp;&nbsp;
                <p:commandButton id="searchButton" value="Search" 
            action="#{updateMetadataItemsBean.search}"
            update="dataForm:metadataitems, message, dataForm:dataPanel" />
        <br />
        <br />
        <br />
    </p:panel>
    <p:panel styleClass="center" id="dataPanel" >
        <p:dataTable id="metadataitems" var="result"
            value="#{updateMetadataItemsBean.results}" styleClass="center"
            resizableColumns="true"
            selection="updateMetadataItemsBean.selectedMetadataItem"
            rowKey="#{result.metadataKey}" rendered="#{updateMetadataItemsBean.show}">              
            <p:column headerText="Select Item to Update" selectionMode="single"></p:column>
            <p:column headerText="Metadata Key">
                <h:outputText value="#{result.metadataKey}" />
            </p:column>
            <p:column headerText="Map Name">
                <h:outputText value="#{result.mapName}" />
            </p:column>
            <p:column headerText="Metadata Name">
                <h:outputText value="#{result.metadataName}" />
            </p:column>
            <p:column headerText="Metadata Value">
                <h:outputText value="#{result.metadataValue}" />
            </p:column>
            <p:column headerText="WTX Adapter">
                <h:outputText value="#{result.wtxAdapter}" />
            </p:column>
            <p:column headerText="Card Number">
                <h:outputText value="#{result.cardNumber}" />
            </p:column>
            <p:column headerText="Create Date TS">
                <h:outputText value="#{result.createDateTS}" />
            </p:column>
        </p:dataTable>
        <br />
        <br />
        <br />
    </p:panel>

This is the relevant code from the bean:

public class UpdateMetadataItemsBean implements Serializable{
public static final long serialVersionUID = 4;
private String metadataKey;
private String mapName;
private String metadataName;
private String metadataValue;
private String wtxAdapter;
private String cardNumber;
private String createDateTS;
private String searchTerm;
private String selectedDataKey;
private boolean show = false;
private MetadataItems selectedMetadataItem;
private ArrayList<MetadataItems> results = new ArrayList<MetadataItems>();

[getters and setters]

public void search() {
    Search s = new Search();
    setResults(s.search(searchTerm));

    setShow(true);
}

Thanks in advance to anyone who can point me in the right direction.


原文:https://stackoverflow.com/questions/31052647
更新时间:2024-03-18 19:03

最满意答案

尝试

var result = 0;
(function (i, callback) {
    if (i > 0) {
        result = result + i;
        i = i - 1;
        var callee = arguments.callee;
        setTimeout(function () {
            callee(i, callback)
        }, 100);
    } else if (i == 0) {
        callback();
    }
}(10, function () {
    alert(result);
}));

演示: 小提琴

为什么?
您的方法存在多个问题

  1. setTimeout是async意味着你的警报会在加法操作完成之前被触发 - 解决方案是使用一个回调方法,一旦添加结束就会执行,如上所示
  2. 当你将一个字符串传递给setTimeout ,它将在全局范围内执行,即arguments.callee将引用一个与你期望的不同的对象。

Try

var result = 0;
(function (i, callback) {
    if (i > 0) {
        result = result + i;
        i = i - 1;
        var callee = arguments.callee;
        setTimeout(function () {
            callee(i, callback)
        }, 100);
    } else if (i == 0) {
        callback();
    }
}(10, function () {
    alert(result);
}));

Demo: Fiddle

Why?
There are multiple problems in your approach

  1. setTimeout is async meaning your alert will get triggered before addition operations are completed - a solution is to use a callback method which will get executed once the additions are over as shown above
  2. when you pass a string to setTimeout it will get executed in the global scope, ie the arguments.callee will refer to a different object than what you will expect.

相关问答

更多
  • 您无法将数据从“超时”功能返回到otherFunction 。 如果我理解你想要什么,你似乎运气不好。 You can't return data from the "timed-out" function to otherFunction. If I understood what you want correctly, you seem to be out of luck.
  • 这里有几个问题。 首先,您在匿名函数中定义代码。 这个结构: (function() { ... )(); 做两件事 它定义一个匿名函数并调用它。 有范围的理由这样做,但我不知道这是你真正想要的。 你正在传递一个代码块到setTimeout() 。 问题是当这样执行时, update()不在范围内。 然而,如果你传递一个函数指针,所以这样做: (function() { $(document).ready(function() {update();}); function update() ...
  • 那是因为你在第一个setTimeout离开了当前的网页。 这不是由setTimeout函数引起的,而是由您离开页面引起的。 Location.assign()方法使窗口加载并显示URL参数的页面。 这基本上意味着,当您触发window.location.assign('url') ,您强制页面重新加载。 这会阻止处理任何其他代码行。 你可能也想要 a)发出ajax请求以初始化您的身份验证过程 b)使用传统的回发请求在会话中存储第一个url请求的状态。 然后,工作流中访问的第二个页面将具有适当的凭据。 Tha ...
  • “我试图让setTimeout每2秒调用一次'poll'函数,它不是” .setTimeout()方法在指定的延迟后调用一次只传递一次的函数。 .setInterval()方法调用您重复传递它的函数,并在每次调用之间指定延迟。 从更新到你的问题,你似乎认为他们都做同样的事情。 请阅读我链接到的doco。 请注意,你必须传递一个函数引用(或者一个字符串来被评估),所以说: setInterval(poll, 2000); // NOT setInterval(poll(), 2000); 后者不应该工作,因 ...
  • 尝试 var result = 0; (function (i, callback) { if (i > 0) { result = result + i; i = i - 1; var callee = arguments.callee; setTimeout(function () { callee(i, callback) }, 100); } else if (i == 0) { ...
  • 尝试使用jQuery版本3.0 .animate() ,它现在使用requestAnimationFrame // Creates a jQ object where elem set to index of [0] // a plain object with value of 0 `{to:0}` // call .animate() chained to the jQ object // Animates `{to:0}` value from 0 - 1 // $({to ...
  • 它适用于我将updateAllClients()放入io.on('connection'...)函数内时的情况,如下所示: function updateAllClients() { io.socket.emit('update', {x:x, y:y}); x++; y++; setTimeout(updateAllClients, 100); } io.sockets.on('connection', function (socket) { updateAllC ...
  • 您需要阻止执行其余代码,实际上您在清除setTimeout后重新声明了t 。 小提琴 var c = 0; var t; function timedCount() { document.getElementById('txt').value = c; c = c + 1; if (c == 5) { clearTimeout(t); return false; } t = setTimeout(timedCount, 1000); ...
  • 这似乎解决了这个问题。 演示: 改变这一行: if(order_index[order_index[parent_id]]) 至: if( order_index[parent_id] ) This seems to fix it. Demo: Change this line: if(order_index[order_index[parent_id]]) to: if( order_index[parent_id] )
  • 如果我明白 - 锁定开关时,它完成解锁后: var lock = 0; function Switch() { if(lock == 0) { lock = 1; if(videoNieuw.className == "show"){ playNoise(1280, 720); btnswitch.className="controls now"; setTimeo ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)