myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leonardo Uribe (JIRA)" <>
Subject [jira] Commented: (MYFACES-1692) CommandLink does not execute action if no javascript is allowed
Date Tue, 01 Apr 2008 02:38:24 GMT


Leonardo Uribe commented on MYFACES-1692:

Checking the javascript code of myfaces, I have found some thoughts about this issue:

1. I have run the solution provided, and renders something like this:

<form id="form" name="form" method="post" action="/myfaces-examples12/helloWorld.jsf" enctype="application/x-www-form-urlencoded">
<a href="/myfaces-examples12/helloWorld.jsf?form:_idcl=form:link1&javax.faces.ViewState=8EgC7hvJoXWgMHaUZxk5rx66APlnNueyP32ajDxbvc/i5akMf2jX5RwThYAU4FDpr0IJMZQjJ1Izg7ssnvZWuedBpxy9wCxB"
id="form:link1">press me</a>

<input type="hidden" name="form_SUBMIT" value="1" /><input type="hidden" name="javax.faces.ViewState"
id="javax.faces.ViewState" value="8EgC7hvJoXWgMHaUZxk5rx66APlnNueyP32ajDxbvc/i5akMf2jX5eYYlouo1labftL/yNL5lR+Sl3m2fYcxyRRj3PDXGGRM"

Use the solution cause the state is encoded twice (the values for state are not the same).

2. The question in deep is: how to submit a form through a link without javascript? I have
tried a lot in several ways for many days to found a way to do this and I have not found any
solution that meet this conditions.

The previous solution raises an exception on myfaces 1.2.

server state saving

java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(
at java.lang.Integer.valueOf(
at org.apache.myfaces.application.jsp.JspStateManagerImpl.getServerStateId(
at org.apache.myfaces.application.jsp.JspStateManagerImpl.restoreView(
at org.apache.myfaces.application.jsp.JspViewHandlerImpl.restoreView(
at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(

client state saving

at org.apache.myfaces.application.TreeStructureManager.restoreTreeStructure(
at org.apache.myfaces.application.jsp.JspStateManagerImpl.restoreView(
at org.apache.myfaces.application.jsp.JspViewHandlerImpl.restoreView(
at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(

Let's suppose that we can encode the link and solve the previous exception. Suppose a typical
form with a input field (h:inputText). When the link is clicked, the value of the input field
is not encoded on the link, so the result is that this value is never send to the server.
So, this solution (if we can make this work) only works for forms without input controls.

In this scenario, the best is do something like this on the renderer (maybe better on encodeBegin)

    protected void renderCommandLinkStart(FacesContext facesContext, UIComponent component,
                                          String clientId,
                                          Object value,
                                          String style,
                                          String styleClass)
            throws IOException
            String[] anchorAttrsToRender;
            if (JavascriptUtils.isJavascriptAllowed(facesContext.getExternalContext()))
                renderJavaScriptAnchorStart(facesContext, writer, component, clientId);
                throw new javax.faces.FacesException("h:commandLink not supported with javascript
                //renderNonJavaScriptAnchorStart(facesContext, writer, component, clientId);

This only make fails apps with h:commandLink and no javascript enabled. 

> CommandLink does not execute action if no javascript is allowed
> ---------------------------------------------------------------
>                 Key: MYFACES-1692
>                 URL:
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: General
>    Affects Versions:  1.2.0
>         Environment: Tomcat 6.0, javax.faces.STATE_SAVING_METHOD=server, org.apache.myfaces.ALLOW_JAVASCRIPT=false
>            Reporter: Thomas Fischer
> Situation:
> The tag <h:commandLink action="#{someBean.someAction}" value="submit"></h:commandLink>
is used in a jsp page, which is visited by the user. The user clicks on the link.
> Expected behaviour:
> The method someBean.someAction() should be called, and the navigation rule which matches
the outcome should determine the page to be displayed.
> Wrong behaviour:
> The method defined in action is not called and the same jsp page is rendered again. 
> I did some debugging to find the reason of this problem. It seems to me that the server
does not recognize that the click on the link is a postback. In line 172 in org.apache.myfaces.renderkit.html.HtmlResponseStateManager,
the HTTP Parameter ResponseStateManager.VIEW_STATE_PARAM is checked for existence. If it is
there, the request is a callback, and if it is not there, the request is not treated as postback.
This parameter is not encoded in the link rendered by h:commandLink, thus the request is not
treated as a postback, and the page is just rendered again.
> If javaScript rendering is allowed, this works fine because the HTTP parameter ResponseStateManager.VIEW_STATE_PARAM
is rendered as a hidden input field, and the javascript code does a form submit.
> It seems to me that the problem could be solved by adding the parameter ResponseStateManager.VIEW_STATE_PARAM
to the generated link (but I did not check it).

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message