0
votes

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 Map<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?

1
You need a converter for your object.Bhesh Gurung

1 Answers

0
votes

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}"/>