Hidden field for "remembering" an old value.

View: New views
4 Messages — Rating Filter:   Alert me  

Hidden field for "remembering" an old value.

by Q Beukes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey,

I have the following:
<webuijsf:table id="gridReaders" paginateButton="true" paginationControls="true">
  <webuijsf:tableRowGroup binding="#{ConfigLamps.rgReaders}" id="rgReaders" rows="10"
    sourceData="#{ConfigLamps.readers}" sourceVar="currentRow">
  <webuijsf:hiddenField binding="#{ConfigLamps.readerId}" converter="#{ConfigLamps.integerConverter}"
    id="readerId" text="#{currentRow.value['id']}"/>
  <webuijsf:tableColumn sort="id">
    <webuijsf:textField binding="#{ConfigLamps.txtReaderID}" converter="#{ConfigLamps.integerConverter}"
        id="txtReaderID" text="#{currentRow.value['id']}"
        valueChangeListenerExpression="#{ConfigLamps.readerData_processValueChange}"/>
   </webuijsf:tableColumn>
  </webuijsf:tableRowGroup>
</webuijsf:table>

Then, ConfigLamps.readers source data binding is merely linked against a "public Lamp[] getReaders()" method which returns a bunch of Lamp objects. The object has a field "id" which I want to update using the text field.

I do the matching against the entity by getting the current row's "readerId.getValue()", fetching a Lamp by this ID, and then updating it's fields. I do this for all my tables.

It has worked so far to carry the primary key of the record in a hidden field, but I have run into a problem where I want to update the primary key field itself.

Since both the hidden and text field's have: text="#{currentRow.value['id']}"
Whenever I change the value of the text field, the hidden field's binding field also changes.

This is normal.

My question is
(1) Is there a better way of identifying the record I am busy with. For instance, can I fetch row's object (which is referred to by currentRow. In other words, can I get the currentRow's Lamp object.
(2) Is there a way to have the hidden field's value set by value, meaning it isn't linked against the binding object?

Regarding the first question, I have checked around the RowKey object and such, to see if I can get the bound object, but find no way to do this.

thanks
Quintin

Re: Hidden field for "remembering" an old value.

by Stefan Bley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Regarding question (1)

If you bind your tableRowGroup's sourceData to a object list data provider you can get the current lamp like this:

public Object getSelectedObject() {
        try {
            for (RowKey rowKey : getRgReaders().getSelectedRowKeys()) {
                return this.myObjectListDataProvider().getObject(rowKey);

            }
        } catch (Exception e) {
        }
        return null;
    }

I don't really understand your second question. You *don't* want it reference the same value as the textfield?

Stevy

Q Beukes wrote:
Hey,

I have the following:
<webuijsf:table id="gridReaders" paginateButton="true" paginationControls="true">
  <webuijsf:tableRowGroup binding="#{ConfigLamps.rgReaders}" id="rgReaders" rows="10"
    sourceData="#{ConfigLamps.readers}" sourceVar="currentRow">
  <webuijsf:hiddenField binding="#{ConfigLamps.readerId}" converter="#{ConfigLamps.integerConverter}"
    id="readerId" text="#{currentRow.value['id']}"/>
  <webuijsf:tableColumn sort="id">
    <webuijsf:textField binding="#{ConfigLamps.txtReaderID}" converter="#{ConfigLamps.integerConverter}"
        id="txtReaderID" text="#{currentRow.value['id']}"
        valueChangeListenerExpression="#{ConfigLamps.readerData_processValueChange}"/>
   </webuijsf:tableColumn>
  </webuijsf:tableRowGroup>
</webuijsf:table>

Re: Hidden field for "remembering" an old value.

by Q Beukes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey,

My second question is if I can have it reference the same value, but the change in one, doesn't change both.

So basically, TextField references object.id by reference (meaning changing the text field changes the object value).

And HiddenField references object.id by value (copies the value), so changing it doesn't change object.id, and changing textfield doesn't changed hidden field's value. Basically a way to store and post the "original" value.

Q


On 7/21/08, Stefan Bley <stefan.bley@...> wrote:

Regarding question (1)

If you bind your tableRowGroup's sourceData to a object list data provider
you can get the current lamp like this:

public Object getSelectedObject() {
        try {
            for (RowKey rowKey : getRgReaders().getSelectedRowKeys()) {
                return this.myObjectListDataProvider().getObject(rowKey);

            }
        } catch (Exception e) {
        }
        return null;
    }

I don't really understand your second question. You *don't* want it
reference the same value as the textfield?

Stevy



Q Beukes wrote:
>
> Hey,
>
> I have the following:
> <webuijsf:table id="gridReaders" paginateButton="true"
> paginationControls="true">
>   <webuijsf:tableRowGroup binding="#{ConfigLamps.rgReaders}"
> id="rgReaders" rows="10"
>     sourceData="#{ConfigLamps.readers}" sourceVar="currentRow">
>   <webuijsf:hiddenField binding="#{ConfigLamps.readerId}"
> converter="#{ConfigLamps.integerConverter}"
>     id="readerId" text="#{currentRow.value['id']}"/>
>   <webuijsf:tableColumn sort="id">
>     <webuijsf:textField binding="#{ConfigLamps.txtReaderID}"
> converter="#{ConfigLamps.integerConverter}"
>         id="txtReaderID" text="#{currentRow.value['id']}"
>
> valueChangeListenerExpression="#{ConfigLamps.readerData_processValueChange}"/>
>    </webuijsf:tableColumn>
>   </webuijsf:tableRowGroup>
> </webuijsf:table>
>
>


--
View this message in context: http://www.nabble.com/Hidden-field-for-%22remembering%22-an-old-value.-tp18559843p18565295.html

Sent from the Project Woodstock - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...




--
Quintin Beukes

Re: Hidden field for "remembering" an old value.

by Stefan Bley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I don't think there is a feature like that.
You could try a disabled/readOnly field that is not submitted with the form instead of the hiddenfield.

Or you bind the hiddenfield's text to a property in your backing bean and implement some custom logic in your getters and setters, which would delegate to the object's getters and setters only in special cases.

Stevy

Q Beukes wrote:
Hey,

My second question is if I can have it reference the same value, but the
change in one, doesn't change both.

So basically, TextField references object.id by reference (meaning changing
the text field changes the object value).

And HiddenField references object.id by value (copies the value), so
changing it doesn't change object.id, and changing textfield doesn't changed
hidden field's value. Basically a way to store and post the "original"
value.
LightInTheBox - Buy quality products at wholesale price