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.

Similar Messages

  • JSF Command Button and Command Links

    The main page of my JSF application has a Save button and Command Links. After making any changes on the main page the user should click Save before using any of the Links. Most of the time almost all users do this. However, some users are making changes then clicking a Link, thereby losing their changes.
    I could always execute my save method in the backing bean when a link is clicked, but, most of the time this would be doing a lot of processing which usually would not be necessry.
    Is their some way to check if any changes have been made and then doing the save only when necessary?
    Regards,
    Al Malin

    Anybody?
    What would be beneficial is something like this. If somehow it could be determined if any of the JSF fields on the page were modified. Then, in the backing bean method that handles the ActionEvents for the links, I would check if changes were made and, if so, call my save method.
    In other words is it possible to determine, in the backing bean, whether or not JSF fields have changed?
    Regards,
    Al Malin

  • Output Link and Command link problem

    I have this command link that I want to redirect to a certain url, a complete one with the Http://www.webpage.com.. and its value is Goto This Page..
    lets say I want it to pass through a certain backing bean before redirecting how am i supposed to do it...?
    before it was this simple:
                   <h:outputLink  value="http://www.wepbage.com">
                        <h:outputText value="Go to this page"/>
                   </h:outputLink> but this could says that the action attribute is not valid for an outputLink..
    thanks in advance.. :)

    Here's the stack trace but i can't seem to find which particular thing is causing this..
    16:30:33,921 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet
    threw exception
    java.lang.IllegalStateException: Cannot forward after response has been committe
    d
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationD
    ispatcher.java:313)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDis
    patcher.java:301)
    at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatc
    h(ServletExternalContextImpl.java:415)
    at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspV
    iewHandlerImpl.java:234)
    at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:
    352)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
    icationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
    ilterChain.java:173)
    at org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(Exte
    nsionsFilter.java:92)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
    icationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
    ilterChain.java:173)
    at org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(Exte
    nsionsFilter.java:92)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
    icationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
    ilterChain.java:173)
    at org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(Exte
    nsionsFilter.java:122)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
    icationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
    ilterChain.java:173)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
    lter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
    icationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
    ilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
    alve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
    alve.java:178)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
    yAssociationValve.java:175)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
    torBase.java:432)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
    e.java:74)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
    ava:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
    ava:105)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
    ve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
    a:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
    :869)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
    rocessConnection(Http11BaseProtocol.java:664)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
    int.java:527)
    at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWor
    kerThread.java:112)
    at java.lang.Thread.run(Thread.java:595)
    here's the bean
    public void link(){
             HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
             try {
                  searchController.setNewSearch(true);
                  response.sendRedirect("http://www.shipserv.com");
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
         }

  • Dynamically change and re-link shared object

    I work on a digital signal processing system that never shuts down. I am trying to develop the capability to dynamically change a processing algorithm. Where can I find more information on how to swap out a function or object method, relink and keep the system going with the new code?

    One more thing. This is in C or C++.

  • ADF Table and Command Link

    Hi,
    I am using version 11.1.1.5.0;
    I am facing an issue with a commandLink held in a table column and it's actionListener not firing ahead of the selectionListener of the table.
    The selectionListener of the table call a method in the backing bean to show/hide like a toggle affect. When the commadLink is visible and selected there is an actionListener to execute another method but the tables selectionListener takes precedence and the commandLink is hidden.
    Any suggestions?
    Regards
    Sun-E

    JSF Fragment code:
    <af:table value="#{bindings.clearedConditionsVO1.collectionModel}"
    var="row" rows="#{bindings.clearedConditionsVO1.rangeSize}"
    id="t4" rowSelection="single" styleClass="conTable"
    columnStretching="column:col2" horizontalGridVisible="false"
    verticalGridVisible="false" fetchSize="100"
    *selectionListener="#{pageFlowScope.consRIBean.cleConSelListner}"*
    contentDelivery="immediate" rowBandingInterval="0"
    autoHeightRows="100">
    <af:column id="col2">
    <af:panelGroupLayout id="pgl59" layout="vertical"
    styleClass="conditionsIter2" valign="top">
    <af:panelGroupLayout id="panelGroupLayout16" layout="vertical">
    <af:outputText id="outputText9" value="Affected plot(s):"
    styleClass="outstanding_right"/>
    <af:outputText value="#{row.bindings.Clearedplots.inputValue}"
    id="outputText10" styleClass="conText"/>
    </af:panelGroupLayout>
    <af:panelGroupLayout id="pgl63" layout="horizontal"
    styleClass="gap1"
    rendered="#{row.exCol eq 'true' ? 'true' : 'false'}">
    <af:outputText id="ot35" value="Creation date:"C
    <af:panelGroupLayout id="pgl64" layout="horizontal"
    styleClass="APdpr"
    rendered="#{row.exCol eq 'true' ? 'true' : 'false'}">
    <af:panelGroupLayout id="pgl65" layout="horizontal"
    halign="left">
    <af:outputText value="contact: #{row.bindings.Contact.inputValue}"
    id="ot37" styleClass="conText"/>
    </af:panelGroupLayout>
    <af:panelGroupLayout id="pgl66" layout="horizontal"
    halign="right">
    <af:image source="/images/arwlink_arrow.png" id="i7"
    shortDesc="back"/>
    <af:commandLink text="Contact" id="cl18"
    styleClass="arwlink"
              *actionListener="#{pageFlowScope.consRIBean.openPopUp}">*
    <af:setPropertyListener from="#{row.ConditionRiId}"
    to="#{pageFlowScope.conditionRIiD}"
    type="action"/>
    </af:commandLink>
    </af:panelGroupLayout>
    </af:panelGroupLayout>
    <af:outputText value="Job Ref: #{row.bindings.FusionJobId.inputValue}"
    id="ot38"
    rendered="#{row.exCol eq 'true' ? 'true' : 'false'}"
    styleClass="conText"/>
    <af:spacer width="10" height="10" id="s24"/>
    <af:panelGroupLayout id="pgl60"
    rendered="#{row.exCol eq 'true' ? 'false' : 'true'}">
    <af:image source="/images/arwlink_add.png" id="i8"
    shortDesc="Read more"/>
    <af:commandLink text="Read more" id="cl11"
    styleClass="arwlink"
    action="#{pageFlowScope.consRIBean.showClearConCollection}">
    <af:setPropertyListener from="#{row.ConditionRiId}"
    to="#{pageFlowScope.conditionRIiD}"
    type="action"/>
    </af:commandLink>
    </af:panelGroupLayout>
    </af:panelGroupLayout>
    </af:panelGroupLayout>
    <af:panelGroupLayout id="pgl68" styleClass="conditionsIter4"
    layout="vertical" valign="top"
    rendered="#{row.exCol eq 'true' ? 'true' : 'false'}">
    <af:outputText value="Documents tagged to this condition:"
    id="ot39" styleClass="DocCons"/>
    <af:panelGroupLayout id="pgl69" styleClass="gap1">
    <af:image source="/images/arwlink_arrow.png" id="i9"
    shortDesc="Send"/>
    <af:commandLink text="Send now" id="cl12" styleClass="arwlink"/>
    </af:panelGroupLayout>
    </af:panelGroupLayout>
    </af:panelGroupLayout>
    <af:spacer height="15" id="s13"/>
    </af:column>
    </af:table>
    </af:panelGroupLayout>

  • Must command link parameter variable SESSION Scope??

    I add a EJB Session Bean Method to my page which returns an array:
    public Province[] getProvinces();
    When you place the Session Bean to the page, it automatically creates a REQUEST SCOPE VARIABLE called "provinceRemoteGetProvincesResultBean" in the type of Province array. And it automatically creates a Data Table to display the results.
    Up to this point every thing's cool!! I can call the method properly, get the results and display without any problem.
    However when I try to create a COMMAND LINK to one of the columns of the TABLE (e.g. Province has a NAME column) I have a problem:
    <h:commandLink styleClass="commandLink" id="lnkName" action="#{pc_ProvinceManagement.doLnkNameAction}">
    <h:outputText id="otxName" value="#{varprovinceRemoteGetProvincesResultBean.name}" styleClass="outputText">
    </h:outputText>
    <f:param name="provinceId" value="#varprovinceRemoteGetProvincesResultBean.id}"></f:param>
    </h:commandLink>
    The problem is that this "provinceRemoteGetProvincesResultBean" is REQUEST scope and Command Link does not work with REQUEST Scope variables!!!
    I had similar examples before, when I used the command link with a REQUEST SCOPE variable, it didn't work. When I use it with a SESSION Scope variable it works.
    In this particular case, I cannot make the Province[] a SESSION SCOPE variable, because it's not a class!!! Therefore I need to create a new class containing a Province[] and make that class a SESSION SCOPE variable, which makes things quite complicated!!
    IS IT TRUE THAT COMMAND LINK PARAMETERS MUST BE SESSION SCOPE?????

    Line 4: <f:param name="provinceId" value="#varprovinceRemoteGetProvincesResultBean.id}"></f:param>
    value="#varpro... >>> value="#{varpro...                                                                                                                                                                                                                                                                                       

  • Programatically adding command links in ADF Tree?

    Hi,
    I am using Build JDEVADF_11.1.1.3.PS2_GENERIC_100408.2356.5660. Can anyone please provide me some sample code for programatically adding dynamically generated ADF command links in the nodes of ADF Tree(Tree nodes in it are created using View Object - Drag & drop of data control). Now how can i add links in the nodes generated.
    Thanks,
    Vik

    Hi,
    try setting partialSubmit=true on the command link. Just in case it fires the action method before the context menu displays
    Frank

  • Generating dynamic command links in data table

    Hi,
    I have a requirement to generate dynamic number of columns in a datatable. Also these columns should contain a command link.
    I have written following piece of code to do so...
    public UIData getDataTableBinding()
         UICommand comm = null;
         UIColumn col;
         UIOutput out = null;
         Application app = app = FacesContext.getCurrentInstance().getApplication();
    // Suppose I want to generate 7 columns
         for(int j = 0; j < 7; ++j) {
         out = new UIOutput();
         col = new UIColumn();
         comm = new UICommand();
         ValueBinding vb = app.createValueBinding("#{" + j + "}");
         out.setValueBinding("value", vb);
         out.setRendererType("javax.faces.Text");
         comm.setRendererType("javax.faces.Link");
    comm.getChildren().add(out);
         MethodBinding mbButton = app.createMethodBinding("#{pc_File1.doLink1Action}",
    null);
         comm.setAction(mbButton);
         col.getChildren().add(comm);
         dataTableTemp.getChildren().add(col);
         return dataTableTemp;
    I have bound the "binding" attribute of the data table to getDataTableBinding()
    method.
    If I remove all the references to UICommand i.e comm variable, table is displayed properly, but if
    I try to include a command link component as mentioned above I get "Assertion failed error"
    SRVE0068E: Could not invoke the service() method on servlet Faces Servlet. Exception thrown :
    javax.servlet.ServletException: javax.faces.el.EvaluationException: Error getting property
    'dataTableBinding' from bean of type pagecode.File1: javax.faces.FacesException: Assertion Failed
         at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:638)
         at com.ibm._jsp._File1._jspService(_File1.java:92)
         at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:88)
    Any kind of help on this issue would be appreciated,
    Thanks in advance,
    Raina

    Hi,
    I solved my problem just by replacing UIOutput component with HtmlOutputText component and then making it as a child component of UICommand component.
    Now I am facing a new problem. Whenever I try to refresh the page I get following exception
    "SRVE0026E: [Servlet Error]-[Faces Servlet]: java.lang.IllegalStateException: Duplicate component ID 'form1:table1:cmd0' found in view."
    I am explicitly setting the component id of the UICommand component using the setViewId() method.
    This problem is observed only when I refresh the page. In case I navigate to another page and then again come back to this current page, then I don't get this exception.
    Your help would be appreciated,
    Raina

  • 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 :)

  • 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.

  • 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.

  • 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 pages / parameter and navigation links

    hi all!
    my goal is to develop a portal page , with a naviagtion region on the left side (this is a dynamic page in which links are defined) and on the right side there should be the main region (also a dynamic page , with parameter input). Now, it should be possible to pass different parameters to the main region dynamic page, by clicking on the different links in the menu region. Each link should pass an other parameter to the main dynamic page. How is that possible ? (using as10g)
    regards,
    katharina

    I don't realy get the requirement...
    Basicly each space has their own navigation model. I don't know if it's possible to share navigation models from one space to another...

  • I want to run the h:outputText in a loop and with command link

    I have a managed bean property of type Collection (ArrayList). These collection elements should be displayed a series of hyperlinks separated by commas.
    can i refer the collection element with an index from h:outputText tag
    Thanks in advance.

    Can I achive this by using JSTL core tags and outputText. Like using c:foreach and then render the command link.
    how can we render outputText with value as a collection.
    Thanks.

Maybe you are looking for