如何在jsf中的数据表中进行列级渲染? [英] How to do a column level render in datatable in jsf?

查看:116
本文介绍了如何在jsf中的数据表中进行列级渲染?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不使用ajax的情况下在jsf中的数据表中呈现列级?

How to do a column level render in datatable in jsf without using ajax?

例如,第一列具有下拉菜单选择。根据选择,我需要在第二栏中启用按钮。

For example, First column having a Drop down menu selection. Based on the selection, I need to enable button in the second column.

有人可以帮我这个忙吗?

Can any one help me on this.

推荐答案


  1. 如果使用列级渲染,则表示一种重新渲染表中的单个列,那么答案是-您不能。浏览器不允许这样做。您需要将每个td分别重新呈现在colimn中。

  1. If by "column level render" you mean "a way to rerender a single column in table" then the answer is - you can't. Browsers do not allow this. You would need to rerender each td in a colimn separately.

如果您只是想随时更改表的某些部分,则:

If you just mean "change some parts of the table on the fly", then:


  • 如果用 ajax表示 javascript,则-不能。您需要一些JavaScript才能执行此操作。

  • if by "ajax" you mean "javascript", then - you can't. You need quite some javascript to do this.

如果用 ajax表示连接服务器,则-您可以编写自己的Javascript

if by "ajax" you mean "connecting to the server", then - you can write your own Javascript to do the job on the client.

诀窍是-一旦开始使用javascript启用和禁用按钮,就必须走一路:不仅是在选择选项下拉列表更改时,而且在表格首次呈现时。如果不这样做,则必须在Java中以Java语言编写一个表示逻辑。

The trick is - once you start using the javascript to enable and disable buttons, you must go all the way: not only when an option is selected dropdown is changed, but also when the table is first rendered. If you don't, you will have to colliding pieces of presentation logic, on in Java, one in Javascript.

可以应用的有效Javascript解决方案示例到JSF输出将是:

An example of a working Javascript solution that could be applied to JSF output would be:

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'></script>
<table id='mytable'>
    <tr>
        <td><select>
                <option>A</option><option>B</option>

        </select></td>
        <td><input type='button' value='test'></td>
    </tr>
    <tr>
        <td><select>
                <option>A</option><option>B</option>

        </select></td>
        <td><input type='button' value='test'></td>
    </tr>
</table>
<script>
    function fix_table(){
        $('#mytable select').each(function(){
            $('input', this.parentNode.parentNode).attr('disabled',this.value=='B')
        })
    }

    fix_table();
    $('#mytable select').change(function(){fix_table()})
</script>

从下拉菜单中选择 B时,相关按钮将被禁用。

When you select "B" from a dropdown, the relevant button gets disabled.

我认为这是一个非常糟糕的解决方案。

In my opinion this is a very bad solution.

您应该使用JSF及其提供的工具(例如ajax标记) )或切换技术。混合技术会使它们成倍增加难度,而混合您并不是真正擅长的东西(由于您不得不问这个问题,您肯定不是),这会适得其反。

You should either use JSF and the tools it provides (like the ajax tag), or switch technology. Mixing technologies makes them exponentially harder, and mixing things you are not really good at (and since you had to ask the question - you are certainly not) will backfire.

这篇关于如何在jsf中的数据表中进行列级渲染?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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