如何根据条件使primefaces数据表列可编辑 [英] How to make a primefaces datatable column editable based on a condition

查看:53
本文介绍了如何根据条件使primefaces数据表列可编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 primefaces 数据表,其中包含一些可编辑的列.我想根据某些条件将其中一个可编辑列中的一个单元格设为不可编辑,例如,如果该列是颜色,则用户应该能够输入不同的颜色.但是,如果该行包含具有特定 id('*) 的另一列,则用户应该无法更新该单元格.

I have a primefaces datatable which has some editable columns. I want to make one of cell in one of the editable columns as non-editable based on some condition, e.g, If that column is color, user should be able to enter different colors. But if the row contains another column with a particular id('*), user should not be able to update that cell.

我尝试根据 inputText 中的条件添加禁用,如下所示.

I tried adding disabled based on the condition in the inputText as below.

<p:column  headerText="Color Choice"  >               
                 <p:cellEditor>
                     <f:facet name="output"><h:outputText value="#{row.color}" /></f:facet>
                     <f:facet name="input"><p:inputText id="colorchoice" value="#{row.color}" disabled ="#{row.id.contains('*')}"/></f:facet>     
                    </p:cellEditor>             
                </p:column>

这实际上限制了用户更改该特定单元格,但用户仍然可以单击并选择该单元格.我希望用户无法点击并选择它以获得更好的 UI 体验,

This actually restricts the user from changing that particular cell, but the user still can click and select the cell. I want the user not able to click and select it to have a better UI experience,

推荐答案

我认为你必须使用 rendered.我给你一个示例代码.您必须更改 rendered 代码.

I think you must use rendered. I give you a sample code. You must change the rendered code.

          <p:column  headerText="Color Choice"  >               
             <p:cellEditor rendered="#{row.color eq 'red'}">
                 <f:facet name="output"><h:outputText value="#{row.color}" /></f:facet>
                 <f:facet name="input"><p:inputText id="colorchoice" value="#{row.color}" /></f:facet>
             </p:cellEditor>
              <h:outputText rendered="#{row.color ne 'red'}" value="#{row.color}"/>
            </p:column>

您还可以在支持 bean 中创建一个方法,该方法可以决定是否要渲染某些内容.你可以用 rendered 渲染任何你想要的东西.

You can also make in the backing bean a method that can decide if you want to render something or not. And you can render what ever if you want with rendered.

 <p:dataTable id="cars1" var="car" value="#{somethingBean.cars1}" editable="true" style="margin-bottom:20px">
    <f:facet name="header">
        Row Editing
    </f:facet>

    <p:column headerText="Year" rendered = "#{somethingBean.renderMethod(car)}">
        <p:cellEditor >
            <f:facet name="output"><h:outputText value="#{car.year}" /></f:facet>
            <f:facet name="input"><p:inputText value="#{car.year}" style="width:100%" label="Year"/></f:facet>
        </p:cellEditor>
    </p:column>

    <p:column headerText="Year">
        <<h:outputText value="#{car.year}" />
    </p:column rendered = "#{somethingBean.renderMethod(car)}">


    <p:column style="width:35px">
        <p:rowEditor rendered = "#{somethingBean.renderMethod(car)}"/>
    </p:column>
</p:dataTable>

-----管理bean方法----

-----Managebean Method----

 public Boolean renderMethod(Car car) {

 if(car.color.equal("red")){
        return true;
    }else{
       return false;
    }
 }

这篇关于如何根据条件使primefaces数据表列可编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆