3 Replies Latest reply on Nov 27, 2008 9:52 AM by nbelaevski

    value of h:inputText is not applied to the bean on click of

    starfish0r

      I 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.

        • 1. Re: value of h:inputText is not applied to the bean on click
          ilya_shaikovsky

          rich:modalPanel should have its own form inside and be placed outside any external ones.

          • 2. Re: value of h:inputText is not applied to the bean on click
            starfish0r

            Thank you for the (very) quick reply.
            That actually solved something! Thanks a lot. How are novice users like me supposed to find out about that? I googled for 2 days now and the answer is that simple.

            Now i am getting a conversion error for the Date field ('null converter'). Meaning: i submit a string to the hashmap eventhough the data type should be java.util.Date. I know this is not richfaces-related, but is there a quick way to inject my own converter into this so the string will be parsed and converted into a java.util.Date?
            Alternative would be to work with strings for java.util.Date the whole time which is not as optimal. :(

            Thanks for the great support so far!
            Btw: I cannot find the link to edit my previous post. Is that disabled or am i too stupid for the internet?

            • 3. Re: value of h:inputText is not applied to the bean on click
              nbelaevski

              Hell,

              "starfish0r" wrote:
              Thank you for the (very) quick reply.
              That actually solved something! Thanks a lot. How are novice users like me supposed to find out about that? I googled for 2 days now and the answer is that simple.


              You can:

              1. Read the manual: http://www.jboss.org/jbossrichfaces/docs/
              2. Explore examples on demo site: http://livedemo.exadel.com/richfaces-demo/welcome.jsf
              3. Ask here

              "starfish0r" wrote:
              Now i am getting a conversion error for the Date field ('null converter'). Meaning: i submit a string to the hashmap eventhough the data type should be java.util.Date. I know this is not richfaces-related, but is there a quick way to inject my own converter into this so the string will be parsed and converted into a java.util.Date?
              Alternative would be to work with strings for java.util.Date the whole time which is not as optimal. :(


              You can create your own Facelets tag that will create input with converter attached.

              "starfish0r" wrote:
              Thanks for the great support so far!
              Btw: I cannot find the link to edit my previous post. Is that disabled or am i too stupid for the internet?


              Editing and deleting posts is disabled for users on this forum for some reason.