h:commandLink - 'onclick' encoding

I've noticed a deficiency in the JSF specification regarding the encoding of the 'onclick' attribute of the <h:commandLink> component:
[http://java.sun.com/javaee/javaserverfaces/1.2/docs/tlddocs/h/commandLink.html]
[http://java.sun.com/javaee/javaserverfaces/2.0/docs/pdldocs/jsp/h/commandLink.html]
[http://java.sun.com/javaee/javaserverfaces/2.0/docs/pdldocs/facelets/h/commandLink.html]
All of these state:
Encode Behavior
If an "onclick" attribute was specified by the user, render this JavaScript in a function, and render the user's JavaScript in a function. Render both functions in a choice function as follows:
var a=function(){#USER_FUNCTION#}; var b=function(){#JSF_FUNCTION#}; return (a()==false) ? false : b();
where #USER_FUNCTION# is the user's JavaScript and #JSF_FUNCTION# is the JavaScript rendered by JSF. The choice function should operate such that if the user's JavaScript returns true, then the rendered JavaScript will also execute.Anyone familiar with JavaScript executed in a browser knows the event handlers are executed a bit differently than normal functions. So the 'this' reference in event handlers refers to the element the handler has been registered on, like:
<a href="..." onclick="window.alert(this.href);">...</a>Invoking a function in the normal way "resets" the 'this' reference to the global object, i.e. the 'window', so:
<script type="text/javascript">
  function testAlert() {
    alert(this.href);
<a href="..." onclick="testAlert();">...</a>no longer works as expected. The same happens with the JSF specified way of handling user specified 'onclick' script:
<h:commandLink value="Try me!" action="..." onclick="window.alert(this.href);" />would render:
<a href="#" onclick="var a=function(){window.alert(this.href);}; var b=function(){#JSF_FUNCTION#}; return (a()==false) ? false : b();">Try me!</a>The user code in the above example would 'alert' an undefined value and not the expected 'href' of the link element. The problem is when one wants to pass the original 'this' reference to the element to a function for additional processing but this reference gets lost because of the JSF specification. It is really trivial to have this done correctly and causing no confusion to newcomers (like me), as:
var a=function(){#USER_FUNCTION#}; var b=function(){#JSF_FUNCTION#}; return (a.call(this)==false) ? false : b();Note the a.call(this) vs. a() call. This would preserve the 'this' reference in the #USER_FUNCTION# code, would be more natural to everyone (no difference between writing the code in a plain HTML link element or JSF h:commandLink) and would be just better. I hope someone will address this issue in next JSF revision. It is currently very irritating if not a buggy behavior.

You have raised a very interesting and valid point. However, this is probably not the best venue to get the message to the people that need to hear it. I would suggest bringing it up on the Mojarra developers mailing list ( [https://javaserverfaces.dev.java.net/mailinglists.html|https://javaserverfaces.dev.java.net/mailinglists.html] ).

Similar Messages

  • t:commandLink onclick event issue

    Hi All,
    Thanks to all of you for your previous valuable suggestions. Currently iam working on JSF1.1 where i need to implement a javascript window.confirm(...) when the user clicks on 'Delete' command link. The problem is when i click on 'Ok' button in the confirm window my javascript function returning true and the row gets deleted. And when i click on 'Cancel' button my javascript function returning false but still the row get deleted. Could you please suggest me on this.
    My code is as follows.
    <script type="text/javascript">
              function deleteConfirm() {
                        var response = window.confirm("Are you sure you want to Delete");
                        if(response) {
                             alert(response);
                             return true;
                        } else {
                             alert(response);
                             return false;
    </script>
    And my <t:commandLink> is as follows
    <t:commandLink onclick="javascript:deleteConfirm(this);" actionListener="#{additionalInterestBean.deleteInterest}" action="additional_interest_list">
    <h:outputText value="#{PolicyLabels['AdditionalInterestList.Delete']}" />
    </t:commandLink>
    Any help or suggestions will be highly appreciated.
    Thanks
    Krishna

    Hi Niki,
    Thanks for your suggestion. I tried the way as you suggested but didn't work. I am getting a javascript error on the status bar....done,with errors on page.
    <t:commandLink onclick="return confirm('Are you sure you want to Delete');" actionListener="#{additionalInterestBean.deleteInterest}" >
    <h:outputText value="#{PolicyLabels['AdditionalInterestList.Delete']}" />
    </t:commandLink>

  • JSF t:commandLink onclick event

    Hi All,
    First of all i would like to thank you all for your previous valuable suggestions. Currently i am working on a requirement where i have a <t:commandLink..>
    when i click on command Link...i need to call a backing bean method and once that method execution is completed i need to open a new popup window. How can i do this. Any help will be highly appreciated.
    Please let me know if my requirement is not clear or in complete.

    Hi Niki,
    Thanks for your suggestion. I tried the way as you suggested but didn't work. I am getting a javascript error on the status bar....done,with errors on page.
    <t:commandLink onclick="return confirm('Are you sure you want to Delete');" actionListener="#{additionalInterestBean.deleteInterest}" >
    <h:outputText value="#{PolicyLabels['AdditionalInterestList.Delete']}" />
    </t:commandLink>

  • CommandLink onclick JavaScript

    How to add onclick JavaScript to commandLink ?
    Why commandButton has onclick method, but commandLink hasn't ?

    When you use <h:commandLink>, the JSF implementation must write the "onclick" event handler so that the form it belongs to is submitted with enough info to tell which link was clicked. If you could add your own code for "onclick", it could potentially disable the main functionality of the <h:commandLink>. Use <h:outputLink> instead if you want to override the "onclick" behavior.

  • How to create a modeless dialog using commandlink

    i want to create a modelessdialog using commandlink. and my code is
    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <f:view>
    <script language="Javascript1.2">
    function modelesswin(){
    window.showModelessDialog();
    </script>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <h:form>
    <h:commandLink onclick="javascript:modelesswin('popup.html', 300, 300)" value="click"></h:commandLink>
    </h:form>
    </body>
    </f:view>
    </html>
    when i click the buttonlink the dialog box is not in a stable state that is its will appear and within a second it will disappear .. can any one of them can suggest me how to create a modeless dialoge using commandlink or by jsf option button
    regards
    subramanian

    If I had to guess (and I do :), the onclick is firing, bring up the dialog, but the commandLink causes a form submit, so the page is submitted. There is no action on the commandLink, so it's navigating back to the same page, causing it to refresh and your dialog to disappear. It would appear to me that you need a h:outputLink or simply <a href="# onclick="..." /"></a>

  • I have 2 tables i would like to make visisble onclick and hidden onclick?

    hi
    i am having 2 tabls in a jsf page intially first table is visible and secong is hidden. onclick i wrotes the javascipt to make second as visible.
    its not visisble why below is my code
    <h:panelGrid id="secondlien" width="100%" border="0" cellspacing="0" cellpadding="0" style="visibility:hidden; position: absolute;">
                        <h:panelGrid columns="2" border="0" cellspacing="0" cellpadding="0">
                             <h:commandLink onclick="showLien(1)" onmouseout="MM_swapImgRestore();"
                   onmouseover="MM_swapImage('subbody:closingData:first','','images/1stlientabdown.gif',1);">
                                  <h:graphicImage id="first" value="images/1stlientabup.gif" style="border:thin white;" />
                             </h:commandLink>
                             <h:graphicImage value="images/2ndlientabdown.gif" style="border:thin white;" />
                        </h:panelGrid>
    this is not visible if i cahnge the property as visble aslo
    thansk in advance

    Plug the device into the computer.
    Select the content desired to sync.
    Sync.

  • Custom JSF tag not working HELP!!!!

    We have a custom tag to display the list of attachments for a a selected entity. So for example if there are entities A, B, C...each entity can have none or 1 or more attachments. When you go to the details page you see the list of attachments if any and an image against it that can be clicked to delete the attachment.
    Here is the tag:
    <at:attachmentTable value="#{Entity.attachmentList}" remove="#{Entity.removeAttachment}" />
    Here is the renderer code for the delete the attachment part of the tag:
    private void writeRemove(UIComponent component, FacesContext ctx, ResponseWriter writer, String clientId, Attachment attachment, String parentId) throws IOException {
              writer.startElement("td", component);
              writer.startElement("a", component);
              writer.writeAttribute("href", "#", null);
              writer.writeAttribute("onmousedown", "confirmationDelete(this, 'attachment');", null);
              String encoding = "if(typeof jsfcljs == 'function'){jsfcljs(document.getElementById('"+ parentId + "'),{'" + clientId + "':'" + clientId + "','attachmentId':'" + attachment.getId().toString() +"'},'');}return false";
              writer.writeAttribute("onclick",encoding, null);
              writer.writeAttribute("type", "submit", null);
              writer.startElement("img", component);
              writer.writeAttribute("src", "/acw/images/removeline.gif", null);
              writer.writeAttribute("alt", "", null);
              writer.endElement("img");
              writer.endElement("a");
              writer.endElement("td");
    Here is the setProperties method for the tag:
         protected void setProperties(UIComponent component) {
              FacesContext context = FacesContext.getCurrentInstance();
              super.setProperties(component);
              setProperty(component, "value", value);
              setProperty(component, "parameterValue", parameterValue);
              setProperty(component, "parameterName", parameterName);
              if (remove != null && UIComponentTag.isValueReference(remove)) {
                   MethodBinding method = FacesContext.getCurrentInstance().getApplication().createMethodBinding(remove, new Class[] {});
                   UICommand command = (UICommand)component;
                   command.setAction(method);
    Here is how the tag renders as an <a> html tag:
    a href="#" onmousedown="confirmationDelete(this, 'attachment');" onclick="if(typeof jsfcljs == 'function'){jsfcljs(document.getElementById('entity'),{'entity:j_id_jsp_1417973014_25':'entity:j_id_jsp_1417973014_25','attachmentId':'10326'},'');}return false" type="submit"><img src="/images/removeline.gif" alt="" /></a>
    Here is what is heppening:
    When you click on the image to delete the attachment, the control somehow nevers goes to the removeAttachement method in the backing bean. As you can see in the tag above (remove="#{Entity.removeAttachment}" ).
    I have tried everything and at this point am not able to see what is going worng. Anyone who can see the obvious that I am missing please please do point it to me. I am sort of desperate for a solution....
    Thanks.
    TD

    Anchors don't have a type="submit". You should be basing this on an h:commandLink. In fact you could probably rewrite it all as an XML tag that just generates an h:commandLink.

  • Error while using window.open() in JSP page

    I am getting error while using window.open() in my JSP page.
    This is code in my JSP page,
    <h:commandLink onclick="loadContextSensitiveHelp(#{setNewDayStatusBean. cycleStatusViewObject.helpUrl});" value="Help">
    function loadContextSensitiveHelp(helpPageName) {
    top.consoleRef=window.open('#{facesContext.externalContext.requestContextPath}/main/patient/helpPageName','myconsole',
    'width=350,height=250'
    +',menubar=0'
    +',toolbar=0'
    +',status=0'
    +',scrollbars=1'
    +',resizable=0')
    top.consoleRef.document.close()
    I am getting the following error in my browser,
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: /SetNewDayStatus.jsp(69,34) #{..} is not allowed in template text
         org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
         org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
         org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:102)
         org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:711)
         org.apache.jasper.compiler.Node$ELExpression.accept(Node.java:935)
         org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2336)
         org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2386)
         org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:838)
         org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1507)
         org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2336)
         org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2386)
         org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2392)
         org.apache.jasper.compiler.Node$Root.accept(Node.java:489)
         org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2336)
         org.apache.jasper.compiler.Validator.validate(Validator.java:1737)
         org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:178)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:306)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
         com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:428)
         com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:444)
         com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:116)
         com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
         com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
         com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
         javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.13 logs.
    Anyone help me to solve this issue. Thanks............................

    I am getting error while using window.open() in my JSP page.
    This is code in my JSP page,
    <h:commandLink onclick="loadContextSensitiveHelp(#{setNewDayStatusBean. cycleStatusViewObject.helpUrl});" value="Help">
    function loadContextSensitiveHelp(helpPageName) {
    top.consoleRef=window.open('#{facesContext.externalContext.requestContextPath}/main/patient/helpPageName','myconsole',
    'width=350,height=250'
    +',menubar=0'
    +',toolbar=0'
    +',status=0'
    +',scrollbars=1'
    +',resizable=0')
    top.consoleRef.document.close()
    I am getting the following error in my browser,
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: /SetNewDayStatus.jsp(69,34) #{..} is not allowed in template text
         org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
         org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
         org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:102)
         org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:711)
         org.apache.jasper.compiler.Node$ELExpression.accept(Node.java:935)
         org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2336)
         org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2386)
         org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:838)
         org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1507)
         org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2336)
         org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2386)
         org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2392)
         org.apache.jasper.compiler.Node$Root.accept(Node.java:489)
         org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2336)
         org.apache.jasper.compiler.Validator.validate(Validator.java:1737)
         org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:178)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:306)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
         com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:428)
         com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:444)
         com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:116)
         com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
         com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
         com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
         javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.13 logs.
    Anyone help me to solve this issue. Thanks............................

  • Link to .chm file in JSF application

    Hello,
    I'm working on JSF , i have to link .chm (help file-user manual) to application using commandLink.
    Location of help file i.e .chm file will be in application.
    Requirements are , click on link , .chm file has to be opened in popup.
    If any one knows how to do this, pls do reply.
    Thank you,

    Hello,
    Thanks for reply, i working on '*jboss-4.0.5.GA* ', and i've placed .chm file where i've place jsp pages.
    This is code used to open word file in application .
    <h:commandLink onclick="javascript:openPopupWindow('help/Test.doc','650','300','yes');return false;" styleClass="label" style="color:white" value="#{str['label.help']}" tabindex="5" />
    And its working fine for word .doc. This code is not working for rest of the different file formats ..
    For .chm file
    <h:commandLink onclick="javascript:openPopupWindow('help/Test.chm','650','300','yes');return false;" styleClass="label" style="color:white" value="#{str['label.help']}" tabindex="5" />
    The popup will be shown but the contents of file are not same as original , look and feel and rest .
    Please check this code .
    Thank you,

  • How to get data from rich:dataGrid variable to backing bean

    Hi,
    I have a problem in the following code. I have a dataGrid and I display data in the data grid by calling an array (bean.list). The array is displayed as pictures in JSF and the user clicks on one of those images. (more like a shopping card)
    My question is once the user selects a picture, I want to get some details (e.g.price) and store it back in my bean class for later use.
    Please tell me how I store the data back to the bean class.
    <rich:dataGrid border="0" value="#{bean.list}" var="item"  columns ="2" >
           <h:panelGrid border="0" columns="2">
    <a4j:commandLink onclick="#{rich:component('modalPanel')}.show()"><h:graphicImage value="/images/#{item.imageName}"  /> </a4j:commandLink>
    <h:outputText value=" #{item.price}" /> bean.list is stored in the DB and once I display all the product images in JSF, the user clicks on any picture.
    I want to get some information (item.price) from that item and store it back in the bean class. And probably some other information (e.g.item.date) from the item.
    Thanks for your help
    Edited by: shana10 on Nov 18, 2009 10:45 PM

    private function onItemClick( e:ListEvent ):void
         alert=Alert.show(experimentdetails.getItemAt(e.rowIndex).experimentName.toString());
    The ListEvent has a rowIndex and a columnIndex property that you can use to find out the record/attribute that was clicked.
    Does this solve your query ?
    Balakrishnan V

  • Actions do not fired inside af:table

    Hi,
    I have recently faced a problem within actions inside af:table. Such that: The action of a commanlink (the command link resides in a af:table column) does not executed (the backing bean do not get hit). The suprising thing is: The command can be executed outside af:table. I do not get any error or warning.
    I will be apprecitated if you provide help.... The list the table I hope it will also provide help... The command link actions do not provoked (both of them).
    <af:table value="#{bindings.SeferSummaryReportQuery.collectionModel}"
    var="row" id="seferSummaryTable"
    rendered="#{bindings.SeferSummaryReportQuery.estimatedRowCount>0 &amp;&amp; backing_user_seferSummary.searchPerformed.value != null}"
    rows="#{bindings.SeferSummaryReportQuery.rangeSize}"
    first="#{bindings.SeferSummaryReportQuery.rangeStart}"
    partialTriggers="customRangeSizeList_SeferSummaryReportQuery"
    emptyText="#{bindings.SeferSummaryReportQuery.viewable ? res['global.no_rows_yet'] : res['global.access_denied']}"
    width="99%" banding="row">
    <af:column sortProperty="Alias" sortable="true"
    rendered="true"
    headerText="#{res['SeferSummaryReportQuery.Alias']}"
    width="100">
    <af:commandLink action="playbackMobile"
    text="#{row.Alias}">
    <af:setActionListener from="#{row.Mobile}"
    to="#{requestScope.requestMobileId}"/>
    </af:commandLink>
    </af:column>
    <af:column sortable="false" formatType="icon"
    width="35">
    <af:objectSpacer width="0" height="2"/>
    <af:commandLink onclick="return userSeferSummary.showGoogleEarthMobileLocationHistory(#{row.Rowno})"
    id="cmdShowOnGoogleEarth"
    action="#{backing_user_seferSummary.showOnGoogleEarth_action}">
    <af:setActionListener to="#{requestScope.selectedSeferRowno}"
    from="#{row.Rowno}"/>
    <af:objectImage source="/themeViewer/images/google_earth.jpg"
    shortDesc="#{res['global.show_on_google_earth']}"/>
    </af:commandLink>
    </af:column>
    </af:table>

    Hi,
    more likely is that the table is not enclosed by a form tag. Forget about what the previous poster said about the token, it doesn't hold true in your case
    Frank

  • How this piece of html code is encoded from commandLink?Help!

    Hi, this is the jsf code:
    <h:panelGrid columns="1">
                         <h:dataTable value="#{temp.nameFile}" var="myL"
                             rendered="#{temp.show1}">
                             <h:column>
                                  <h:commandLink actionListener="#{temp.create}" value="#{myL.name}"
                                       immediate="true">
                                       <f:param name="name" value="#{myL.name}" />
                                       <f:param name="path" value="#{myL.path}" />
                                  </h:commandLink>
                             </h:column>
                        </h:dataTable>
                   </h:panelGrid>And this is the html code it generates:
    <table>
         <tbody>
              <tr>
                   <td>
                   <table>
                        <tbody>
                             <tr>
                                  <td><a href="#"
                                       onclick="document.forms['_id0']['_id0:_idcl'].value='_id0:_id2:0:_id4';
                                                             document.forms['_id0']['name'].value='ISO-3166';
                                                             document.forms['_id0']['path'].value='D:/Tomcat5.0/webapps/test/WEB-INF/iso3166.xml';
                                                             document.forms['_id0'].submit(); return false;">ISO-3166</a></td>
                             </tr>
                             <tr>
                                  <td><a href="#"
                                       onclick="document.forms['_id0']['_id0:_idcl'].value='_id0:_id2:1:_id4';
                                                              document.forms['_id0']['name'].value='NAICS';
                                                              document.forms['_id0']['path'].value='D:/Tomcat5.0/webapps/test/WEB-INF/naics.xml';
                                                              document.forms['_id0'].submit(); return false;">NAICS</a></td>
                             </tr>
                             <tr>
                                  <td><a href="#"
                                       onclick="document.forms['_id0']['_id0:_idcl'].value='_id0:_id2:2:_id4';
                                                             document.forms['_id0']['name'].value='UNSPSC';
                                                             document.forms['_id0']['path'].value='D:/Tomcat5.0/webapps/test/WEB-INF/unspsc.xml';
                                                             document.forms['_id0'].submit(); return false;">UNSPSC</a></td>
                             </tr>
                        </tbody>
                   </table>
                   </td>
              </tr>
         </tbody>
    </table>there is a line of html code like this:
    document.forms['_id0']['_id0:_idcl'].value='_id0:_id2:1:_id4';I know that "_id0" is the form ID, and "_id0:_idcl" is the clientID,but what is the value part "_id0:_id2:1:_id4" and what is the meaning of each part?I am writing my custom renderer, so i need to know how it is encoded,please help:)
    Best Regards:)
    Robin

    _id0 - id of the form
    _id2 - id of the datatable
    1 - row index
    _id4 - id of the commandlink                                                                                                                                                                                       

  • MYSTERY!.. action not invoked on encoded commandLink...  WHY?

    Hi All !!!
    QUESTION: How are the navigation definition (in faces-config.xml) is "wired" to a "HtmlCommandButton" I encode in my custom renderer... or any other encoded UICommand?...
    This is a mystery to me at the moment. I have not been able to find any clear explanation as to how this works -- so I've not been able to debug the issue below.
    The issue: I encode an HtmlCommandButton in my custom renderer, and add an "action" attribute bound to a backing bean method "doAction()"...
    ---But, the action method is never invoked!!!
    Again, this is primarily due to the fact that I cannot tell what "wires" the navigation definitions (in faces-config.xml) to the "action" attribute in the command button and the "doAction()" method in the backing bean.
    Please let me know what I am missing or omitting from this code to allow the "action" mechanism to work properly!! :-).
    Below is the entire test application (custom component).... The idea is to have the user click on a div tag which popluates a hidden input tag and clicks a hidden HtmlCommandButton to submit the request. The application should navigate to the same page or another page based on the value of the clicked div tag.
    ***gorm.jsp***
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@ taglib uri="http://mycomponents" prefix="my"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
            <link rel="stylesheet" type="text/css" href="./stylesheet.css" title="Style">
        </head>
        <body>
            <f:view>
                <h:form id="form01">
                    <h:messages/>
                    <f:verbatim><h1>Testing custom JSF component: XYZTag:  Click on a div tag...</h1></f:verbatim>
                    <my:xyz id="xyz01" divdata="#{caveBean.divdata}" valueclicked="#{caveBean.valueclicked}" />
                </h:form>
            </f:view>
        </body>
    </html>
    ***blidge.jsp***
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@ taglib uri="http://mycomponents" prefix="my"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
            <link rel="stylesheet" type="text/css" href="./stylesheet.css" title="Style">
        </head>
        <body>
            <f:view>
                <h:form id="form01">
                    <h:messages/>
                    <f:verbatim><h1>show value of the div tag that was picked...</h1></f:verbatim>
                    <h:outputText value="#{caveBean.valueclicked}" />
                    <f:verbatim><br/></f:verbatim>
                    <h:commandButton value="goback" type="submit" action="#{caveBean.doAction}"/>
                </h:form>
            </f:view>
        </body>
    </html>
    ***CaveBean.java*** (backing bean)
    package xyz;
    import java.util.*;
    public class CaveBean
        private List divdata;
        private String valueclicked;
        public CaveBean()
        public void setDivdata(List divdata)
            this.divdata = divdata;
        public List getDivdata()
            List list = new ArrayList();
            list.add("blidge");
            list.add("gorm");
            list.add("glargle");
            return list;
        public String getValueclicked()
            System.out.println("valueclicked was:" + this.valueclicked + "!");
            return this.valueclicked;
        public void setValueclicked(String valueclicked)
            this.valueclicked = valueclicked;
            System.out.println("valueclicked set to:" + this.valueclicked + "!");
        public String doAction()
            System.out.println("doAction() invoked!");
            if (valueclicked.equals("gorm"))
                return "gorm";
            else
                return "blidge";
    ***taglib (tld)***
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
    <taglib>
      <tlib-version>0.03</tlib-version>
      <jsp-version>1.2</jsp-version>
      <short-name>mycomponents</short-name>
      <uri>http://mycomponents</uri>
      <description>mycomponent tags</description>
      <tag>
        <name>xyz</name>
        <tag-class>mycomponents.XYZTag</tag-class>
        <attribute>
          <name>id</name>
          <description>this component's id</description>
        </attribute>
        <attribute>
          <name>rendered</name>
          <description>is this component rendered?</description>
        </attribute>
        <attribute>
          <name>divdata</name>
          <description>div label strings</description>
        </attribute>
        <attribute>
          <name>valueclicked</name>
          <description>value of leaf node that was clicked</description>
        </attribute>
      </tag>
    </taglib>
    ***XYZTag***
    package mycomponents;
    import javax.faces.application.Application;
    import javax.faces.component.UIComponent;
    import javax.faces.webapp.UIComponentBodyTag;
    import javax.faces.el.ValueBinding;
    import javax.faces.context.FacesContext;
    public class XYZTag extends UIComponentBodyTag
        private String divdata;
        private String valueclicked;
        public String getComponentType ()
            return "XYZComponent";
        public String getRendererType ()
            return "XYZRenderer";
        @Override
            protected void setProperties (UIComponent component)
            super.setProperties (component);
            if( divdata != null )
                if (isValueReference (divdata))
                    FacesContext context = FacesContext.getCurrentInstance ();
                    Application app = context.getApplication ();
                    ValueBinding vb = app.createValueBinding (divdata);
                    component.setValueBinding ("divdata", vb);
                else
                    component.getAttributes ().put ("divdata", divdata);
            if( valueclicked != null )
                if (isValueReference (valueclicked))
                    FacesContext context = FacesContext.getCurrentInstance ();
                    Application app = context.getApplication ();
                    ValueBinding vb = app.createValueBinding (valueclicked);
                    component.setValueBinding ("valueclicked", vb);
                else
                    component.getAttributes ().put ("valueclicked", valueclicked);
        //setting "#{}" stuff...
        public String getDivdata ()
            return this.divdata;
        public void setDivdata (String divdata)
            this.divdata = divdata;
        public String getValueclicked ()
            return this.valueclicked;
        public void setValueclicked (String valueclicked)
            this.valueclicked = valueclicked;
        public void release ()
            super.release ();
            divdata = null;
            valueclicked = null;
    ***XYZComponent***
    package mycomponents;
    import javax.faces.component.UIComponentBase;
    import javax.faces.component.UICommand;
    import javax.faces.context.FacesContext;
    import java.util.List;
    import javax.faces.el.ValueBinding;
    public class XYZComponent extends UICommand
        private List divdata;
        private String valueclicked;
        public XYZComponent()
            setRendererType("XYZRenderer");
        public void setDivdata(List divdata)
            this.divdata = divdata;
        public List getDivdata()
            if(null != divdata)
                return divdata;
            ValueBinding _vb = getValueBinding("divdata");
            if(_vb != null)
                return (List)_vb.getValue(getFacesContext());
            else
                return null;
        // setting "#{}" stuff
        public void setValueclicked(String valueclicked, FacesContext facesContext)
            this.valueclicked = valueclicked;
            ValueBinding _vb = getValueBinding("valueclicked");
            _vb.setValue(facesContext,valueclicked);
        public String getValueclicked()
            if(null != valueclicked)
                return valueclicked;
            ValueBinding _vb = getValueBinding("valueclicked");
            if(_vb != null)
                return (String)_vb.getValue(getFacesContext());
            else
                return null;
        @Override
            public Object saveState(FacesContext context)
            Object values[] = new Object[2];
            values[0] = super.saveState(context);
            values[1] = divdata;
            values[2] = valueclicked;
            return ((Object) (values));
        @Override
            public void restoreState(FacesContext context, Object state)
            Object values[] = (Object[])state;
            super.restoreState(context, values[0]);
            divdata = (List) values[1];
            valueclicked   = (String)  values[2];
        @Override
            public String getFamily()
            return "XYZ";
    ***XYZRenderer***
    package mycomponents;
    import javax.faces.component.UIComponent;
    import javax.faces.render.Renderer;
    import javax.faces.context.FacesContext;
    import javax.faces.context.ResponseWriter;
    import javax.faces.application.Application;
    import javax.faces.application.ApplicationFactory;
    import javax.faces.FactoryFinder;
    import javax.faces.component.UICommand;
    import javax.faces.component.html.HtmlCommandButton;
    import javax.faces.el.MethodBinding;
    import java.util.List;
    import java.util.Map;
    import java.util.Set;
    import java.util.Iterator;
    import org.w3c.dom.NodeList;
    import org.w3c.dom.Node;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import org.xml.sax.SAXException;
    import java.io.File;
    import java.io.IOException;
    import org.w3c.dom.Document;
    public class XYZRenderer extends Renderer
        List divdata;
        String valueclicked;
        // is there a way to derive this, rather than hardcoding???
        String divaction = "#{" + "caveBean" + ".doAction}";
        public XYZRenderer()
        @Override
            public void decode(FacesContext context, UIComponent component)
            Map requestMap = context.getExternalContext().getRequestParameterMap();
            String clientId = component.getClientId(context);
            String value = (String) requestMap.get(clientId);
            XYZComponent xYZComponent = (XYZComponent)component;
            xYZComponent.setValueclicked((String)requestMap.get(clientId + ":valueclicked"),context);
        @Override
            public void encodeEnd(FacesContext context, UIComponent component) throws java.io.IOException
            XYZComponent xYZComponent = (XYZComponent)component;
            ResponseWriter writer = context.getResponseWriter();
            String clientId  = component.getClientId(context);
            Map test = component.getAttributes();
            divdata         = (List)   component.getAttributes().get("divdata");
            valueclicked    = (String) component.getAttributes().get("valueclicked");
            Map requestMap = context.getExternalContext().getRequestParameterMap();
            //build clickable div tags
            Iterator iterator = divdata.iterator();
            while (iterator.hasNext())
                String divlabel = String.valueOf(iterator.next());
                writer.startElement("div",component);
                writer.writeAttribute("onclick", "javascript: var thisform=this; while (thisform.nodeName != 'FORM') thisform = thisform.parentNode; var valueclicked=document.getElementById('"+ clientId +":valueclicked'); valueclicked.value='" + divlabel + "'; alert('you clicked the " + divlabel + " div tag'); document.getElementById('" + (clientId +"hiddenbutton").replaceAll(":","") +  "').click();", null);
                writer.writeText(String.valueOf(divlabel) ,null);
                writer.endElement("div");
            //build hidden input field that will be populated by the value of the clicked div tag
            writer.startElement("input", component);
            writer.writeAttribute("type", "hidden", null);
            writer.writeAttribute("id", clientId + ":valueclicked", null);
            writer.writeAttribute("name", clientId + ":valueclicked", null);
            writer.writeAttribute("value", "", null);
            writer.endElement("input");
            //build hidden button, whose dom "click" method will be invoked when div tags are clicked
            writer.startElement("div",component);
            encodeHiddenButton(context, clientId, divaction);
            writer.endElement("div");
        private HtmlCommandButton createHiddenButton(FacesContext context, String clientId, String divaction)
            Application application = context.getApplication();
            HtmlCommandButton hiddenButton = (HtmlCommandButton) context.getApplication().createComponent(HtmlCommandButton.COMPONENT_TYPE);
            ApplicationFactory factory = (ApplicationFactory)FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
            MethodBinding binding = factory.getApplication().createMethodBinding(divaction,null);
            hiddenButton.setId((clientId +"hiddenbutton").replaceAll(":",""));
            hiddenButton.setType("button");
            hiddenButton.setAction(binding);
            hiddenButton.setOnclick("javascript: alert('youve clicked the new HtmlCommandButton - invisible submit button!...'); var thisform=this; while (thisform.nodeName != 'FORM') thisform = thisform.parentNode;thisform.submit();");
            hiddenButton.setValue("hiddenbutton");
            return hiddenButton;
        private void encodeHiddenButton(FacesContext context, String clientId, String divaction)
        throws IOException
            HtmlCommandButton hiddenButton = createHiddenButton(context, clientId, divaction);
            hiddenButton.encodeBegin(context);
            hiddenButton.encodeChildren(context);
            hiddenButton.encodeEnd(context);
    ***web.xml***
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
          version="2.4">
        <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>*.faces</url-pattern>
        </servlet-mapping>
        <session-config>
            <session-timeout>30</session-timeout>
        </session-config>
        <welcome-file-list>
            <welcome-file>gorm.jsp</welcome-file>
        </welcome-file-list>
        <jsp-config>
            <taglib>
                <taglib-uri>/mycomponents</taglib-uri>
                <taglib-location>/WEB-INF/tlds/mycomponents.tld</taglib-location>
            </taglib>
        </jsp-config>
    </web-app>
    *** faces-config.xml***
    <?xml version='1.0' encoding='UTF-8'?>
    <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
    <faces-config>
       <navigation-rule>
          <from-view-id>/gorm.jsp</from-view-id>
          <navigation-case>
             <from-outcome>gorm</from-outcome>
             <to-view-id>/gorm.jsp</to-view-id>
          </navigation-case>
          <navigation-case>
             <from-outcome>blidge</from-outcome>
             <to-view-id>/blidge.jsp</to-view-id>
          </navigation-case>
       </navigation-rule>
       <navigation-rule>
          <from-view-id>/blidge.jsp</from-view-id>
          <navigation-case>
             <from-outcome>submit</from-outcome>
             <to-view-id>/gorm.jsp</to-view-id>
          </navigation-case>
       </navigation-rule>
       <managed-bean>
          <managed-bean-name>caveBean</managed-bean-name>
          <managed-bean-class>xyz.CaveBean</managed-bean-class>
          <managed-bean-scope>request</managed-bean-scope>
       </managed-bean>
        <component>
            <component-type>XYZComponent</component-type>
            <component-class>mycomponents.XYZComponent</component-class>
        </component>
        <render-kit>
            <renderer>
                <component-family>XYZ</component-family>
                <renderer-type>XYZRenderer</renderer-type>
                <renderer-class>mycomponents.XYZRenderer</renderer-class>
            </renderer>
        </render-kit>
    </faces-config>--thanks again for any help!!!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      

    Hi,
    I THINK this is what you are after. You firstly shoudl add a new attribute to your component which can take a value binding expression to your bean method, this function can take any format is likes in your backing bean as long as it is public. In you tag you will then need some code similar to this:
    if(divaction != null){
             if(isValueReference(divaction )){
                    //This line here is if your function takes a single Integer arguement,
                   //you should replace it with whatever is correct for your function.
              Class[] defineParams = {Integer.class};
              MethodBinding mb = FacesContext.getCurrentInstance().getApplication().createMethodBinding(divaction , defineParams);
              ((YourComponent)component).setDivaction(mb);
             else{
              MethodBinding mb = Util.createConstantMethodBinding(divaction );
              ((RelationshipsComponent)component).setDivaction(mb);
         }And in your component you will need to add a MethodBinding variable with teh relevent getter/setter. One thing that I had a problem with here is that you must now implement the save/restore state functions or between phases the component will forget all about your methodbinding.
    private MethodBinding divaction;
    //getter/setter
    //save/restore state
    public Object saveState(FacesContext fc) {
         Object values[] = new Object[2];
         values[0] = super.saveState(fc);
         values[1] = saveAttachedState(fc, divation);
         return (values);
        public void restoreState(FacesContext fc, Object state) {
         Object values[] = (Object[]) state;
         super.restoreState(fc, values[0]);
         divaction= (MethodBinding) restoreAttachedState(fc,values[1]);
        } That saiid and done, you can move on to the renderer. I have not tried to adda button in the way in which you are, I have encoded markup directly using:
    public static void encodeButton(ResponseWriter writer, String szName, String szValue, UIComponent component) throws IOException{
         writer.startElement("input", component);
         writer.writeAttribute("type", "submit", null);
         writer.writeAttribute("name", szName, null);
         writer.writeAttribute("value", szValue, "value");
         writer.endElement("input");
        }The name element is important as it is used in the decode phase, it is the value that is stored in the requestMap if the button has been pressed.
    The decode method in your rendere is wher eyou will fire your method off, you must first check to see if your button was pressed by looking for its name in the requestMap:
    Map requestMap = fc.getExternalContext().getRequestParameterMap();
    if (requestMap.containsKey(yourButtonName)){
         //react to the button being pressed
    }You should have a method bound to your control now through the code added to your tag (and obviously on the .jsp page), all you need to do is fire it which is accomplished using the following code:
    MethodBinding mb = ((yourComponent)component).getDivaction();
              if(mb!= null){
                       //this stuff here with val is again related to your method arguements, if your method takes none, you can pass null. If you pass the wrong arguments you will get an exception telling you the function does not exist.
                  Object val[] = new Object[1];
                  Integer n = new Integer((int)rvo.getId());
                  val[0] = n;
                  mb.invoke(fc, val);
              }I know this is a different approach to that which you are using, and I daresay its not quite perfect, but it works for me!

  • h:commandLink value="Add New CD/DVD" id="addnewcd_dvd" onclick

    Hi,
    commandlink is not working with onclick()
    please tell me another solution or is there any bug in my script
    <script type="text/javascript">
    function checkSupervisor()
         if("<%=session.getAttribute("supervisor")%>"=="N")
         alert("don't have rights for this option");
    </script>
    <h:commandLink value="Add New CD/DVD" id="addnewcd_dvd" onclick="checkSupervisor()" action="#{viewCDBean.addLicenceCDDetails}" />
    Edited by: My_Problems on Jun 18, 2008 10:53 AM

    getting exception
    exception
    org.apache.jasper.JasperException: /CD/viewAllCDs.jsp(89,2) Attribute onclick invalid for tag commandLink according to TLD
         org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
         org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
         org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:236)
         org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:986)
         org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:706)
         org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1442)
         org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2166)
         org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2216)
         org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:726)
         org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1442)
         org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2166)
         org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2216)
         org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:726)
         org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1442)
         org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2166)
         org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2216)
         org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:726)
         org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1442)
         org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2166)
         org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2216)
         org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2222)
         org.apache.jasper.compiler.Node$Root.accept(Node.java:457)
         org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2166)
         org.apache.jasper.compiler.Validator.validate(Validator.java:1484)
         org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:167)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:296)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:302)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
         com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
         com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
         com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
         com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
         com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
         javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
         org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)

  • Onclick javascript confirm for commandlinks

    Pre JSF 1.2, there was no onclick for commandLinks. Below is some javascript I wrote to dynamically pre-pend a confirm javascript call before the onclick submit event is called. I use this so that my delete links in my application pop up confirm dialogs before actually doing the submit. (I am unable to upgrade to JSF 1.2) I hope this helps someone else experiencing the same problem.
    Comments and suggestions are always welcome!
    You need to wrap your commandLink components with some kind of tag:
    Example: <span name="deleteButton" confirm="#{itemTitle}"><commandLink... /></span>
    Also, you need to add pageConfirmLoader as a function to be executed on window load.
    var ConfirmLoader = {
         init : function(tag, tagName) {
              this.tag = tag;
              this.tagName = tagName;
         load : function() {
             if(this.tag != null && this.tagName != null) {
                   var spans = document.getElementsByTagName(this.tag);
                   var spansLength = spans.length;
                   var confirmHelper = {
                        functs: [ ],
                        descs: [ ],
                        confirmDelete: function(event) {
                             var loc = event.target.parentNode.parentNode.id;
                             var confirmText = "Are you sure you want to delete this item?";
                             if(this.descs[loc] != null) {
                                  confirmText = "Are you sure you want to delete '" + this.descs[loc] + "' ?"
                             if(confirm(confirmText) ) {
                                  eval(this.functs[loc](event));
                   for (i = 0; i < spansLength; i++) {
                        if (spans.getAttribute('name') == this.tagName) {
                             confirmHelper.functs[spans[i].id] = spans[i].childNodes[0].onclick;
                             confirmHelper.descs[spans[i].id] = spans[i].getAttribute('confirm');
                             spans[i].childNodes[0].onclick = function(event){ confirmHelper.confirmDelete(event); };
    function pageConfirmLoader() {
         ConfirmLoader.load();
    ConfirmLoader.init('span', 'deleteButton');

    I have one missed attribute: the wrapping span tag also needs some kind of id assigned to it, so the javascript ConfirmLoader can insert the values into the correct locations.
    <span name="deleteButton" confirm="#{itemTitle}" id="#{iter.nextId}" ><commandLink... /></span>

Maybe you are looking for