myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rafa Pérez" <raja...@gmail.com>
Subject Re: Editable DataTable
Date Thu, 21 Feb 2008 09:59:35 GMT
InputText implements EditableValueHolder, so it should be submitted to the
server.

On Thu, Feb 21, 2008 at 10:02 AM, Hemanth Abburi <java4hemanth@gmail.com>
wrote:

> I think the values submitted in the input fields present in the datatable
> don't get populated into the managed beans because
> HtmlDataTable *extends* javax.faces.component.UIData which* extends*
> javax.faces.component.UIComponentBase....
> As UIData *doesn't* implement EditableValueHolder interface ( which has
> setSubmittedValues() method ) the values submitted in the datatable don't
> get updated to the managed bean because the setter (mutator) method for the
> list will not get called.
> If I am right, then how do I update the values in the list present in the
> managed bean which is used by the datatable?
>
> On 2/20/08, Andrew Robinson <andrew.rw.robinson@gmail.com> wrote:
> >
> > Just make sure Person has setName(String) and setAge(Number) methods.
> > You may need to use number converters with the age to work with
> > different number types.
> >
> > -Andrew
> >
> > On Wed, Feb 20, 2008 at 12:48 AM, Rafa Pérez <rajalin@gmail.com> wrote:
> > > This is not neccesary. Because of the ValueBinding for the InputText,
> > when
> > > you submit the form every object of the list of persons gets updated
> > with
> > > the values you entered in the table. This way, you only have to do:
> > >
> > >  for(Person person : persons) {
> > >
> > >     System.out.println(person.getName());
> > >     System.out.println(person.getAge());
> > > }
> > >
> > >
> > > HTH,
> > >
> > > - - Rafa
> > >
> > >
> > >
> > > On Feb 20, 2008 7:53 AM, Hemanth Abburi <java4hemanth@gmail.com>
> > wrote:
> > >
> > > >
> > > > Hi,
> > > >           Thanks for the prompt reply.
> > > >           What I meant by getting the values was "How can I retrieve
> > the
> > > values which the user has entered in the inputText field of the
> > datatable?".
> > > >            I found out a solution but don't know whether it's a
> > standard
> > > one or not.
> > > >             I  used the following code in the managed bean to get
> > the
> > > values submitted in the form.
> > > >
> > > >  UIComponent comp =
> > > FacesContext.getCurrentInstance
> > ().getViewRoot().findComponent("myform");
> > > >  List l=comp.getChildren();
> > > >  Iterator itr = l.iterator();
> > > >  while(itr.hasNext()){
> > > >   Object obj=itr.next();
> > > >
> > > >   if( obj instanceof UIData){
> > > >     UIData uIData=(UIData)obj;
> > > >     System.out.println("UIData "+ uIData);
> > > >     HtmlDataTable myTable = (HtmlDataTable)uIData;
> > > >
> > > >    for(int i=0;i<myTable.getRowCount();i++){
> > > >     myTable.setRowIndex(i);
> > > >     Person person = new Person();
> > > >     person = (Person) myTable.getRowData();
> > > >     System.out.println(person.getName());
> > > >     System.out.println(person.getAge());
> > > >
> > > >     }
> > > > person.getName() and person.getAge() are giving me the edited
> > values.
> > > > Is there any other way by which I can get them?
> > > > I can use "binding" but I would not like to use it.
> > > >
> > > >
> > > >
> > > >
> > > > On 2/19/08, Andrew Robinson <andrew.rw.robinson@gmail.com> wrote:
> > > > > your code is correct.
> > > > >
> > > > > #{person.name} invokes <Person instance>.getName()
> > > > > #{person.age} invokes <Person instance>.getAge()
> > > > >
> > > > > On Feb 18, 2008 9:30 PM, Hemanth Abburi <java4hemanth@gmail.com>
> > wrote:
> > > > > > Hi !!
> > > > > >            I am a newbie to JSF and am working on datatable.
I
> > wanted
> > > to
> > > > > > create a simple editable datatable.The datatable component in
> > the jsp
> > > is as
> > > > > > shown below..
> > > > > >
> > > > > >
> > > > > >
> > > > > > <h:dataTable value="#{table.persons}" var="person" border="1"
> > > > > > id="customTable" >
> > > > > >
> > > > > > <h:column>
> > > > > >
> > > > > > <f:facet name="header" ><h:outputText
> > > > > > value="#{msg.serialNumber}"/></f:facet>
> > > > > >
> > > > > > <h:outputText value="#{person.name}"/>
> > > > > >
> > > > > > </h:column>
> > > > > >
> > > > > > <h:column>
> > > > > >
> > > > > > <f:facet name="header"><h:outputText value="#{msg.exp
> > }"/></f:facet>
> > > > > >
> > > > > > <h:inputText value="#{person.age}"/>
> > > > > >
> > > > > > </h:column>
> > > > > >
> > > > > > </h:dataTable>
> > > > > >
> > > > > > I just want to know how i can get the values of "name" and "age"
> > which
> > > are
> > > > > > members of a class person.
> > > > > >
> > > > > > The managed bean contains of a list by the name "persons" which
> > > consists of
> > > > > > objects of type "person".
> > > > > >
> > > > > > Thanks,
> > > > > >
> > > > > > Hemanth.
> > > > >
> > > >
> > > >
> > >
> > >
> >
>
>

Mime
View raw message