How to do a column level render in datatable in jsf?

本小妞迷上赌 提交于 2020-01-06 08:16:16

问题


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:


  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.

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

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

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

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.

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>

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

In my opinion this is a very bad solution.

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.



来源:https://stackoverflow.com/questions/6706849/how-to-do-a-column-level-render-in-datatable-in-jsf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!