value of h:inputText is not applied to the bean on click of
starfish0r Nov 27, 2008 8:01 AMI am relatively new to richfaces (2 months) and I'm having problems with this for a while now.
For a long time, i didnt even get the commandLink to trigger its action in the bean, but after some random changes of the components at least this works now.
Short Description:
My goal is to display a rich:dataTable which is completely dynamic. All the data (the column names, column description) comes from the DB via iBatis. This part works just fine (after a lot of anger+agression).
Now, of course, i want to have the standard CRUD-stuff. the 'R' already works, as i mentioned. I am working on the 'U', so i can update a single Row of the table via a rich:modalPanel which pops up, shows input fields for every column (dynamically) with the current data that it contains.
Since the number of columns of the table is dynamic, i cannot work with classes and particular properties such as #{row.firstname} (which i would need getFirstname() and setFirstname(String) for). Instead, i use a HashMap for each row, which enables me to access the value by #{row[columnname]}. (Not exactly this expression, but i hope u get the point)
Nothing really exotic in my opinion :)
About the actual problem:
When the a4j:commandLink (the "Save"-Link) on the modalPopup is clicked, it's action (and/or actionListener, where is the difference anyway?) is triggered, but the edited values from the h:inputText ("#{tableBean.selectedRow[columnname]}") are not applied to the bean. This means that i dont have any access to the 'new' values that should have been submitted by the commandlink.
Instead, the values of HashMap are the original ones.
This is driving me crazy since i have no idea what jsf/richfaces/whatever is actually doing, all I can do is debug the java part. But thats no help.
Using: Latest richfaces, tomcat6, everything else is working.
I modified the project in http://eclipse.dzone.com/articles/an-introduction-to-jboss-richf to get where i am. That tutorial is working with concrete tables, i added the functionality to be able to use dynamic columns via the HashMap.
The Page:
<ui:define name="body"> <h:form id="dynamic_table_form"> <rich:dataTable id="dynamic_table" value="#{tableBean.rows}" var="row" sortMode="single" reRender="dynamic_table_ds" ajaxKeys="#{tableBean.richAjaxKeys}"> <rich:columns value="#{tableBean.columns}" var="col" sortable="true" sortBy="#{row[col.name]}"> <f:facet name="header"> <h:outputText value="#{tableBean.columnLabels[col.name]}" /> </f:facet> <h:outputText id="#{col}" value="#{row[col.name]}" /> <f:facet name="footer"> <h:outputText value="#{col.type}" /> </f:facet> </rich:columns> <rich:column> <f:facet name="header"> #{msg.c_edit} </f:facet> <a4j:commandLink value="#{msg.c_edit}" oncomplete="#{rich:component('rowedit')}.show()" reRender="rowedit"> <f:setPropertyActionListener value="#{row}" target="#{tableBean.selectedRow}" /> <f:setPropertyActionListener value="#{row[tableBean.primarykey]}" target="#{tableBean.oldpkeyvalue}" /> </a4j:commandLink> <f:facet name="footer" /> </rich:column> </rich:dataTable> <h:outputText value="#{tableBean.errorText}" /> <rich:datascroller id="dynamic_table_ds" for="dynamic_table" fastControls="show" boundaryControls="hide" stepControls="hide"></rich:datascroller> </h:form> <a4j:form> <rich:modalPanel id="rowedit"> <f:facet name="header"> #{msg.c_edit} </f:facet> <!-- Unclean: manual HTML. But i dont see any other way here --> <table> <ui:repeat value="#{tableBean.columns}" var="col"> <tr> <td><h:outputLabel value="#{tableBean.columnLabels[col.name]}:"/></td> <td><h:inputText value="#{tableBean.selectedRow[col.name]}"/></td> </tr> </ui:repeat> </table> <!-- Buttons for cancelling and saving --> <h:panelGrid columns="2"> <a href="#" onclick="#{rich:component('rowedit')}.hide();return false">Close</a> <a4j:commandLink oncomplete="#{rich:component('rowedit')}.hide();return false" actionListener="#{tableBean.saveSelectedRowListener}" value="#{msg.c_save}" reRender="#{tableBean.reRenderAttributeValue}" /> </h:panelGrid> </rich:modalPanel> </a4j:form> </ui:define>
This is what it looks like after i click the "edit"-Link ("Bearbeiten" in german) in the first row of the table: [img]http://img440.imageshack.us/img440/253/scrbk4.jpg[/img]
I hope anyone can help me. I have to do this for work and no one knows anything about jsf/richfaces/etc here.