> As just pointed out to me by Mike K. my solution goes against the jsf
> 1.1 spec. All of the form data will not be maintained as it would by
> using javascript+commandLink.
But, at least for those that are forced to use No_JS mode, you provide a
solution.
Thanks
I think it should be ok, that a commandlink does not preserve the
form-data.
That's what the buttons are for...
regards
Alexander
>
>
> On 7/24/06, Ryan Wynn <[EMAIL PROTECTED]> wrote:
> > For the impatient,
> >
> > (1) create the following class
> >
> > public class HtmlLinkRendererFix extends HtmlLinkRenderer {
> >
> > protected FormInfo findNestingForm(UIComponent uiComponent,
> > FacesContext facesContext) {
> > return
> _ComponentUtils.findNestingForm(uiComponent, facesContext);
> > }
> >
> > protected void
> renderNonJavaScriptAnchorStart(FacesContext facesContext,
> > ResponseWriter writer, UIComponent
> component, String clientId)
> > throws IOException {
> > ViewHandler viewHandler =
> facesContext.getApplication()
> > .getViewHandler();
> > String viewId =
> facesContext.getViewRoot().getViewId();
> > String path =
> viewHandler.getActionURL(facesContext, viewId);
> >
> > StringBuffer hrefBuf = new StringBuffer(path);
> >
> > //add clientId parameter for decode
> >
> > if (path.indexOf('?') == -1) {
> > hrefBuf.append('?');
> > } else {
> > hrefBuf.append('&');
> > }
> > String hiddenFieldName = HtmlRendererUtils
> >
> .getHiddenCommandLinkFieldName(findNestingForm(component,
> >
> facesContext).getFormName());
> > hrefBuf.append(hiddenFieldName);
> > hrefBuf.append('=');
> > hrefBuf.append(clientId);
> >
> > hrefBuf.append('&');
> > hrefBuf.append(findNestingForm(component,
> facesContext).getFormName()
> > + "_SUBMIT");
> > hrefBuf.append('=');
> > hrefBuf.append(1);
> >
> > if (getChildCount(component) > 0) {
> > addChildParametersToHref(component,
> hrefBuf, false, //not the first
> > // url parameter
> >
> writer.getCharacterEncoding());
> > }
> >
> > StateManager stateManager =
> facesContext.getApplication()
> > .getStateManager();
> > hrefBuf.append("&");
> > if
> (stateManager.isSavingStateInClient(facesContext)) {
> > hrefBuf.append(URL_STATE_MARKER);
> > } else {
> >
> hrefBuf.append(RendererUtils.SEQUENCE_PARAM);
> > hrefBuf.append('=');
> >
> hrefBuf.append(RendererUtils.getViewSequence(facesContext));
> > }
> > String href =
> facesContext.getExternalContext().encodeActionURL(
> > hrefBuf.toString());
> > writer.startElement(HTML.ANCHOR_ELEM, component);
> > writer.writeURIAttribute(HTML.HREF_ATTR,
> facesContext
> >
> .getExternalContext().encodeActionURL(href), null);
> > }
> >
> > private void addChildParametersToHref(UIComponent
> linkComponent,
> > StringBuffer hrefBuf, boolean
> firstParameter, String charEncoding)
> > throws IOException {
> > for (Iterator it =
> getChildren(linkComponent).iterator(); it.hasNext();) {
> > UIComponent child = (UIComponent) it.next();
> > if (child instanceof UIParameter) {
> > String name =
> ((UIParameter) child).getName();
> > Object value =
> ((UIParameter) child).getValue();
> >
> > addParameterToHref(name,
> value, hrefBuf, firstParameter,
> > charEncoding);
> > firstParameter = false;
> > }
> > }
> > }
> >
> > private static void addParameterToHref(String name,
> Object value,
> > StringBuffer hrefBuf, boolean
> firstParameter, String charEncoding)
> > throws UnsupportedEncodingException {
> > if (name == null) {
> > throw new IllegalArgumentException(
> > "Unnamed parameter
> value not allowed within command link.");
> > }
> >
> > hrefBuf.append(firstParameter ? '?' : '&');
> > hrefBuf.append(URLEncoder.encode(name,
> charEncoding));
> > hrefBuf.append('=');
> > if (value != null) {
> > //UIParameter is no
> ConvertibleValueHolder, so no conversion
> > // possible
> >
> hrefBuf.append(URLEncoder.encode(value.toString(), charEncoding));
> > }
> > }
> >
> > }
> >
> > (2) add the following to your faces-config.xml
> >
> > <render-kit>
> > <render-kit-id>HTML_BASIC</render-kit-id>
> > <renderer>
> >
> <component-family>javax.faces.Output</component-family>
> >
> <renderer-type>javax.faces.Link</renderer-type>
> >
> <renderer-class>HtmlLinkRendererFix</renderer-class>
> > </renderer>
> > <renderer>
> >
> <component-family>javax.faces.Command</component-family>
> >
> <renderer-type>javax.faces.Link</renderer-type>
> >
> <renderer-class>HtmlLinkRendererFix</renderer-class>
> > </renderer>
> > </render-kit>
> >
> >
> > Works without javascript enabled.
> >
> >
> > On 7/24/06, Ryan Wynn <[EMAIL PROTECTED]> wrote:
> > > On 7/24/06, Ryan Wynn <[EMAIL PROTECTED]> wrote:
> > > > I think I fixed the problem where the commandLink
> doesn't work with
> > > > javascript turned off. It is working for me now.
> > > >
> > > > See
> > > >
> > > > https://issues.apache.org/jira/browse/MYFACES-1370
> > >
> > > Basically the way it was written it was almost working.
> The problem
> > > was that in order for the the link renderers decode method to be
> > > called 1 additional parameter had to be supplied.
> > >
> > > namely,
> > > <parent_form_client_id>_SUBMIT=1
> > >
> > > This seems to work since links need to be nested within a
> form to work
> > > anyway. It does not submit the form obviously (otherwise
> javascript
> > > would be needed), this is a normal GET request with the parameters
> > > encoded in the url.
> > >
> > >
> > >
> > >
> > >
> > >
> > > >
> > > >
> > > >
> > > > On 7/24/06, Jesse Alexander (KSFD 121)
> > > > <[EMAIL PROTECTED]> wrote:
> > > > > Whether a single component gracefully degrades is up to the
> > > > > component-writer.
> > > > > THe JSF does (degradation is missing commnd-link...)
> > > > >
> > > > > But not all component-writers like to put the
> additional grease on their
> > > > >
> > > > > components to make them degrade gracefully. Some are just to
> > > > > JS-fanatics. ;-)
> > > > >
> > > > > Therefor one must test and then file
> JS-degradation-bug-requests for
> > > > > each
> > > > > component. I (for myself) would already be happy to
> read in each
> > > > > component-
> > > > > description the JS-requirements and degradation grade.
> > > > >
> > > > > regards
> > > > > Alexander
> > > > >
> > > > >
> > > > >
> > > > > > -----Original Message-----
> > > > > > From: Guy Coleman [mailto:[EMAIL PROTECTED]
> > > > > > Sent: Monday, July 24, 2006 12:15 PM
> > > > > > To: MyFaces Discussion
> > > > > > Subject: Re: ALLOW_JAVASCRIPT
> > > > > >
> > > > > > On 20/07/2006 22:02, Mike Kienenberger wrote:
> > > > > > > On 7/20/06, ragsta <[EMAIL PROTECTED]> wrote:
> > > > > > >> a simple question: does the ALLOW_JAVASCRIPT
> parameter work?
> > > > > > >>
> > > > > > >> Is very important for me that my site work even if the
> > > > > > javascript is
> > > > > > >> disabled on the user browser but turnig off the param
> > > > > > outputlink doesn't
> > > > > > >> work more...even if the primary goal of turning off the
> > > > > > param is to
> > > > > > >> change
> > > > > > >> the behaviour of this command....
> > > > > > >>
> > > > > > >> if this option is bugged I think I have to all
> back to a different
> > > > > > >> framework...
> > > > > > >
> > > > > > > You will be very limited in what you can do if
> you disabled
> > > > > > javascript.
> > > > > > > For instance, h:commandLink cannot work without
> javascript.
> > > > > > >
> > > > > > > Most of the interesting components also require
> javascript, as do a
> > > > > > > lot of the common "tricks" for accomplishing tasks.
> > > > > > >
> > > > > > > You're probably better off not using JSF if
> you're not able
> > > > > > to allow
> > > > > > > javascript.
> > > > > > >
> > > > > >
> > > > > >
> > > > > > We have had some success with using styled h:commandButtons
> > > > > > instead of
> > > > > > commandLinks to avoid Javascript.
> > > > > >
> > > > > > It's true that some advanced components cannot be
> used without
> > > > > > Javascript, but we have taken the approach that a
> site that degrades
> > > > > > gracefully is acceptable. For example, the
> inputDate popup cannot be
> > > > > > used without Javascript but the user can still enter a date
> > > > > > manually in
> > > > > > the input box.
> > > > > >
> > > > > > -Guy.
> > > > > >
> > > > >
> > > >
> > >
> >
>