开发者

How to do a column level render in datatable in 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 colu开发者_如何学Pythonmn.

Can any one help me on this.


  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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜