Setting A Value/id For A Pushbutton?

I was wondering if anyone can enlighten me as to how I can set a value/id for a pushbutton? (a button would work if thats the way it needs to be done)

In my case, I am grabbing data from the database and doing a for loop for each set of data that I fetch.
I want to be able to add a button to the set of data while printing it from the for loop and when the user clicks on it, allow the user to edit the data. So far I haven't found a way to set a value/id for the button like one would do in plain html. If this is possible then I know what set of data I am working on by the ID of that button which is gathered from my initial database fetch.

Thanks,

TJ

mjablonski's picture

maciaktj wrote:
I was wondering if anyone can enlighten me as to how I can set a value/id for a pushbutton? (a button would work if thats the way it needs to be done)

Echo2 is a component-oriented framework... so OO is your best friend. Simply derive your own button-class and enhance it with additional features.

Quick example to give you the idea:

public class ValueButton extends nextapp.echo2.app.Button {

     private Object value;

     public void setValue(Object obj) {
    this.value = obj;
     }

     public Object getValue() {
    return this.value;
     }
}

That's it. Now you'll can use your own ValueButton instead of Button and set/get a value as additional information.

Cheers, Maik

Thanks for the information and that works wonderful for a limited set of pre-defined buttons. However now I am trying to figure out how to set a listener that can determine which button was pushed to a variable amount of buttons.

UPDATE - I ended up adding an actionListener routine right within the button statement like this:

button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
log.debug("Value: " + button.getValue());
}
}

);

And that seems to work great! Thanks for all of your help. :)

Thanks,

TJ