Using Collection to accept values of JSF form
I want to accept all values of a JSF form in a List. There might be varius tags such as inputText, selectOneMenu, inputTextArea etc. tags in the form. But my aim is to accept it to List of bean not to individual bean property for each tag. I can't decide how'll I write the List in bean so that it works as I want. I know that Java generic can be used but I don't know about it yet. Could anyone help me do this....either the way to accept values in List or in Java generic?
Thanks
# 2
Thanks....actually I've to do this because I'm not sure how many tags will be there during runtime as all these are in a datatable and appear based on values retrieved from database. I think it won't be clear to you before you see the code. The datatable code is as follows:
<t:dataTable styleClass="standardTable" headerClass="standardTable_Header" footerClass="standardTable_Header" rowClasses="standardTable_Row1,standardTable_Row2" columnClasses="standardTable_Column,standardTable_ColumnCentered,standardTable_Column" id="data" var="rmqc" value="#{rawmaterialqcdetails.allRMQCDetailByID}" preserveDataModel="true">
<h:column>
<f:facet name="header">
<h:outputText value="Test"/>
</f:facet>
<h:inputTextarea value="#{rmqc.test}" rows="6" cols="35" readonly="true"> </h:inputTextarea>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Specification"/>
</f:facet>
<h:inputTextarea value="#{rmqc.specification}" rows="6" cols="35" readonly="true"> </h:inputTextarea>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Result"/>
</f:facet>
<f:subview id="resultc" rendered="#{rmqc.result=='c'}">
<h:selectOneMenu id="comply" styleClass="selectOneMenu" value="#{rawmaterialqcdetails.testValueC}">
<f:selectItem itemLabel="" itemValue=""/>
<f:selectItem itemLabel="Complies" itemValue="Complies"/>
<f:selectItem itemLabel="Does not comply" itemValue="Does not comply"/>
</h:selectOneMenu>
<h:outputText value="Sampling Quantity:">
</h:outputText>
<h:inputText id="samplingQuantity" value="#{rawmaterialqcdetails.samplingQuantityC}" styleClass="textbox"></h:inputText>
<h:commandLink action="#{rawmaterialqcdetails.addTestValueC}">
<h:outputText value="Ok"/>
<f:param name="ID" value="#{rmqc.ID}"/>
<f:param name="RMID" value="#{rmqc.RMID}"/>
</h:commandLink>
</f:subview>
<f:subview id="resulti" rendered="#{rmqc.result=='i'}">
<h:inputText id="input" size="20" styleClass="textbox" value="#{rawmaterialqcdetails.testValueI}"/>
<h:outputText value="Sampling Quantity:">
</h:outputText>
<h:inputText id="samplingQuantity" value="#{rawmaterialqcdetails.samplingQuantityI}" styleClass="textbox"></h:inputText>
<h:commandLink action="#{rawmaterialqcdetails.addTestValueI}">
<h:outputText value="Ok"/>
<f:param name="ID" value="#{rmqc.ID}"/>
<f:param name="RMID" value="#{rmqc.RMID}"/>
</h:commandLink>
</f:subview>
</h:column>
</t:dataTable>
Look in the selectOneMenu tag with id=="comply" value is taken in rawmaterialqcdetails.testValueC bean property. This selectOnemenu tag may appear more than once on the form based on value from database which is decided in subview with id="resultc". Please note that in the subview rendered portion where I check rmqc.result=='c'. Now the selectOneMenu tag may appear several times based on rendering rmqc.result=='c'. But the value of this selectOneMenu tag is always taken in a single bean property rawmaterialqcdetails.testValueC.
This way there's an inputText tag with id samplingQuantity whose value is taken in rawmaterialqcdetails.samplingQuantityC bean property. The scenario is the same as selectOneMenu tag for this. When I click on the commandLink the action rawmaterialqcdetails.addTestValueC saves value to database. Now the problem is when these selectOneMenu and inputText tags appear more than once on form, the values are not accepted in rawmaterialqcdetails.testValueC and
rawmaterialqcdetails.samplingQuantityC bean properties and I can't send these to database.
There's one more subview with id="resulti" where the case is the same. This is why I want to collect all values accepted from form to List and then send all those to database. Do you have any idea how can I get around this?
Thanks