开发者

How to bind h:inputText value to custom object

I'm using JSF 2.0 (JEE6, Glassfish 3.1) and stuck with such problem:

I want to bind my h:inputTexts values not just by a simple String or Integer but my object:

public class IDX {

int d;
int k;
int w;

IDX(int d, int k, int w) {
    this.d = d;
    this.k = k;
    this.w = w;
}

//getters&setters
...

In managed bean I have:

private Ma开发者_JS百科p<IDX, Object> values; //with getters&setters

which is constructed as a HashMap. Now I would like from my JSF page to bind h:inputText value to an object IDX, something like this:

....
<h:form>
   ....
   <h:inputText value="#{myBean.values[1,1,1]}" />
   ....
</h:form>
....

which obviously doesn't look good. Any ideas? Is it possible or I have to use Strings or Integers only?


If you are trying to bind Idx instance to h:inputText your managed bean should look as follows-

@ManagedBean
public class MyBean {
    private Idx idx; //getter/setter

You are gonna need a converter for Idx that converts an instance of Idx to (and from) String. Something as follows -

@FacesConverter(forClass=Idx.class)
public class IdxConverter implements Converter {
    public String getAsString(...//provide implementation
    public Object getAsObject(...//provide implementation

And in the page -

<h:inputText value="#{myBean.idx}"/>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜