当前位置 博文首页 > 适己而忘人者,人之所弃;克己而立人者,众之所戴。:JSF学习(

    适己而忘人者,人之所弃;克己而立人者,众之所戴。:JSF学习(

    作者:[db:作者] 时间:2021-07-11 12:31

    最近开始学习JSF基础,发现比较重要的一点,就是如何用编程方式访问托管Bean。看了一些JSF的实例,不过大多都是用JSF1.1来实现的。虽然在JSF1.2的环境中也可以很好运行,但是在编译的时候会看到降级的消息。这里找了一些资料总结一下JSF1.1和JSF1.2访问托管Bean的方法。

    一、从JSF页面传递参数给托管Bean
    虽然利用h:commandLink 和h:commandButton组件,可以通过action和actionListener来触发托管Bean中的方法,但是不能向这些方法中传递参数。对于动态传递参数,不是不可以实现,这点可以通过使用f:attribute来实现。而且f:attribute也可以很好的和actionListener联合使用。
    例子:

    < h:commandLink?actionListener = " #{myBean.action} " >
    ????????
    < f:attribute?name = " attrname1 " ?value = " attrvalue1 " ? />
    ????????
    < f:attribute?name = " attrname2 " ?value = " attrvalue2 " ? />
    ????????...???
    ????????
    < h:outputText?value = " Click?here " ? />
    ????
    </ h:commandLink >
    ????
    ????
    < h:commandButton?value = " Press?here " ?actionListener = " #{myBean.action} " >
    ????????
    < f:attribute?name = " attrname1 " ?value = " attrvalue1 " ? />
    ????????
    < f:attribute?name = " attrname2 " ?value = " attrvalue2 " ? />
    ????????...
    ????
    </ h:commandButton >cs