从后台bean访问JSF组件标签的属性值 [英] Accessing JSF components tag attribute values from a backing bean

查看:214
本文介绍了从后台bean访问JSF组件标签的属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要访问组件标记属性,如:

 < H:inputText的ID =input_age />

从后台bean,如:

 公共类的UserInfo {
    串inputAgeId;
    公众的UserInfo(){
        inputAgeId = {code访问组件标签属性} .getStyleClass();
    }
}


解决方案

  UIViewRoot视图= FacesContext.getCurrentInstance()getViewRoot()。

您就可以使用<一个href=\"http://docs.oracle.com/javaee/6/api/javax/faces/component/UIComponent.html#findComponent%28java.lang.String%29\">view.find(\"component_id\")得到正确的组件。一旦你的组件,你可以使用<一个href=\"http://docs.oracle.com/javaee/6/api/javax/faces/component/UIComponent.html#getAttributes%28%29\">getAttributes()获得地图&LT;弦乐,对象&gt; 与组件的所有属性。

如果您正在访问总是相同的compent,您可以其绑定到后台bean 来代替。

I need to access a components tag attribute like:

<h:inputtext id="input_age/>

from a backing bean, like:

public class UserInfo{
    String inputAgeId;
    public UserInfo(){
        inputAgeId = {code to access component tag attribute}.getStyleClass();
    }
}

解决方案

UIViewRoot view = FacesContext.getCurrentInstance().getViewRoot();

You can then use view.find("component_id") to get the right component. Once you have the component, you can use getAttributes() to get a Map<String, Object> with all the attributes of the component.

If you are accessing always the same compent, you can bind it to the backing bean instead.

这篇关于从后台bean访问JSF组件标签的属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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