Command Link as a row of a datatable in JSF

Hi All,
I am new to JSF. I have a Datatable with n number of rows.
I would like to have a command Link in each of the rows, so that when i click the command link i should get the data of the entire row in my edit page.
Can anyone suggest how can i achieve this.
Regards
SN

Hi,
Do following:
1- add a datatable in your page and fill it with data comes from database(Assume u have no problem with datatable)
2- add a column as commandLink in data table. e.g.
<h:column>
<f:facet name="header">
<h:outputText value="name" />
</f:facet>
<t:commandLink action="editObject" immediate="true" >
<h:outputText value="#{theobject.name}" />
<t:updateActionListener property="#{objectForm.id}" value="#{objectDto.id}" />
</t:commandLink>
</h:column>
in this code:
"name" is header of column,
"editObject" is defined in navigation rule to navigate to edit page, lets say object form.
"theobject.name" the value that mouse gets finger over it!
"objectForm.id" the pointer to an "id setter" of a managed bean (named objectForm) defined in faces-config.xml. In this setter you can load corresponding data from database
"objectDto.id" the pointer to an "id getter" of a managed bean (named objectDto) defined in faces-config.xml. this getter return the id of the entity row you clicked on.
3- Clearly, you need to defined all managed beans, and dont forget to have a customized setter for id of objectForm (setId) to load the entity from database and fill all editable properties(as you like) in this function (setId).
4- you need a JSF page to redirect to it for editing properties and feed by objectForm
5- Thats it :)

Similar Messages

  • Display images in rows & columns using dataTable in JSF 2.0, netbeans 6.9.1

    Hi,
    I have to display only images on a web page in JSF2.0 in Netbeans. I am using datatable and column to do so. But there is one problem.
    All images are display only in single column(i.e. vertically). I want to display in rows and columns not only column.
    e.g. One row will have atleast 3 images and more rows like this.
    Which attribute should i use of datatable? or should i use some other tag?
    My code is:
    <h:dataTable var="images"
    value="#{jsfMBean.allImages}"
    rules="none"
    cellpadding="20"
    border="0" >
    <h:column>
    <h:graphicImage value="faces/WEB-INF/upload/#{images.picid}" width="300px" height="100px" />
    </h:column>
    </h:dataTable>
    Thanks.
    NetBeans 6.9.1
    JSF 2.0 with facelets
    glassfish 3.0
    Enterprise java beans
    PrimeFaces 3.0

    I believe you are looking for the panelgrid, not the datatable.
    Note that there are a few useful websites online that list the available JSF tags plus their properties, such as these:
    http://www.horstmann.com/corejsf/jsf-tags.html
    http://www.exadel.com/web/portal/jsftags-guide

  • Command link usage.

    Hi,
    I am using </h:commandLink > tag to generate command links in each row of <h:table> tag. simple code i am using:
    <h:dataTable value="#{projectBean.projects}" var="projectsData">
    <h:column>
    <f:facet name="header">Name</f:facet>
    <h:outputLink value="#{projectBean.getProjectDetails">
    <h:outputText value="#{projectsData.name}"/>
    <f:param name="pId" value="#{projectsData.projectId}"/>
    </h:outputLink>
    </h:column>
    <h:column>
    <f:facet name="header">Date</f:facet>
    <h:outputText value="#{projectsData.stDate"/>
    </h:column>
    </h:table>
    I am able to generat the link with the param value passing but the action method is not getting invoked on press of the link, could any one help me in usage of commandlink tag in invoking action page.
    Regards
    Mruthyunjaya

    I have used the command link instead of outLink also the tag is under form tag only but still the link action is not executed.
    if i changed the bean to session scope it is running fine, but as the bean is session scope it is displaying old values along with new values, i.e. the form is displayed with repeated values.
    can some one help me in solving this problem.
    thanks
    Mruthyunjaya

  • Command Link usage in JSF datatable

    Hi,
    Following is my requirement. Can any one help me in resolving the issue.
    I hava a JSF page which displays a datatable. One of the columns in the datatable displays a command link. When the user clicks the link in a particular row. Details correpsonding to the particular row have to be displayed in another page. I am using action attribute to perform the navigation from first page to next. Inside action method in the backing, is there any other means to get the row data from the datatable for which the link is clicked.
    Please help.

    You may find this article useful: http://balusc.blogspot.com/2006/06/using-datatables.html

  • Command Link inside of datatable

    I have the following problem when I put a command link inside a datatable.
    The action or actionlisteners never get called. Now here is the funny thing.
    1. If I move the action link outside the datatable it works.
    2. if I change the scope of the bean to session it works
    3. if the datatable contains more than 1 row it works
    The last one tells me this is a bug.
    To test this I change the sql query to limit the result so 1 row would be returned.
    The sql query returns a CachedRowSetImpl
    I believe this is a bug.
    <h:dataTable rows="6" first="0" id="table" binding="#{event.eventdata}" value="#{event.eventdetails}" var="eventdetail">
    <h:column>
    <h:commandLink value="#{eventdetail.title}" action="#{event.resaveEventaction}" actionListener="#{event.resaveEventdetails}" id="test" >
    </h:commandLink>     
    </h:column>
    <h:column>
    </h:dataTable>

    Here is some additional information that makes this more confusing.
    The following code is used to populate the datatable
    public CachedRowSetImpl getEventdetails(){
         CachedRowSetImpl rs2 = null;
         String selectedeventmy = selectedevent;
         int rowcount = 0;
         try { 
              sql = "SELECT * FROM event where eventid='"+selectedeventmy+"' ";
              rs2 = RunQuery.mysql(sql);
              rowcount = rs2.size();
         } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
         return rs2;
    where RunQuery.mysql is
    public class RunQuery {
         public static CachedRowSetImpl mysql(String sql) throws Exception {
              CachedRowSetImpl crset = null;
              InitialContext initCtx = new InitialContext();
              Context envCtx = (Context) initCtx.lookup("java:comp/env");
              try {
                   DataSource ds = (DataSource) envCtx.lookup("jdbc/associations");
                   Connection conn = null;
         Statement stmt = null;
         conn = ds.getConnection();
         stmt = conn.createStatement();
         stmt.execute(sql);
         ResultSet rs = stmt.getResultSet();
         crset = new CachedRowSetImpl();
         crset.populate(rs);
         rs.close();
         stmt.close();
         conn.close();
              } catch (Exception e) {
                   System.out.println(e.getMessage());
              return crset;
    if I replace the line
    String selectedeventmy = selectedevent;
    with String selectedeventmy = "61";
    it works properly.
    selectedevent is populated from the following triggered by another action event on another page. ? The funny thing is if the result set returns more that 1 row all works ok.
    public String viewDetails(){
         System.out.println("Running view Details");
         int selectedrow = eventlist.getRowIndex();
         Object selected = eventlist.getRowData();
         Map rowdata = (Map) selected;
         selectedevent = rowdata.get("eventid").toString();
         System.out.println("Selected Event:"+selectedevent);
         outcome="eventdetails";
         return outcome;
    }

  • Dynamic datatable and command link

    I'm having a problem creating CommandLink's automatically. What we have is a tag, which can contain a set of data. We need this on several locations, so we have to create a datatable dynamically. When you press a link, it should be possible to retrieve the ID of the component on that specific row.
    The problem is, we can create the table with the necessary data. When I construct the column with the ID (and the link), it fails.
    Code:
    HtmlCommandLink link = new HtmlCommandLink();
    Application app = FacesContext.getCurrentInstance().getApplication();
    ELContext elContext = FacesContext.getCurrentInstance().getELContext();
    ValueExpression ve = app.getExpressionFactory().createValueExpression(elContext,"${" + TABLE_VAR_NAME + "." + property + "}", Object.class);
    link.setValueExpression("value", ve);
    link.getAttributes().put("rowId", ve.getExpressionString() );
    link.addActionListener(
        new ActionListener(){
         public void processAction(ActionEvent arg0)
              throws AbortProcessingException {
              LOG.info(">>>>>>>>>>>>> Linked pushed !!"  +
              arg0.getComponent().getAttributes().get("rowId"));
    selectColumn.getChildren().add(link);
    datatable.getChildren().add(selectColumn);The rowId is always #{row.code}, instead of the actual data. Is there a way to create a command link dynamically, press it and retrieve the ID of that field? That expression should be evaluated at runtime and added to the datatable, but that doesn't happen apparently.

    I've read your article, but I didn't find anything I could use. Facing a deadline and don't really have time to try out multiple (possible) solutions. The problem is that all the examples I can find point to MethodBinding, but I don't need that. I just need to get the ID of the row that was clicked, nothing more.
    This works fine:
    link.setValueExpression("value", ve);I don't see why the other expression isn't evaluated.
    I can do getParent().getParent() to get a reference to the DataTable, but the datamodel on that object is empty btw.

  • Command links in h:datatable not working

    I have some command links in h:datatable which are not working. When I click the command link all I get is a referesh page(same page is displayed with datatable values as null). But when I put command link outside h:datatable, the navigation takes place properly. Any idea what could be worng

    You can try using t:dataTable from tomahawk.jar, instead of the h:dataTable. Make the following changes in your code.
    1. Add the taglib uri in your JSP as,
    <%@ taglib uri = "http://myfaces.apache.org/tomahawk" prefix="t" %>
    2. Add the tomahawk-1.1.3.jar to your WEB-INF/lib folder.
    3. Instead of using h:dataTable, use t:dataTable.
    4. After the form save your bean's state as,
    </h:form>
    <t:saveState id="viewForm" value="#{stateBean}"/>
    Here, id can be any name and the value should be the name of your bean, how u have used in your JSP.
    I hope this will help you.

  • Getting selected row for command link in af:table

    Hi
    I have a h:commandLink in a column of my af:table. When it is clicked, I need to get the selected row data.
    I know the documentation says use setCurrentRowValue method, but I am not using the Data Control Palette - I get the data fromt the database using code in the BackingBean.
    Is there any other way? Pls help.

    Yes, I got it. But my method gets the data in the selected row, not the rowKey
    First I used af:commandLink instead of h:commandLink and then used af:setActionListener based on an example in the jDeveloper Help. I had to change it a bit since I am not using DCP or bindings.
    This is the sample from Help, hope it helps!
    SF Page Code for a Command Link Using a setActionListener Component <af:commandLink actionListener="#{bindings.setCurrentRowWithKey.execute}"
    action="edit"
    text="#{row.svrId}"
    disabled="#{!bindings.setCurrentRowWithKey.enabled}"
    id="commandLink1">
    <af:setActionListener from="#{row.svrId}"
    to="#{userState.currentSvrId}">
    </af:commandLink>

  • JSF Command Link inside DataTable has to be clicked twice in order to work

    I currently have a command link inside of a dataTable. However, when I go to the page and click the link nothing happens. It appears that the page is refreshed but looking at the logs nothing is done. However, if you click the same link again everything is updated properly. How do I get the command link to work properly? And, I have everything operating in the session scope.

    sdgorham wrote:
    No I do not have h:messages on the page. Just add it for debugging purposes. There might have been a validation or conversion error occurred which wasn't 'catched' by any h:message.
    Unfortunately, upgrading to another version isn't an option at the moment. OK, I checked the MyFaces page and 1.1.5 is indeed the latest JSF 1.1 implementation.
    Is there any other possible solutions that are more like a hyperlink than the command button. What exactly is causing the problem that I described?Have you tried if it works with a button or not? Only then we can be more sure about the cause of the problem.

  • Invoke Edit action once I click on Command Link,,,,,, Help me out in

    Hi
    I am having a datatable , which consists of of ROWS, & Columns
    when I click on that command link, it shoud open a property page with all the bean data populated,,,, "I am using the same Add property page for edit also", Now I am modifying the data and click on "Add", Now It should call[b] UpdateQuery ie, ModifyServiceDomain instead of Insert Query "Add ServiceDomain".., Tell me how to do that...
    How to solve the above problem..
    Java Class:
    public class ServiceDomainEventHandler {
        * This method is used to modify a service domain from the Web UI.
        * @return "succuess", if a service domain can be modified successfully,
        *         "failure", if a service domain can not be modified
       public String modifyServiceDomain()
          log.debug( "Into modifyServiceDomain method" );
          String returnStr = "edit_SD";
          FacesContext facesContext = FacesContext.getCurrentInstance();
          ExternalContext externalContext = facesContext.getExternalContext();
          HttpServletRequest request = (HttpServletRequest) externalContext
                .getRequest();
          String serviceDomainName = (String) request
                .getParameter( "serviceDomainName" );
          ServiceDomain servicedomain = null;
          try
             servicedomain = new ServiceDomainDbAccess()
                   .getServiceDomainByName( UIConstants.WHICH_DB,
                         serviceDomainName );
          catch (SQLException pe)
             pe.printStackTrace();
          try
             servicedomain = new ServiceDomainMgerImpl().getServiceDomainById(
                   UIConstants.WHICH_DB, Integer.parseInt( servicedomain
                         .getId() ) );
             if (servicedomain != null)
                facesContext.getExternalContext().getRequestMap().put(
                      "ServiceDomain", servicedomain );
             else
                log.debug( "Unable to obtain the ServiceDomain!" );
          catch (NrsProvisionException pe)
             returnStr = "failure";
             handleUIErrors( facesContext, pe );
          log.debug( "modifyServiceDomain method return value: " + returnStr );
          return returnStr;
        * This method is used to add a service domain from the Web UI.
        * @return "succuess", if a service domain can be added successfully,
        *         "failure", if a service domain can not be added
       public String addServiceDomain()
          log.debug( "Into addServiceDomain method" );
          String returnStr = "success";
          FacesContext facesContext = FacesContext.getCurrentInstance();
          ExternalContext externalContext = facesContext.getExternalContext();
          Map requestMap = externalContext.getRequestMap();
          ServiceDomain curServiceDomain = (ServiceDomain) requestMap
                .get( "ServiceDomain" );
          try
             new ServiceDomainMgerImpl().addServiceDomain( curServiceDomain );
          catch (NrsProvisionException pe)
             returnStr = "failure";
             handleUIErrors( facesContext, pe );
          log.debug( "addServiceDomain method return value: " + returnStr );
          return returnStr;
    Jsp Page:
    <%@ page language="java" %>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
    <f:view>
         <f:loadBundle basename="com.nortel.ems.mgmt.nrsm.messages.ServiceDomainMessageBundle" var="bundle"/>
         <%
              String path = request.getContextPath();
              String basePath =
              request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
         %>
         <html>
              <head>
                   <base href="<%=basePath%>">
                   <link REL="stylesheet" TYPE="text/css" HREF="<%= request.getContextPath()%>/css/nrsStyle.css">
                   <title>Service Domain add page</title>
              </head>      
              <body>
              <f:verbatim>
              <div
                   style="height:500px;overflow: scroll; margin-top: -2px;margin-bottom: -2px;border: 1px solid #CCCCCC; border-top:none;width:100%">
         </f:verbatim>
                   <h:panelGroup id="SDPanel" styleClass="panelGroup">
                        <h:form id="SDForm" >                    
                             <h:panelGroup id="SDSubPanel" >
                               <h:panelGrid id="SDPanelGrid" styleClass="panelGrid"
                                              columnClasses="panelGridCol1,panelGridCol2,panelGridCol3,panelGridCol4"
                                            headerClass="tableHeaders" columns="4">   
                                    <f:facet name="header">     
                                         <h:outputText id="SDHead" value="#{bundle.serviceDomainAdd}"/>   
                                    </f:facet>                                                
                                  <h:message for="SDForm" styleClass="fieldErrors" />
                                  <h:outputText id="BlankCol1" value=""/>                                 
                                  <h:outputText id="BlankCol2" value=""/>                                 
                                  <h:outputText id="BlankCol3" value=""/>                                                               
                                    <h:outputText id="SDName" value="#{bundle.serviceDomainName}"/>
                                    <h:inputText id="name" value="#{ServiceDomain.name}" />
                                  <h:outputText id="Mandatory" value="*"/>                                 
                                    <h:message for="name" styleClass="fieldErrors" />
                                    <h:outputText id="SDDesc" value="#{bundle.serviceDomainDesc}"/>
                                    <h:inputTextarea id="description" value="#{ServiceDomain.description}" />   
                                  <h:outputText id="BlankCol4" value=""/>                                 
                                    <h:message for="description" styleClass="fieldErrors" />
                               </h:panelGrid>            
                             </h:panelGroup>
                   <h:panelGroup styleClass="buttonpanelright">
                        <h:commandButton id="AddSD" action="#{ServiceDomainEventHandler.addServiceDomain}" value="#{bundle.serviceDomainSave}"/>
                             <h:commandButton id="CancelSD" action="#{ServiceDomainEventHandler.cancel}" value="#{bundle.serviceDomainCancel}" />
                   </h:panelGroup>
              </h:form>
         </h:panelGroup>
         <h:outputText id="SDMandatoryIndicator" styleClass="mandatory" value="#{bundle.mandatory}"/>
         <f:verbatim>
              </div>
         </f:verbatim>
         </body>
         </html>
    </f:view>[code[/code]]

    update your adobe reader here, http://get.adobe.com/reader/
    untick unwanted tag-along ware.

  • Getting the selected row from a datatable -- URGENT

    Hi,
    I am facing the following problem with a datatable. The datatable does not have any Input components like CommandLink, Buttons, Radio Buttons and Checkbox. Even I cannot use the hidden Command Link.
    One solution is to use a input hidden variable which can hold the curent row Id. But in this case too, how to get the control in a backing bean method is not clear to me.
    Please guide me how to get the data of the selected row in the backing bean.
    Thanks in advance......
    VJain.

    I again explain my problem:
    I need to get the Current Selected Row onclick of any row in a Datatable. But the datatable is restricted not to have any CommandLink or Input component so that I can generate the action to go to any method on a backing bean as shown below.
    <h:dataTable id="dTable" value="#{Bean.myList}" var="currentRow" >
    <h:column id="row1">
    <h:outputText value="# currentRow.productNumber}"></h:outputText>
    </h:column>
    <h:column id="row2">
    <h:outputText value="# currentRow.productName}"></h:outputText>
    </h:column>
    </h:dataTable>
    As shown above I cannot use any commandButton or CommandLink to submit the page. All I can do is to generate any onclick function on Table and do something with it. But not sure how to do it.
    Now I want the productNumber of the selected row in any method say getCurrentRowId of the Bean.
    I hope the problem must be clear now....
    Thanks for your quick reply..
    VJ

  • Command Link problem-Urgent

    Hi
    I am having Tabbedpane, under that I am including three jsp files...
    which contains a dataTable , having one column data as a commandLink which inturn opens a Edit page.
    It is working with out tappedpane, When I click Command link for Edit
    in TabbedPane, I am getting java script error saying "Error on page".
    When I submit the action from commandLink from an individulal page .
    Its working fine.
    anyone help me in resolving this issue...?

    Update your Ie, or maybe you have some option that the others don't have.

  • Command link in adf pivot table

    Hi,
    I Created one View Object (WrkVOR) Based on below query
    Select Desc1,Desc2 ,Date,Sum(Amount) From populate_wrk Group by Desc1,Desc2 ,Date
    Based on View Object we created pivot table
    Rows - Desc1 ,Desc2
    Column - Date
    Amount will come under each date (Like Matrix report)
    Up to It is working fine
    i added a command link on data(Amount) when i click the command link i am getting below error
    DVT-2015 Slice 1 Exceeds boundary -3
    please help....
    Thanks
    shk

    Hi,
    the real problem of the original poster seems to be <af:commandLink text="#{row.GlobalDealId}" id="cl1" action="createMDM" immediate="true" partialSubmit="true"> having immediate set to true in which case the request goes from restore view to render response. You usually use immediate=true on a command item to cancel an action (bypassing all the other JSF lifecycle steps).
    Peter551059,
    you don't give us much information about your case. So if the problem is IE9 and you verified IE9 is supported for the version of JDeveloper you use, then - in case you have a support contract - my best advise is to file a service request and have support looking at it just in case you hit a defect that should be filed as a bug
    Frank

  • Command link in adf table is not working..

    Hi All,
    I am having ADF Table, in that one column is with command link and,if click on commnad link it is not going to coorsponding action or actionListener methods of bean. If i give same command link out side of the table it working fine.But i have to pass some perameters on click of button.
    I am getting same problem in many places , if i delete the page and page-def files again if i create some times it is working but some times not working. Is there any specific reason for this.Following is the code snippet...
    <af:column sortProperty="GlobalDealId" sortable="false"
    headerText="#{bindings.DsaDealsResultsVO1.hints.GlobalDealId.label}"
    id="c8">
    <af:commandLink text="#{row.GlobalDealId}" id="cl1" action="#{pageFlowScope.editProfileCompleteness.sample}" immediate="true" partialSubmit="true">
    <af:setActionListener from='"#{row.GlobalDealId}"'
    to='"#{pageFlowScope.globalDealId}"'/>
    <af:setActionListener from='"#{row.CustName}"'
    to='"#{pageFlowScope.custName}"'/>
    <af:setActionListener from='"#{row.IsSaDeal}"'
    to='"#{pageFlowScope.isSaDeal}"'/>
    </af:commandLink>
    </af:column>
    Even i tried with out immediate="true" partialSubmit="true" also.
    And i set ChangeventPolicy = ppr for Iterator in page defnation file.
    Awaiting for ur reply.

    Hi,
    the real problem of the original poster seems to be <af:commandLink text="#{row.GlobalDealId}" id="cl1" action="createMDM" immediate="true" partialSubmit="true"> having immediate set to true in which case the request goes from restore view to render response. You usually use immediate=true on a command item to cancel an action (bypassing all the other JSF lifecycle steps).
    Peter551059,
    you don't give us much information about your case. So if the problem is IE9 and you verified IE9 is supported for the version of JDeveloper you use, then - in case you have a support contract - my best advise is to file a service request and have support looking at it just in case you hit a defect that should be filed as a bug
    Frank

  • Command Link inside table to external website in popup window

    Hi,
    I am trying to have a command link inside a table which is on the tables id. I know that if I have control of the destination page I can use setCurrentRowKeyValue. However I do not have control of the external website. So I cannot add it into my faces-config.xml file? I have tried putting a GoLink and a GoButton but I get the following Illegal character in fragment error, when I put my destination URL in. An example of the format the URL is:
    http://www.bbc.co.uk/radio?&music=#{row.PrimaryKey}&adf=123
    Where I am adding in #{row.PrimaryKey} which is the Id of the row. I would like to have the new page opened into a pop up window if this is possible.
    I am not sure if this can be done in the backing bean or whether my approach is the correct one?
    Many Thanks
    Steve

    something like...
    <af:goLink text="#{row.PrimaryKey}"
               destination="http://www.bbc.co.uk/radio?&amp;music=#{row.PrimaryKey}&amp;adf=123"
               targetFrame="_blank"/>Regards,
    Neeraj

Maybe you are looking for

  • Performance issue in the Incremental ETL

    Hi Experts, we have performance issue and the task "Custom_SIL_OvertimeFact" is taking more than 55 mins. this tasks reads the .csv file coming from business every 2 weeks with a few rows of data updated and appended. every day this tasks runs and sc

  • When locating a song via "Artists," the menu goes straight to albums

    I think this has to do with my recent iPod update, as it didn't used to happen- when I scroll through the artist names all are present- but when you select an artist, for many of them (not all, not sure why not) it goes straight to the album of that

  • Internal error - code 302 on setup

    WRT610N router - Vista operating system I had to format and reinstall Vista and am attempting to re-install the setup software that came with my router.  Each time I try, the installation stops and an error message tells me there has been an internal

  • JDeveloper 11.1.2.3: panelDashboard, ways to maximize btf panelbox

    I've been looking at couple of examples on how to use the paneldashboard and panelbox component. I have been trying to implement an approach which requires minimal coupling between a single DashboardApp and various ChildApps. I have a panelbox (in Da

  • Toplink 1..m finder problem

    I have a problem with a finder which is attempting to traverse a 1..m relation ship between two ejb's. I have tried expressing the finder using both EJBQL and the expression framework, but am getting the same error in both cases. I have two entity be