weixin_33690963 2016-09-08 20:17 采纳率: 0%
浏览 31

Ajax请求和属性

I am trying this tutorial which describes how to set attributes into server call and how to analyse the attributes on backing bean;

<h:commandButton id="submit" 
actionListener="#{userData.attributeListener}" action="result"> 
   <f:attribute name="value" value="Show Message" />                
   <f:attribute name="username" value="JSF 2.0 User" />
</h:commandButton>

I googled a lot but most examples show how to set attrs for synch-ed calls not the asynch-ed ones :S So my question is ... how to send attributes on server if that would be the ajax call and how to get them on backing bean (see suggestion A code snippet)?

suggestion A :

<h:commandButton id="submit" 
    actionListener="#{userData.attributeListener}" action="result"> 
       <f:ajax>
            <f:attribute/>? how to
       </f:ajax>

    </h:commandButton>

and if there is a good tutorial concerning to this question please do share the link :)

Thanks

  • 写回答

2条回答 默认 最新

  • weixin_33708432 2016-09-15 22:00
    关注

    OK I just wrote a test which sets attributes out the ajax block as :

    <h:commandButton id="submit" 
        actionListener="#{userData.callWithAttributes}" action="result"> 
           <f:attribute name="a" value="#{testa}"/>
           <f:attribute name="b" value="#{testb}"/>
           <f:ajax .../>
    </h:commandButton>
    

    ...and on the backing bean

    ...
    public void callWithAttributes(ActionEvent e){
      String a=(String) e.getComponent().getAttributes().get("a");
      ...
    }
    ...
    

    Seems like it's working fine :) So attributes should be placed into event-making component block - the h:commandButton in this particular case...

    评论

报告相同问题?

悬赏问题

  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码