users@javaserverfaces.java.net

RE: HtmlDataTable: UIData.setRow method question

From: <jacob_at_hookom.net>
Date: Mon, 04 Dec 2006 16:34:01 -0500
getData() doesn't drive page navigation, it's just there to populate the dataTable on the screen, I'm assuming the set of data would initially be lazy fetched from the DB and stored in the Bean, only adding an extra item if someone asked for it.  You could get tricky and only add a row if there isn't already an empty row at the tail within your 'onAddRow' method.

 
OK... I believe I understand what your doing.
 
Your adding a new empty object (row) that will render the two empty HtmlInputText objects, in which the user may use to enter in the next value.
 
Side note: In your getData() getter, you're just reloading the data or page if there is no data?
 
Thank you very much for the response, this will go a long ways.
 
--Todd


From: jacob@hookom.net [mailto:jacob@hookom.net]
Sent: Monday, December 04, 2006 3:13 PM
To: users@javaserverfaces.dev.java.net
Subject: RE: HtmlDataTable: UIData.setRow method question

it's much easier than that based on my understanding--

Just add another empty object to your dataset (value bound)

public class BackingBean {
   private List data;
   public void getData() {
      if (this.data == null) {
         // lazy load
      }
      return this.data;
   }

   public void onAddRow() {
       this.getData().add(new Bean());
   }

   public void onSave() {
      BeanDao dao = new BeanDao();
      for (Bean b : this.getData()) {
         if (b.hasValue()) { // not empty instance
            dao.save(b);
         }
      }
   }
}

<h:dataTable value="#{backingBean.data}" var="foo">
   <h:column>Text: <h:inputText value="#{foo.text}"/></h:column>
   <h:column>Value: <h:inputText value="#{foo.value}"/></h:column>
</h:dataTable>

<h:commandButton action="#{backingBean.onAddRow}"/>
<h:commandButton action="#{backingBean.onSave}"/>


 
I believe I understand this, but I just want to make sure there isn't an easier way to accomplish this.
 
I am trying to use the HtmlDataTable in the following matter:
 
 
The Text and Value HtmlInputText are string values. Clicking on the "Add Row" button just adds one row below the current row - in which a user can enter another set of text and value pairs.
 
Clicking on the "Save" button would save all of the data to the backing bean (I haven't figured out the best way to do this, but I am concerned with the following question at this point).
 
(Oh, saving state and validation... I'll get there as well.)
 
My thought is I believe I should use the UIData.setRow method to add the row?
 
Looking at the HtmlInputText API, that seems like the right way too go...
 
I have googled on this and found a lot of good information on building a HtmlDataTable in a backing bean, which is a great start and provides a path. But to accomplish what I've described above, I haven't seen any examples or information similar...
 
I'd appreciate some thoughts as I am developing this.
 
Thanks,
 
--Todd
NOTICE: This email message is for the sole use of the
intended recipient(s) and may contain confidential and privileged
information. Any unauthorized use, disclosure or distribution is
prohibited. If you are not the intended recipient, please contact
the sender by reply email and destroy all copies of the original
message.