How do I get the rowid or the DataModel from a DataTable inside a DataTable

Hi,
I have a simple application which I cannot get to work.
I have two entity classes: Parent and Child.
I want to create a page which lists all of the Parents, and in a column of the Parent row has an inner dataTable which displays the Children of the Parent. I then want to click on the Child and link to a view of that Child. What is happening is that I cannot resolve which child was clicked inside my row. I don't seem to be able to get the datamodel for the List children, so it always defaults to the first child in the list.
Goal: drill down to a specific child from a list of parents with a sublist of children belonging to each parent.
I have tried creating a new method called prepareChildView() in ParentController like this below but it always returns the first child. I figure I need to create the DataModel earlier but cannot figure out how to do this. Perhaps the auto generated pattern makes it difficult to achieve what I want to - not sure.
public String prepareChildView() {
        current = (Parent)getItems().getRowData();
        DataModel d = new ListDataModel(current.getChildren());
        Child child = (Child)d.getRowData();
        //child is always the first child!
        return "\children\View";
    }I may be going about this completely wrong so am open to suggestions. I am using JSF2, Glassfish3.0.
Parent.java
@Entity
public class Parent implements Serializable {
    @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
    private List<Child> children;
    public List<Child> getChildren() {
        return children;
    public void setChildren(List<Child> children) {
        this.children = children;
}Child.java
@Entity
public class Child implements Serializable {
    @ManyToOne
    @JoinColumn(name = "parent")
    private Parent parent;
    public Parent getParent() {
        return parent;
    public void setParent(Parent parent) {
        this.parent = parent;
}ParentFacade and ChildFacade are auto generated from NetBeans, as are ParentController and ChildController.
ParentController:
Code doen't fit in the post.
List.xhtml
<h:form styleClass="jsfcrud_list_form">
            <h:panelGroup id="messagePanel" layout="block">
                <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
            </h:panelGroup>
            <h:outputText escape="false" value="#{bundle.ListParentEmpty}" rendered="#{parentController.items.rowCount == 0}"/>
            <h:panelGroup rendered="#{parentController.items.rowCount > 0}">
                <h:outputText value="#{parentController.pagination.pageFirstItem + 1}..#{parentController.pagination.pageLastItem + 1}/#{parentController.pagination.itemsCount}"/> 
                <h:commandLink action="#{parentController.previous}" value="#{bundle.Previous} #{parentController.pagination.pageSize}" rendered="#{parentController.pagination.hasPreviousPage}"/> 
                <h:commandLink action="#{parentController.next}" value="#{bundle.Next} #{parentController.pagination.pageSize}" rendered="#{parentController.pagination.hasNextPage}"/> 
                <h:dataTable value="#{parentController.items}" var="item" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px">
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Id"/>
                        </f:facet>
                        <h:outputText value="#{item.id}"/>
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Name"/>
                        </f:facet>
                        <h:outputText value="#{item.name}"/>
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Children" />
                        </f:facet>
                        <h:dataTable value="#{item.children}" var="child" >
                            <h:column>
                                <h:commandLink action="#{parentController.prepareView}" value="#{child.name}" />
                            </h:column>
                        </h:dataTable>
                    </h:column>
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value=" "/>
                        </f:facet>
                        <h:commandLink action="#{parentController.prepareView}" value="#{bundle.ListParentViewLink}"/>
                        <h:outputText value=" "/>
                        <h:commandLink action="#{parentController.prepareEdit}" value="#{bundle.ListParentEditLink}"/>
                        <h:outputText value=" "/>
                        <h:commandLink action="#{parentController.destroy}" value="#{bundle.ListParentDestroyLink}"/>
                    </h:column>
                </h:dataTable>
            </h:panelGroup>
            <br />
            <h:commandLink action="#{parentController.prepareCreate}" value="#{bundle.ListParentCreateLink}"/>
            <br />
            <br />
            <h:commandLink value="#{bundle.ListParentIndexLink}" action="/index" immediate="true" />
        </h:form>

Hi,
It will help to resolve your issue:
    public String processChildView(){
        UIComponent component = null;
        String  componentId = null;
        Parent parent = null; //Bean class
        Child child = null; //Bean Class
        FacesContext context = FacesContext.getCurrentInstance();
        UIViewRoot root = context.getViewRoot();
        String childView = "childView";
        //Parent Table UIData
        componentId = "parentChildTable";
        component = findComponent(root, componentId);               
        UIData parentTable = (UIData) component;
        //Child Table UIData
        componentId = "childTable";
        component = findComponent(root, componentId);               
        UIData childTable = (UIData) component;
        //Perform Parent Child operation
        if(parentTable != null && childTable != null){
            if(parentTable.getRowData() instanceof Parent){
                //Get Parent Object from parentTable
                parent = (Parent) parentTable.getRowData();
                //Get child object by parent object using childTable's Row Index
                parent = (Parent) parentTable.getRowData();
                child = (Child) parent.getChild().get(childTable.getRowIndex());
                System.out.println("Parent Name " + parent.getName() + "Child Name " + child.getName());
        return childView;
    //Utility method to get component by passing component id in requested view
    public static UIComponent findComponent(UIComponent c, String id) {
         if (id.equals(c.getId())) {
           return c;
         Iterator kids = c.getFacetsAndChildren();
         while (kids.hasNext()) {
           UIComponent found = (UIComponent) findComponent((UIComponent)kids.next(), id);
           if (found != null) {
             return found;
         return null;
  } Regards,
Manish Paliwal
"Life is beautifull."

Similar Messages

  • How can i get thes songs from ipod nano to the itunes libary??

    hi
    i have ipod nano and i sync it with over 500 songs .....my bad i lose all that songs on my libary  .... how can i get thes songs from ipod nano to the itunes libary??

    See this older post from another forum member Zevoneer on different ways to copy content from your iPod to your computer.
    https://discussions.apple.com/thread/2452022?start=0&tstart=0
    B-rock

  • How we can get the values  from one screen to another screen?

    hi guru's.
         how we can get the values  from one screen to another screen?
              we get values where cusor is placed but in my requirement i want to get to field values from one screen to another screen.
    regards.
      satheesh.

    Just think of dynpros as windows into the global memory of your program... so if you want the value of a field on dynpro 1234 to appear on dynpro 2345, then just pop the value into a global variable (i.e. one defined in your top include), and you will be able to see it in your second dynpro (assuming you make the field formats etc the same on both screens!).

  • How do I get the values from a form?

    How do I get the values from a form?

    You can try using request method..
    request.getParameter("yourFormInputName");
    Try this.

  • How do I get the contacts from my mac to syn with icloud? I need to back up my phone and don't want to lose my contacts when I get a new phone.

    How do I get the contacts from my mac to sync with Icloud? I need to back up my phone since I will be receiving a new one tomorrow and the icloud contacts are not the same as the ones on my mac.  Help me

    OS X Lion. 10.7. Your profile says your running 10.6.8, which is Snow Leopard. You need 10.7 to use iCloud with your Mac.

  • HT204053 i have an itunes library with 1,000+ songs on a pc.  my daughter has a macbook air and i loaded my apple ID onto it.  how do i get the songs from my itunes account to show up?  This works fine on her iPhone, but having trouble on the new macbook

    i have an itunes library with 1,000+ songs on a pc.  my daughter has a macbook air and i loaded my apple ID onto it.  how do i get the songs from my itunes account to show up?  This works fine on her iPhone, but having trouble on the new macbook air

    Hey kbert73
    I would do a transfer of purchases from the phone and not sync. If you sync then it will want to start over and sync music that is on the MacBook Pro. If you want to transfer the music, check out the article below that will give you multiple options on how to move. I have also provided on how to sync with multiple computers.
    iTunes: How to move your music to a new computer
    http://support.apple.com/kb/ht4527
    Using iPhone, iPad, or iPod with multiple computers
    http://support.apple.com/kb/ht1202
    Thanks for using Apple Support Communities.
    Regards,
    -Norm G.

  • I have signed into a new account on my itunes on my computer. How do I get the music from the new account to be displayed in my library, because I can only see the old accounts music.

    I have signed into a new account on my itunes on my windows computer. How do I get the music from the new account to be displayed in my library if only the old account's music is showing up?

    You can transfer the music purchased from iTunes Store to the computer but not music acquired somewhere else.
    Syncing is one way street, computer to iPhone. You have to use 3rd party tool to transfer music not from iTunes Store to the computer.

  • HT4437 I want to develop a software with AirPaly service for business things. How can I get the permission from Apple?

    I want to develop a software with AirPaly service for business things. How can I get the permission from Apple?
    This one is used in Windows laptop, and I want it support AirPlay service, but Apple doesn't publish the AirPlay protocol.
    Many thanks.

    Create a developer account, then access he developers forums and see if you can find the information that way 
    The other option would be to simply contact Apple directly.

  • My wife has an I Tunes account on our PC, I have an I tune account on my Mac Book Pro.   How can I get the music from her account on the PC to my account on the Mac Book and I phone?

    My wife has an I Tunes account on our PC, I have an I tune account on my Mac Book Pro.   How can I get the music from her account on the PC to my account on the Mac Book and I phone?

    IflyDavie wrote:
    I need help to delete my icloud account from my iPad.  It has "Find my iPad" on it and won't let me delete without the old password.  I don't want to reset password as it will require reset of Mac Book Pro and 2 iphones.  Help appreciated.
    Your description of the problem is a bit confusing.  Do you have ONLY ONE Apple ID or do you have MORE THAN ONE?

  • Can anyone let me know how can i get the ouput from BW in .txt format.

    Can anyone let me know how can i get the ouput from BW in .txt format. See we can get output as Excel(i.e BEX) and manually convert it into txt format. I need a direct or automated way to do the same.no human intervention.
    mail me at [email protected] or post answer in sdn.

    Please do not multiple post across forums..
    how can i save the data in BEX reports in .txt format automatically
    This helps in keeping track of answers and avoids the issue of repeated answers across forums...
    Please close one of the threads as answered and provide the link that you want to follow
    Arun

  • How Can we get the data from Non-SAP to SAP in WebDynpro

    Hi,
    I hope u understand my query, How can we get the data from Non-SAP to SAP thru WebDynpro Programming.
    Help out with the steps for getting the data or procedure.
    Regards,
    Mutyapu

    You can expose the APIs in the Non-SAP backend as Web Services, and consume them in SAP by creating an Enterprise Proxy. Then these can be called just like normal class methods from Web Dynpro.
    Regards,
    Nithya

  • How can I get the events from a java program?

    I want to make a monitor to watch a java program.How can I get the events from the GUI of this program some as mouse cliking, keyinput. So I can watch these in my monitor.
    Thanks

    Hi,
    To put a monitor to the events occuring in the GHUI u need to register required components with the appropriate EventListeners.
    Liek if u want to get notified when a mouse is clicked, then u need to add The MouseListener to the component which u want to be monitored.
    Say
    myFrame which is the JFrame object which shuld be monitored for the events.
    Then in ur program u have to add following code
    myFrame.addMouseListener( someObectReference );
    Here the someObjectReference should be an instance to a concrete class ..i.e. U write a class like the following
    public class MyMouseListener implements MouseListener {
    // override the followig methods
    public void mouseClicked(MouseEvent me){ sop("MOUSE CLICKED ON THE FRAME");}
    public void mousePressed(MouseEvent me){}
    public void mouseReleased(MouseEvent me){}
    If u dont want to use another class for listening to the events. Then u can make teh current class monitor the events. To do so ur class should implement the appropriate listener and should override the required methods.
    and u should say myFrame.addMouseListenet( this );
    thats it

  • My computer crashed and I no longer have the itunes library. i get an error msg that my iphone is synced to another library - how can I get the info from the phone to the itunes library?

    my computer crashed and I no longer have the itunes library. i get an error msg that my iphone 3g is synced to another library - how can I get the info from the phone to the itunes library without losing everything? How do I delete old audiobooks from my iphone?

    You can transfer itunes purchases:  File>Devices>Transfer Purchases
    The iphone is not a storage/backup device.  The sync is one way - computer to iphone.  The exception is itunes purchases.
    It has always been very basic to always maintain a backup copy of your computer.  Use your backup copy to put everything back.

  • My old computer crashed how do i get the music from my ipod to sinc with my itunes library?

    My old computer crashed how do i get the music from my ipod to sinc with my itunes library?

    You should be able to copy iTunes purchases to your computer's iTunes via File > Transfer Purchases. For music that you've bought from other sources or copied from your own CDs then have you not got a backup of them on, for example, an external drive that you can copy onto the computer ? If not then you will need to find a third-party program to copy them off - this post mentions some that were around a couple of years ago, whether they still exist and work I don't know.

  • My laptop crashed and I had to get a new hard drive.  How do I get the music from my Ipod back into my itunes library?

    My laptop crashed and I had to get a new hard drive.  How do I get the music from my iPod back into iTunes Library?

    See this excellent user tip from another forum member turingtest2 outlining the different methods and software available to help you copy content from your iPod back to your PC and into iTunes.
    Recovering your iTunes library from your iPod or iOS device
    B-rock

  • I have appleTV 1st generation.. How do i get the pictures from my AppleTv on to my new MacBook Pro

    I have appleTV 1st generation.. How do i get the pictures from my AppleTv on to my new MacBook Pro

    Welcome to the Apple Community.
    There is no option to sync photos from the Apple TV (only to it).

Maybe you are looking for