You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Ray Clark <rc...@yahoo.com> on 2005/04/07 04:45:55 UTC

dataTable and commandButton question

I'm sure this must have been asked before but I can't
find it in the archives.  So please forgive me if it
has been asked before.

I have a dataTable with a commandButton rendered on
each row.  When the commandButton is pressed I need
it's managed bean method to know which row the button
was pressed for.  So how can the method know which row
to process?

Thanks,
Ray


		
__________________________________ 
Do you Yahoo!? 
Take Yahoo! Mail with you! Get it on your mobile phone. 
http://mobile.yahoo.com/maildemo 

Re: dataTable and commandButton question

Posted by Aaron Bartell <aa...@gmail.com>.
Here is a small helper class I wrote to do what you are asking.

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
public class UIHelper {
    public UIHelper() {
    }
    public static Object getReqMapObj(String obj) {
        return 
FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get(obj);
    }
    public static void addMessage(String componentName, String message) {
        FacesContext.getCurrentInstance().addMessage(componentName, new 
FacesMessage(message));
    }
}


To use it, it looks like this:

    public String deleteAction() {
        someObject = (SomeObject) UIHelper.getReqMapObj("varobject");
        return null;
    }


<x:dataTable var="varobject" value="#{OrderCtl.partsList}">
    <h:column>
        <f:facet name="header">
          <h:outputText value="Part Number"/>
        </f:facet>
        <h:outputText value="#{varobject.id}" styleClass="copy"/>
    </h:column>                                           
    <h:column>
        <f:facet name="header">
            <h:outputText value="Action"/>
        </f:facet>
        <h:commandButton action="#{OrderCtl.deleteAction}"/>
    </h:column>                                                          
                                                                        
                   </x:dataTable>   

HTH,
Aaron Bartell

Ray Clark wrote:

>I'm sure this must have been asked before but I can't
>find it in the archives.  So please forgive me if it
>has been asked before.
>
>I have a dataTable with a commandButton rendered on
>each row.  When the commandButton is pressed I need
>it's managed bean method to know which row the button
>was pressed for.  So how can the method know which row
>to process?
>
>Thanks,
>Ray
>
>
>		
>__________________________________ 
>Do you Yahoo!? 
>Take Yahoo! Mail with you! Get it on your mobile phone. 
>http://mobile.yahoo.com/maildemo 
>
>  
>

Re: dataTable and commandButton question

Posted by Grigoras Cristinel <gr...@wdd.ro>.
Hi,
In myfaces examples is an example about using x:updateActionListener, in 
dataTable.jsp,
you can set any property you want.
Is working for me.

        <h:column>
                       <f::facet name="header">
                          <h:outputText 
value="#{example_messages['label_country_name']}" />
                       </f::facet>
                       <x:commandLink action="go_country" immediate="true" >
                            <h:outputText value="#{country.name}" />
                            <!-- for convenience: MyFaces extension. 
sets id of current row in countryForm -->
                            <!-- you don't have to implement a custom 
action! -->
                            <x:updateActionListener 
property="#{countryForm.id}" value="#{country.id}" />
                       </x:commandLink>
                   </h:column>


Cristi


Heath Borders wrote:

> There are a few ways to do this.  The easiest is to get call:
>
> FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("var");
>
> where "var" is the name of your datatable's variable.
>
> On Apr 6, 2005 9:45 PM, *Ray Clark* <rcc1234567@yahoo.com 
> <ma...@yahoo.com>> wrote:
>
>     I'm sure this must have been asked before but I can't
>     find it in the archives.  So please forgive me if it
>     has been asked before.
>
>     I have a dataTable with a commandButton rendered on
>     each row.  When the commandButton is pressed I need
>     it's managed bean method to know which row the button
>     was pressed for.  So how can the method know which row
>     to process?
>
>     Thanks,
>     Ray
>
>
>     __________________________________
>     Do you Yahoo!?
>     Take Yahoo! Mail with you! Get it on your mobile phone.
>     http://mobile.yahoo.com/maildemo
>
>
>
>
> -- 
> -Heath Borders-Wing
> hborders@mail.win.org <ma...@mail.win.org> 



Re: dataTable and commandButton question

Posted by Heath Borders <he...@gmail.com>.
There are a few ways to do this. The easiest is to get call:

FacesContext.getCurrentInstance
().getExternalContext().getRequestMap().get("var");

where "var" is the name of your datatable's variable.

On Apr 6, 2005 9:45 PM, Ray Clark <rc...@yahoo.com> wrote:
> 
> I'm sure this must have been asked before but I can't
> find it in the archives. So please forgive me if it
> has been asked before.
> 
> I have a dataTable with a commandButton rendered on
> each row. When the commandButton is pressed I need
> it's managed bean method to know which row the button
> was pressed for. So how can the method know which row
> to process?
> 
> Thanks,
> Ray
> 
> 
> __________________________________
> Do you Yahoo!?
> Take Yahoo! Mail with you! Get it on your mobile phone.
> http://mobile.yahoo.com/maildemo
> 



-- 
-Heath Borders-Wing
hborders@mail.win.org

Antwort: dataTable and commandButton question

Posted by ch...@globus.ch.
I prefer:

        public String loadAttributgroup()
        {
                try
                {
                        // get Table
                        FacesContext t_context = 
FacesContext.getCurrentInstance();
                        UIData t_table = 
(UIData)t_context.getViewRoot().findComponent("SearchAGForm:AGSearchResultTable");
                        // get actual selected row from table
                        AttributgroupHeaderInterface t_attrib = 
(AttributgroupHeaderInterface)t_table.getRowData();
                        // do something else
                        t_attrib = 
AttributgroupBroker.current().loadAttribgroup(t_attrib.getA_AttrGrpNbr());
 
 
                }
                catch (CouldNotFindAGException e)
                {
                        FacesContext.getCurrentInstance().addMessage(null, 
new FacesMessage(FacesMessage.SEVERITY_ERROR, null, 
GMsgBean.getMyBundle().getString(AGMsgBean.COULD_NOT_FIND_AG)));
                }

                return "AGDetails";
        }

Chris





Ray Clark <rc...@yahoo.com>
07.04.2005 04:45
Bitte antworten an "MyFaces Discussion"
 
        An:     myfaces-user@incubator.apache.org
        Kopie: 
        Thema:  dataTable and commandButton question


I'm sure this must have been asked before but I can't
find it in the archives.  So please forgive me if it
has been asked before.

I have a dataTable with a commandButton rendered on
each row.  When the commandButton is pressed I need
it's managed bean method to know which row the button
was pressed for.  So how can the method know which row
to process?

Thanks,
Ray



__________________________________
Do you Yahoo!?
Take Yahoo! Mail with you! Get it on your mobile phone.
http://mobile.yahoo.com/maildemo