3 Replies Latest reply on Feb 10, 2009 4:24 PM by ips

    custom component - HtmlLink works, HtmlCommandLink and HtmlA

    jsutherland

      I am developing a Seam web application with 2.0.0.GA and I am writing a custom facelets component that instantiates seam and a4j components and renders itself.

      Everything seems to be working fine but I have a problem where HtmlAjaxCommandLink (and HtmlCommandLink) will not work to call an action method I have set using setActionExpression, though switch to HtmlLink and it works fine.

      HtmlAjaxCommandLink link = new HtmlAjaxCommandLink();
      link.setId("link-"+id);
      div.getChildren().add(link);
      link.setParent(div);
      link.setValue(name);
      link.setReRender("some-id");
      MethodExpression methodExpression FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{SomeAction.editAction("+id+")}", null, new Class<?>[0]);
      link.setActionExpression(methodExpression);
      


      When I click this link it seems to rerender the part of the page it's supposed to, however the action is not called. This happens similarly when the link is defined as HtmlCommandLink except the page is reloaded.

      When I define the link as HtmlLink (seam link) it works fine and the action is called, but the page is reloaded, and I am trying to do it with an ajax rerender.

      One hint is about my problem is that when the a4j;outputPanel that I am rerendering is not set and ajaxRendered=false than the link doesn't rerender anything and a4j log output is as follows:

      debug[18:02:53,999]: Have Event [object Object] with properties: target: http://localhost:8080/calendar/home.seam#, srcElement: undefined, type: click
      debug[18:02:54,000]: NEW AJAX REQUEST !!! with form :j_id177
      debug[18:02:54,017]: Append hidden control j_id177 with value [j_id177] and value attribute [j_id177]
      debug[18:02:54,018]: Append hidden control autoScroll with value [] and value attribute []
      debug[18:02:54,018]: Append hidden control j_id177:_idcl with value [] and value attribute []
      debug[18:02:54,019]: Append hidden control j_id177:_link_hidden_ with value [] and value attribute []
      debug[18:02:54,019]: Append hidden control javax.faces.ViewState with value [_id1] and value attribute [_id1]
      debug[18:02:54,020]: parameter j_id177:edit-event-1 with value j_id177:edit-event-1
      debug[18:02:54,027]: Start XmlHttpRequest
      debug[18:02:54,028]: Reqest state : 1
      debug[18:02:54,029]: QueryString:
      AJAXREQUEST=_viewRoot&j_id177=j_id177&autoScroll=&j_id177%3A_idcl=&j_id177%3A_link_hidden_=&javax.faces.ViewState=_id1&j_id177%3Aedit-event-1=j_id177%3Aedit-event-1&
      debug[18:02:54,040]: Reqest state : 1
      debug[18:02:54,356]: Reqest state : 2
      debug[18:02:54,358]: Reqest state : 3
      debug[18:02:54,359]: Reqest state : 4
      debug[18:02:54,359]: Reqest end with state 4
      debug[18:02:54,359]: Response with content-type: text/xml;charset=UTF-8
      debug[18:02:54,360]: Full response content:
      <?xml version="1.0"?> <html xmlns="http://www.w3.org/1999/xhtml">
      <head><link type="text/css" rel="stylesheet" href="/calendar/a4j_3_1_3.GAcss/toolBar.xcss/DATB/eAF7WBtjAQAF7wHz" />
      <link type="text/css" rel="stylesheet" href="/calendar/a4j_3_1_3.GAorg/richfaces/renderkit/html/css/msg.css" />
      <link type="text/css" rel="stylesheet" href="/calendar/a4j_3_1_3.GAorg/richfaces/renderkit/html/css/msgs.css" />
      <link type="text/css" rel="stylesheet" href="/calendar/a4j_3_1_3.GAorg/richfaces/renderkit/html/css/calendar.xcss/DATB/eAF7WBtjAQAF7wHz" />
      <link type="text/css" rel="stylesheet" href="/calendar/a4j_3_1_3.GAcss/simpleTogglePanel.xcss/DATB/eAF7WBtjAQAF7wHz" />
      <link type="text/css" rel="stylesheet" href="/calendar/a4j_3_1_3.GAcss/tabPanel.xcss/DATB/eAF7WBtjAQAF7wHz" />
      
      <script type="text/javascript" src="/calendar/a4j_3_1_3.GAorg.ajax4jsf.javascript.AjaxScript"> </script><script type="text/javascript"
      src="/calendar/a4j_3_1_3.GAorg/ajax4jsf/javascript/scripts/form.js"> </script><script type="text/javascript"
      src="/calendar/a4j_3_1_3.GAorg.ajax4jsf.javascript.PrototypeScript">
      </script><script type="text/javascript"
      src="/calendar/a4j_3_1_3.GAorg/richfaces/renderkit/html/scripts/events.js">
      </script><script type="text/javascript"
      src="/calendar/a4j_3_1_3.GAorg/richfaces/renderkit/html/scripts/utils.js">
      </script><script type="text/javascript" src="/calendar/a4j_3_1_3.GAorg/richfaces/renderkit/html/scripts/json/json-dom.js">
      </script><script type="text/javascript" src="/calendar/a4j_3_1_3.GAorg/richfaces/renderkit/html/scripts/scriptaculous/effects.js">
      </script><script type="text/javascript" src="/calendar/a4j_3_1_3.GAorg/richfaces/renderkit/html/scripts/jquery/jquery.js">
      </script><script type="text/javascript" src="/calendar/a4j_3_1_3.GAorg/richfaces/renderkit/html/scripts/JQuerySpinBtn.js">
      </script><script type="text/javascript" src="/calendar/a4j_3_1_3.GAorg/richfaces/renderkit/html/scripts/calendar.js">
      </script><script type="text/javascript" src="/calendar/a4j_3_1_3.GAorg.ajax4jsf.javascript.ImageCacheScript">
      </script><script type="text/javascript" src="/calendar/a4j_3_1_3.GAorg/richfaces/renderkit/html/scripts/browser_info.js">
      </script><script type="text/javascript" src="/calendar/a4j_3_1_3.GAscripts/simpleTogglePanel.js"> </script>
      <script type="text/javascript" src="/calendar/a4j_3_1_3.GAscripts/tabPanel.js">
      </script><meta name="Ajax-Update-Ids" content="" /><title></title></head><body>
      <span id="ajax-view-state">
      <input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="_id1" />
      </span><meta id="Ajax-Response" name="Ajax-Response" content="true" /></body></html>
      debug[18:02:54,361]: Header Ajax-Expired not found, search in <meta>
      debug[18:02:54,361]: search for elements by name 'meta' in element #document
      debug[18:02:54,366]: getElementsByTagName found 2
      debug[18:02:54,366]: Find <meta name='Ajax-Update-Ids' content=''>
      debug[18:02:54,367]: Find <meta name='Ajax-Response' content='true'>
      debug[18:02:54,367]: Header Ajax-Update-Ids not found, search in <meta>
      debug[18:02:54,368]: search for elements by name 'meta' in element #document
      debug[18:02:54,372]: getElementsByTagName found 2
      debug[18:02:54,372]: Find <meta name='Ajax-Update-Ids' content=''>
      warn[18:02:54,373]: No information in response about elements to replace
      debug[18:02:54,373]: call getElementById for id= ajax-view-state
      debug[18:02:54,374]: Hidden JSF state fields: [object HTMLSpanElement]
      debug[18:02:54,374]: Namespace for hidden view-state input fields is undefined
      debug[18:02:54,375]: search for elements by name 'input' in element span
      debug[18:02:54,378]: getElementsByTagName found 1
      debug[18:02:54,379]: Replace value for inputs: 37 by new values: 1
      debug[18:02:54,379]: Input in response: javax.faces.ViewState
      debug[18:02:54,381]: Found same input on page with type: hidden
      debug[18:02:54,382]: Found same input on page with type: hidden
      debug[18:02:54,383]: Found same input on page with type: hidden
      debug[18:02:54,384]: Found same input on page with type: hidden
      debug[18:02:54,384]: Found same input on page with type: hidden
      debug[18:02:54,385]: Found same input on page with type: hidden
      debug[18:02:54,386]: Found same input on page with type: hidden
      debug[18:02:54,386]: Found same input on page with type: hidden
      debug[18:02:54,387]: search for elements by name 'INPUT' in element span
      debug[18:02:54,390]: getElementsByTagName found 0
      debug[18:02:54,391]: Replace value for inputs: 37 by new values: 0
      debug[18:02:54,391]: call getElementById for id= _A4J.AJAX.focus
      debug[18:02:54,392]: No focus information in response
      debug[18:02:54,392]: call getElementById for id= org.ajax4jsf.oncomplete
      


      But when I change the a4j outputPanel to ajaxRendered=true the link seems to work (besides calling the action) and the panel does get rerendered and the a4j log looks normal and contains the xhtml for the panel that is to be rerendered.

      Anything obviously wrong with what I am doing? Any hints are appreciated.

      Thanks,


      Jon