users@javaserverfaces.java.net

RE: HtmlDataTable: UIData.setRow method question

From: xoxota <philippe.desrosiers_at_gmail.com>
Date: Mon, 23 Jul 2007 10:00:11 -0700 (PDT)

I'm trying to do something similar here, and this looks good, but if I
understand correctly the backing bean for the page has to be in the session
scope, otherwise the list will simply be re-initialized from the datastore
the first time getData() is called, correct?

Is there any way to do the same thing, while keeping the backing been in the
request scope?


Jacob Hookom wrote:
>
> 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.&nbsp; You could get tricky and only add a row if
> there isn't already an empty row at the tail within your 'onAddRow'
> method. &nbsp;
>
>
>
>
> OK... I believe I understand what your
> doing.
> &nbsp;
> Your adding a new empty&nbsp;object (row) that will render
> the two empty HtmlInputText objects, in which the user may use to enter in
> the
> next value.
> &nbsp;
> Side note: In your getData() getter, you're just reloading
> the data or page if there is no data?
> &nbsp;
> Thank you very much&nbsp;for the response, this will go a
> long ways.
> &nbsp;
> --Todd
>
>
> From: jacob_at_hookom.net [mailto:jacob_at_hookom.net]
> Sent: Monday, December 04, 2006 3:13 PM To:
> users_at_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 { &nbsp;&nbsp; private List data; &nbsp;&nbsp; public void
> getData() { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (this.data == null)
> { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // lazy
> load &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> return this.data; &nbsp;&nbsp; } &nbsp;&nbsp; public void onAddRow()
> { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.getData().add(new
> Bean()); &nbsp;&nbsp; } &nbsp;&nbsp; public void onSave()
> { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BeanDao dao = new
> BeanDao(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (Bean b : this.getData())
> { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (b.hasValue()) { //
> not
> empty
> instance
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> dao.save(b); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;
> } } &lt;h:dataTable value="#{backingBean.data}"
> var="foo"&gt; &nbsp;&nbsp; &lt;h:column&gt;Text: &lt;h:inputText
> value="#{foo.text}"/&gt;&lt;/h:column&gt; &nbsp;&nbsp;
> &lt;h:column&gt;Value:
> &lt;h:inputText
> value="#{foo.value}"/&gt;&lt;/h:column&gt; &lt;/h:dataTable&gt;
> &lt;h:commandButton
> action="#{backingBean.onAddRow}"/&gt; &lt;h:commandButton
> action="#{backingBean.onSave}"/&gt;
>
>
>
> &nbsp;
>
> I believe I understand this, but I just
> want to make sure there isn't an easier way to accomplish
> this.
> &nbsp;
> I am trying to use the HtmlDataTable in
> the following matter:
> &nbsp;
>
> &nbsp;
> The Text and Value
> HtmlInputText&nbsp;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.
> &nbsp;
> 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).
> &nbsp;
> (Oh, saving state and validation...
> I'll get there as well.)
> &nbsp;
> My thought is I believe I should use
> the UIData.setRow method to add the row?
> &nbsp;
> Looking at the HtmlInputText API, that
> seems like the right way too go...
> &nbsp;
> 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&nbsp;any examples or information
> similar...
> &nbsp;
> I'd appreciate some thoughts as I am
> developing this.
> &nbsp;
> Thanks,
> &nbsp;
> --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.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_javaserverfaces.dev.java.net
> For additional commands, e-mail: users-help_at_javaserverfaces.dev.java.net
>
>
>

-- 
View this message in context: http://www.nabble.com/HtmlDataTable%3A-UIData.setRow-method-question-tf2756711.html#a11748492
Sent from the javaserverfaces users mailing list archive at Nabble.com.