我正在使用Primefaces重写(非常大的)旧的Richfaces应用程序.我现在遇到一种情况,我得到两个列表,一个带有列名,一个带有应该表示为行的对象.
I'm in the process of rewriting a (very) big and old Richfaces application using Primefaces. I now have a situation where I get two lists, one with column names and one with objects that should be represented as rows.
对象看起来像这样:
public class AVeryGenericThingThatIDoNotLike { Object[] values; //Other parameters that I dont care about }当我应该显示此内容时,我希望它将values [0]映射到第一列,values [1]映射到第二列,依此类推.
When I should display this I want it to map values[0] to the first column, values[1] to the second and so forth.
我已经看了primefaces展示,并且有一个动态列的示例,但是我尝试过,但是当我不知道可以存在哪些列时,我无法使它工作.我不知道这一点的原因是,这些列是从一个包含行的数据库中决定的,该行会说应该存在哪些列,并且可以更改,因此,我无法像展示示例中那样构建一个类来使所有列都可用
I have looked at the primefaces showcase and there is an example of dynamic columns but I have tried that and I can not get it to work when I do not know what columns that can exist. The reason that I do not know this is that the columns are decided from a database that holds a row saying what columns that should exist and this can change, so I can not build a class to have all the columns available like in the showcase example.
有人可以在这里给我指点吗?我已经坚持了几天,我真的需要帮助.
Can anyone give me any pointers here? I've been stuck on this for a few days and I really need help.
现在,它可以与Laabidi Raissi的解决方案一起使用.我现在的问题是,对于某些列,我希望呈现按钮和命令链接.通过这种方法,我只能获取字符串,并且如果我尝试返回诸如CommandButtons之类的对象,它将仅打印Java对象哈希.
Now it is kinda working with the solution from Laabidi Raissi. My problem now is that for some columns I want to have buttons being rendered and command links. With this approach I am only able to get strings and if I try to return objects like CommandButtons it will just print a java object hash.
推荐答案如果您使用的是JSF2,那么我认为该解决方案可能对您有用.首先,在您的托管bean中,从数据库(动态)构建列列表,然后:
If you are using JSF2, then I think this solution may work for you. First, in your managed bean, you build your list of columns (dynamically) from DB, and then:
<p:columns value="#{yourManagedBean.listOfColumnsFromDB}" var="column" columnIndexVar="colIndex"> <f:facet name="header"> #{column}</f:facet> <h:outputText value="#{yourManagedBean.values[colIndex]}" /> </p:columns>根据您的评论,我认为添加commandbutton或outputlink非常明显(而不是outputText):
Base on your comment, I think adding commandbutton or outputlink is very obvious (instead of the outputText):
<h:commandButton value="#{yourManagedBean.values[colIndex]}" action="#{yourManagedBean.someActionThatTakesAParam(colIndex)}" rendered="#{colIndex == 4}"/>假设您希望在第5列中使用commandButton.
Supposing you want commandButton in column 5.
您正在寻找什么吗?
希望这会有所帮助
更多推荐
Primefaces动态列,以编程方式
发布评论