myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Harald Müller <harald.muel...@wimaxtelecom.at>
Subject Re: datatable - parameter passing - workaround?
Date Wed, 14 Dec 2005 14:45:45 GMT
Hi!

Ok ... data.getColumns() and data.getRows() are not returning an empty collection.

And I've tried to do it with jsp-code.

<h:dataTable var="row" value="#{homeBean.testdata.rows}">
  <t:columns var="column" value="#{homeBean.testdata.columns}">
    <f:facet name="header">
      <h:outputText value="#{column.header}"/>
    </f:facet>
    <h:outputText value="#{column.value}"/>
  </t:columns>
  <h:column>
    <f:facet name="header">
      <h:outputText value="Process" />
    </f:facet>
    <h:outputText value="#{row.taskMgmtInstance.taskMgmtDefinition.processDefinition.name}"
/>
  </h:column>
</h:dataTable>

The columns are rendered but I have the same content (first element) in every column. I just
can't figure out what's going wrong here.

Some code-snippets:

-> homeBean
public Data getTestdata() {
	DataModel dm = new ListDataModel(this.getTaskInstances());
	this.testdata = new Data(dm);
	return testdata;
}

-> Data
import java.util.ArrayList;
import java.util.List;

import javax.faces.model.DataModel;

public class Data implements RowHolder
{
  private DataModel mRows;
  private List mColumns;
 
  public Data (DataModel dm) {
	  this.mRows = dm;
  }
  
  public DataModel getRows() {
    return mRows;
  }

  public Object getRowData()
  {
    DataModel dataModel = getRows();
    if(dataModel.isRowAvailable())
    {
      return dataModel.getRowData();
    }
    return null;
  }
  
  public List getColumns()
  {
    mColumns = createColumns();
	return mColumns;
  }

  private List createColumns()
  {
 	List result = new ArrayList();
    result.add(new Column("Col1", this));
    result.add(new Column("Col2", this));
    result.add(new Column("Col3", this));
    // add more columns
    return result;
  }
}

-> Column

import org.jbpm.taskmgmt.exe.TaskInstance;

public class Column
{
  private final String mHeader;
  private final RowHolder mRowHolder;

  public Column(String header, RowHolder rowHolder) {
    mHeader = header;
    mRowHolder = rowHolder;
  }
  
  public String getHeader() {
	  return mHeader;
  }

  public String getValue()
  {
	Object rowData = mRowHolder.getRowData();   
    if(rowData != null)
    {
    	return ((TaskInstance)rowData).getName()+"";
    }
    return null;
  }
}

Sorry ... but I really need some help ... :-(

Thanks,
Harry

-----Ursprüngliche Nachricht-----
Von: Mathias Brökelmann [mailto:mbroekelmann@googlemail.com] 
Gesendet: Dienstag, 13. Dezember 2005 15:21
An: MyFaces Discussion
Betreff: Re: datatable - parameter passing - workaround?

I can not see the problem in you code. However I have used UIColumns
only in jsp yet and not created it through java code.

Is data.getColumns() returning a non empty collection?
Is data.getRows() returning a non empty collection?
Can you try it with jsp code?

2005/12/13, Harald Müller <harald.mueller@wimaxtelecom.at>:
> Hi!
>
> Thanks again for your answer.
>
> Mmmmmh ... I've tried it as described on the wiki-page but it looks
> like that I'm doing something wrong with UIColumns.
>
> My code:
>
> HtmlDataTable hdt = (HtmlDataTable)app.createComponent(HtmlDataTable.COMPONENT_TYPE);
> hdt.setHeaderClass("tableheader");
> hdt.setColumnClasses("tablecell");
> hdt.setVar("taskInstance");
>
> DataModel content = new ListDataModel(this.getTaskInstances(includeList));
> Data data = new Data(content);
> hdt.setValue(data.getRows());
> //hdt.setValue(data);
>
> UIColumns columns = (UIColumns)app.createComponent(UIColumns.COMPONENT_TYPE);
> //valueBinding = app.createValueBinding("#{data.columns}");
> //columns.setValueBinding("value",valueBinding);
> columns.setValue(data.getColumns());
> columns.setVar("column");
>
> text = (UIOutput)app.createComponent(HtmlOutputText.COMPONENT_TYPE);
> valueBinding = app.createValueBinding("#{column.value}");
> text.setValueBinding("value", valueBinding);
> columns.getChildren().add(text);
> hdt.getChildren().add(columns);
>
> I've made a change in the "Data"-class - added:
>
> public Data (DataModel dm) {
>   this.mRows = dm;
> }
>
> There is nothing rendered on the page and it looks like that column.getValue() is not
called (but createColumns() and
> getColumns() are).
>
> Sorry ... don't know what's wrong :-(
>
> Thanks,
> Harry
>
>
> -----Ursprüngliche Nachricht-----
> Von: Mathias Brökelmann [mailto:mbroekelmann@googlemail.com]
> Gesendet: Dienstag, 13. Dezember 2005 10:45
> An: MyFaces Discussion
> Betreff: Re: datatable - parameter passing - workaround?
>
> did you take a look at t:columns ? I suggest you to use it if you need
> dynamic columns. You could then follow the wiki doc at
> http://wiki.apache.org/myfaces/Dynamic_Columns
>
> 2005/12/13, Harald Müller <harald.mueller@wimaxtelecom.at>:
> > Hi!
> >
> > Thanks for your answer.
> >
> > Let me try to describe my problem. I'm trying to build a datatable
> > with dynamic columns (additionally to some static columns). All information for
the datatable-creation is stored in a xml-file. It's not a big deal
> > building these dynamic colums with the right header but to fill it with content
I have to call a getter with a parameter.
> >
> > In my particular case:
> > taskInstance.getVariable('variable_name');
> >
> > Ok ... and that's my problem ...
> >
> > Any suggestion?
> >
> > Thanks,
> > Harry
> >
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Simon Kitching [mailto:skitching@obsidium.com]
> > Gesendet: Montag, 12. Dezember 2005 21:35
> > An: MyFaces Discussion
> > Betreff: Re: datatable - parameter passing - workaround?
> >
> > Hi,
> >
> > The rowIndex value changes when the enclosing table iterates over the
> > DataModel. For example, when the table is *rendering*, it does:
> >
> >    for(int index=0; ; ++index) {
> >      dataModel.setRowIndex(index);
> >      if (!dataModel.isRowAvailable)
> >        break;
> >
> >      Object o = dataModel.getRowData();
> >      // render a row for object o
> >    }
> >    dataModel.setRowIndex(-1);
> >
> > It does similar things during the "applyRequestValues" and "updateModel"
> > phases. In particular, any listeners (including action methods) on the
> > component which fire during these steps can assume that the
> > rowIndex/rowData point to the relevant row/object *at the time the
> > listener is invoked*. However the rowIndex is obviously not relevant
> > outside of the listener callbacks.
> >
> > I can't see what you are trying to achieve with your code below. Maybe
> > you could describe the problem you're trying to solve?
> >
> > Regards,
> >
> > Simon
> >
> > Harald Müller wrote:
> > >
> > > List contentList = new ArrayList();
> > > for (int i = 0 ; i<10;i++) {
> > >   contentList.add("row " + i);
> > > }
> > > DataModel content = new ListDataModel(contentList);
> > > hdt.setValue(content);
> > >
> > >
> > > The console-output looks like:
> > >
> > > [STDOUT] >>>>>>>>>> ==> ROWCOUNT 2
> > > [STDOUT] >>>>>>>>>> ==> ROWINDEX 0
> > > [STDOUT] >>>>>>>>>> ==> WRAPPEDDATA [org.jbpm.taskmgmt.exe.TaskInstance@1a9b034,
org.jbpm.taskmgmt.exe.TaskInstance@b950d1]
> > > [STDOUT] >>>>>>>>>> ==> ROWDATA org.jbpm.taskmgmt.exe.TaskInstance@1a9b034
> > > [STDOUT] >>>>>>>>>> ==> ROWCOUNT 2
> > > [STDOUT] >>>>>>>>>> ==> ROWINDEX 0
> > > [STDOUT] >>>>>>>>>> ==> WRAPPEDDATA [org.jbpm.taskmgmt.exe.TaskInstance@1a9b034,
org.jbpm.taskmgmt.exe.TaskInstance@b950d1]
> > > [STDOUT] >>>>>>>>>> ==> ROWDATA org.jbpm.taskmgmt.exe.TaskInstance@1a9b034
> > >
> > > As you can see there are 2 elements (wrappeddata) but the rowindex is not incremented
during the iteration ... so I always get the first element/object back by using 'content.getRowData()'.
> > >
> > > What am I doing wrong?
> > >
> > > Thanks,
> > > Harry
> > >
> > >
> > >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Mathias Brökelmann [mailto:mbroekelmann@googlemail.com]
> > > Gesendet: Montag, 12. Dezember 2005 15:39
> > > An: MyFaces Discussion
> > > Betreff: Re: datatable - parameter passing - workaround?
> > >
> > > use an instance of javax.faces.model.DataModel for the datatable´s
> > > value. You can then use datamodel.getRowIndex() or
> > > datamodel.getRowData() to get the current row value during the
> > > iteration.
> > >
> > > 2005/12/12, Harald Müller <harald.mueller@wimaxtelecom.at>:
> > >> Hi!
> > >>
> > >> My current (test)code to create a datatable in a dynamic created tab looks
like this:
> > >>
> > >>
> > >>       // datatable
> > >>       UIData hdt = (HtmlDataTable)app.createComponent(HtmlDataTable.COMPONENT_TYPE);
> > >>       hdt.setId("hdtId1");
> > >>       hdt.setVar("hdtVar1");
> > >>       tab.getChildren().add(hdt);
> > >>
> > >>       List content = new ArrayList();
> > >>       for (int i = 0 ; i<10;i++) {
> > >>         content.add("row " + i);
> > >>       }
> > >>       hdt.setValue(content);
> > >>
> > >>       // create column
> > >>       UIColumn column = (UIColumn)app.createComponent(HtmlSimpleColumn.COMPONENT_TYPE);
> > >>
> > >>       // create and add header
> > >>       UIOutput header = (UIOutput)app.createComponent(HtmlOutputText.COMPONENT_TYPE);
> > >>       header.setValue("Last Column");
> > >>       column.setHeader(header);
> > >>
> > >>       // create and add content
> > >>       UIOutput text = (UIOutput)app.createComponent(HtmlOutputText.COMPONENT_TYPE);
> > >>       ValueBinding valueBinding = app.createValueBinding(#{hdtVar1})
> > >>       text.setValueBinding("value", valueBinding);
> > >>       column.getChildren().add(text);
> > >>
> > >>       // add column
> > >>       hdt.getChildren().add(column);
> > >>
> > >>
> > >>
> > >> Ok ... it is not possible to pass a parameter using "valuebinding" - so,
there is no way
> > >> to call #{hdtVar1.name(mystring)} ... right?
> > >>
> > >> Is there a way to call a bean-setter and set the current object (of the
datatable-iteration)
> > >> in my bean, so that I'm able to call something like 'String whatever =
hdtVar1.getName("mystring")'
> > >> and do a 'text.setValue(whatever)' from there?
> > >>
> > >> Thanks,
> > >> Harry
> > >>
> > >
> > >
> > > --
> > > Mathias
> > >
> > >
> >
> >
>
>
> --
> Mathias
>


--
Mathias

Mime
View raw message