Reputation: 2195
I want to pass value in the input box to the ajax listener. Please refer following code.
JSF :
<h:dataTable id="cleanerAttendance" value="#{bean.objMap.entrySet().toArray()}">
<h:column>
<f:facet name="header">
<div>Attendance</div>
</f:facet>
<div>
<h:inputText value="entry.value">
<f:ajax execute="@this" listener="#{bean.updateMap(entry)}"/>
</h:inputText>
</div>
</h:column>
</h:dataTable>
Bean :
private Map<Obj2,Integer> objMap = new HashMap<Obj2,Integer>();
public void updateMap(Entry<Obj2,Integer> entry){
System.out.println(entry.getValue());
objMap.put(entry.getKey(), entry.getValue());
}
I want to update objMap when input value changed. But when I run this, updateMap method get called. But entry.getValue()
print as null
. Does anyone know why it is not working and correct way to do this?
I have already checked following answers and it was not worked for me.
Pass h:inputText value to f:ajax listener
How to pass parameter to f:ajax in h:inputText? f:param does not work
Upvotes: 1
Views: 1411
Reputation: 31649
I would do it other way. First provide a getter for the Map:
public Map<Obj2,Integer> getObjMap(){
return objMap;
}
Then iterate over the keys and set the value based in the key you're interested in:
<h:dataTable id="cleanerAttendance" value="#{bean.objMap.keySet().toArray()}" var="obj">
<h:column>
<f:facet name="header">
<div>Attendance</div>
</f:facet>
<div>
<h:inputText value="#{bean.objMap[obj]}">
<f:ajax execute="@this" />
</h:inputText>
</div>
</h:column>
</h:dataTable>
This will basically invoke the model update once each of the ajax binded event happens, no listener needed. Haven't tested it myself, so give it a try!
See also:
Upvotes: 1