Gary, many thanks; well-worded and cleared up my previous questions.  I'm using Apache Beehive as my controller, and will look into how I can access the datatable row attribute that way (via the the page context?).  I already figured I needed to access the current context, but was at a loss as to whether the current row data is available for access via my backing bean.  Thanks again.

TR


From: Gary VanMatre [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 20, 2006 11:39 AM
To: MyFaces Discussion
Subject: RE: Constructing Datatable with Columns Having Foreign Key references

>1) What is locale$select doing in  ="#{locale$select.selectStudent}"? 
>  Is that assuming there is a properties file you're using for locale? 
<  I'm familiar with useing "#{foo.bar}" and "${bar}", but the notation
>  isn't familiar to me.
>

The "locale$select" is just a managed bean name.  I had a Shale example
that I hacked up for this one.  The '$' is a valid character in a
managed bean name.  It's a default convention used by the Shale ViewController
(http://struts.apache.org/struts-shale/features-view-controller.html ).

>
>2) You call select.selectStudent and set a parameter "name" to the
>  value of the current student, "#{s}" ... I understand that forcing
>  an action will cause that portion of the table to be updated, but
>  how do I place multiple 'sub-rows' in a row initially, without requiring
>  a user to click on a particular row?  Does the immediate="true" attribute
>  force the action to take place as the table is rendering?  If so, that
>  is excellent, I didn't realize the immediate attribute would do that for
>  an action (like a commandLink or commandButton). My goal is to populate
>  this entire table on first loading, and not requiring a user to click
>  on a particular row to see the many sub-rows in a column. 
>
The <f:param> in the dataTable nested in the column is used to pass on
the name parameter of the selected student.  So, this has nothing to do
with populating the object graph used by the two data tables.  It's more
about how you could provide a way to select a student. 
 
The immediate attribute on the command components just tells the lifecycle
to stop short and not perform validation on the widgets in the form.  In
this example, it really is not needed since there is not any UIInput
components within the form.

The Student column has a nested datatable that is populated from the ClassInfo
object from the outer dataTable.  The getStudent() method is invoked for each
class object.  This can be a hook to build the list for the nested table using
the primary key of class id. 
 
If you wanted to populate the entire object graph first (list of classes and
students in each class), you might look at the shale view controller (link above).
The ViewCotroller gives you extra lifecycle events such as a "prerender"
callback method that is invoked in the managed bean before the view is
rendered.  This would be a good place to add logic to stage data for the page.
 
The ViewController is fixed to the page by association of the viewId with the
managed bean name.  The managed bean needs to implement the ViewController
interfaces or use the shale tiger annotations.  The mapping of view id to
the managed bean name strips out the '/' chars making them '$' chars and
removes the suffix ".jsp".
 
>TR
 

From: Gary VanMatre [mailto:[EMAIL PROTECTED]
Sent: Wednesday, April 19, 2006 5:51 PM
To: MyFaces Discussion
Subject: RE: Constructing Datatable with Columns Having Foreign Key references

 
How about something like this:
 
JSP:
   <h:form id="test">
   <h:dataTable value="#{locale$select.classes}" var="class">
      <h:column>
          <f:facet name="header">
              <f:verbatim>Students</f:verbatim>  
          </f:facet>
          <h:dataTable value="#{class.students}" var="s">
              <h:column>
                  <h:commandLink action="" value="#{s}" immediate="true">
                &a mp;n b sp;&n bsp;   <f:param name="name" value="#{s}"/>
                  </h:commandLink>
              </h:column>
          </h:dataTable>     
      </h:column>
      <h:column>
          <f:facet name="header">
              <f:verbatim>Class Id</f:verbatim>  
          </f:facet>
          <h:outputText value="#{class.id}"/>
      </h:column>
   &n bsp;&n bsp; <h :column>
          <f:facet name="header">
              <f:verbatim>Description</f:verbatim>  
          </f:facet>
          <h:outputText value="#{class.description}"/>
      </h:column>

   </h:dataTable>
   </h:form>

Managed Bean:
    public ClassInfo[] getClasses() {
       ClassInfo[] classes = new ClassInfo[3];
       classes[0] = new ClassInfo(new Integer(100), "Basket Weaving");
       classes[1] = new ClassInfo(new Integer(200), "Industrial arts");
       classes[2] = new ClassInfo(new Integer(300), "Computer Science");
      
       return classes;
      
    }
   
   
    public String selectStudent() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        String name = (String) facesContext.getExternalContext().getRequestParameterMap().get("name");
   & ;nbs p ;&nbs p;   System.out.println(name);
       
        return null;
    }

ClassInfo Class:
public class ClassInfo {
    private Integer id = null;
    private String description = null;
   
   
    public ClassInfo(Integer id, String description) {
       this.id = id;
       this.description = description;
    }
   
    public String getDescription() {
        return description;
    }
   
    public void setDescription(String description) {
        this.description = description;
    }
   
    public Integer getId() {
        return id;
    }
   
    public void setId(Integer id) {
        this.id = id;
    }
   
    
    public String[] getStudents() {
         //FacesContext facesContext = FacesContext.getCurrentInstance();
         // simulate a db call
         if (id.equals(100)) {
            return new String[] {
                "Bob", "Sally", "Fred"       
            };
         } else if (id.equals(200)) {
            return new String[] {"Joe", "Ben"};   
  ;         } else
            return new String[] {"Gary", "Zane", "Seth"};
       
    }
   
   
}
Gary
 
-------------- Original message --------------
From: "Romanowski, Tim" <[EMAIL PROTECTED]>
Gary, thanks for the suggestion, but I'm not sure I understand how this will help me:
 
Are you suggesting to use the datalist within my datatable?  In such a case, the value returned by "#{countryList.countries}" is dependent upon the row id of my datatable.  So I would have several columns in my datatable, of which one of those columns can have multiple 'sub-rows' per datatable row.  When I render my datatable, how would I access the current row id in a bean so that I can do a calculation for displaying more data in _another_ column for the _same_ row?   Emphasis added since the wording can get tricky.
 
I could solve this by having two Lists, one which is used for the datatable, and another used by the particular column.  I could then synchronize those lists myself, and write some spaghetti to increment a counter every time I grab the data for the particular multi-row column.  However, that is a pretty ugly way of handling this, and I'm hoping there is an elegant (or at least less ugly) solution.  Thoughts? 


From: Gary VanMatre [mailto:[EMAIL PROTECTED]
Sent: Wednesday, April 19, 2006 4:16 PM
To: MyFaces Discussion
Subject: RE: Constructing Datatable with Columns Having Foreign Key references

 
You might give the dataList component a look.  The rowIndexVar will give you the current row (http://myfaces.apache.org/tomahawk/dataList.html).
 
    <t:dataList id="data1"
        styleClass="standardList"
        var="country"
        value="#{countryList.countries}"
        layout="simple"
        rowCountVar="rowCount"
        rowIndexVar="rowIndex">
        <h:outputText value="#{country.name}" />
        <h:outputText value=", " rendered="#{rowIndex + 1 < rowCount}" />
    </t:dataList>
 
Gary
-------------- Original message --------------
From: "Romanowski, Tim" <[EMAIL PROTECTED]>
Perhaps to point this in a useful direction: is it possible to get a value of the current row (such as "row.id") from the FacesContext in a bean?  For example:
 
<t:column>
  <f:facet name="header">
    <f:verbatim>MyValues</f:verbatim>
  </f:facet>
  <h:outputText value="${currentRow.currentRowValues}" />
</t:column>
 
Is it possible to access another value for the currentRow object, such as currentRow.ID, by calling the FacesContext in a backing bean? If so, what is the proper way to do this? 
 
 
 


From: Romanowski, Tim
Sent: Wednesday, April 19, 2006 9:57 AM
To: users@myfaces.apache.org
Subject: Constructing Datatable with Columns Having Foreign Key references

 

When constructing a myfaces (tomahawk) datatable, I have a couple columns that each contain foreign key references.  How do you guys handle the situation where a given row in a datable might have a column that itself has multiple rows?  In other words, row 1 of my datable has a column which itself contains several rows.  It doesn't seem like placing a child datatable within a parent datatable will necessarily solve anything, since I don't know what data goes in the current row until I know the value of a column in the current row. 

From reading looking through the archives and some other sites, it looks (is this true?) that there is no clean way to pass a parameter of the current row id back to a backing bean to do some processing for dynamically constructing the current row.    I've seen some suggestions on setting f:param and using that value, but setting an f:param to equal the current rowid in a datatable doesn't seem to work.  I've also seen another kludge that used a 'disabled' property to set a map value, but that was, well, a kludge (but perhaps the best way?). 

Again, how are you guys constructing complex tables?  Any help would be greatly appreciated!

_____________________________________

TR


Reply via email to