-
1. Re: Can I bind form controls to hashtable like a pojo?
stefans Mar 5, 2008 8:51 AM (in response to luxspes)hi
yes, it is possible to use a HashMap (or afaik any type of Map) to dynamically map values to your JSF controls. I did it like this:
In the Bean I defined a HashMap like this (including getter/setter)
private Map<String, Object> valueMap = new HashMap<String, Object>();
the EL binding then looks like this:
#{BeanName.valueMap['keyString']}
you can also take this further and access a specific property of an POJO within the Map... e.g.:
#{BeanName.valueMap['keyString'].property}
cheers
Stefan -
2. Re: Can I bind form controls to hashtable like a pojo?
asavitsky Mar 5, 2008 3:21 PM (in response to luxspes)Or even
#{BeanName.valueMap.keyString.property}
should do, as long as the keyString doesn't have any spaces/dots/any other funky chars...
-
3. Re: Can I bind form controls to hashtable like a pojo?
franciscoperedo Mar 5, 2008 9:27 PM (in response to luxspes)Hi! Thanks for answering!
Your answer is is almost what I am looking for... but...
I am hitting a big wall here... the keyString in#{BeanName.valueMap['keyString']}
needs to be a variable!The thing is i am
painting
an input text for each dynamic field using a repeater... but now.. to bind that with the HashMap, I need to bind each input with a different key in the hashmap... and I can not find the way to do it!!!Regards,
-
4. Re: Can I bind form controls to hashtable like a pojo?
keithnaas Mar 5, 2008 9:45 PM (in response to luxspes)Can you post your xhtml?
-
5. Re: Can I bind form controls to hashtable like a pojo?
franciscoperedo Mar 5, 2008 10:19 PM (in response to luxspes)Hi! thanks!
Here it is (I basically read de structure of the form some
tables in the database, and create it ):<h:form> <a:repeat value="#{inventario.plantilla.clasificacionCamposList}" var="clasificacion"> <rich:panel> <f:facet name="header">#{clasificacion.nombre}</f:facet> <a:repeat value="#{clasificacion.camposList}" var="campo"> <s:decorate template="../layout/edit.xhtml"> <ui:define name="label">#{campo.nombre}</ui:define> <h:selectOneMenu rendered="#{not empty campo.caracteristicaList}"> <s:selectItems value="#{campo.caracteristicaList}" var="caracteristica" label="#{caracteristica.nombre}"> </s:selectItems> <s:convertEntity/> </h:selectOneMenu> <h:inputText rendered="#{empty campo.caracteristicaList}"></h:inputText> </s:decorate> </a:repeat> <br/> <br/> </rich:panel> <br/> </a:repeat> </h:form>
Any hints?
-
6. Re: Can I bind form controls to hashtable like a pojo?
luxspes Mar 6, 2008 3:23 AM (in response to luxspes)Here is a simplified version:
<a:repeat value="#{controller.fieldList}" var="field"> <h:outputText value="#{field.name}"/> <h:inputText/> </s:decorate> </a:repeat>
How do I bind this dynamically generated inputTexts to a HashMap using the field.name? I mean, AFAIK this will not work:
<a:repeat value="#{controller.fieldList}" var="field"> <h:outputText value="#{field.name}"/> <h:inputText #{controller.valueMap[field]}/> </s:decorate> </a:repeat>
Any hints?
-
7. Re: Can I bind form controls to hashtable like a pojo?
franciscoperedo Mar 6, 2008 4:29 PM (in response to luxspes)Hi!
My mistake, the code in my controller had an error, the following works:<a:repeat value="#{controller.fieldList}" var="field"> <h:outputText value="#{field.name}"/> <h:inputText #{controller.valueMap[field]}/> </s:decorate> </a:repeat>
Thanks! Seam is great!
Regards