You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "Nebinger, David" <dn...@tbbgl.com> on 2006/10/27 04:15:46 UTC

Extending HtmlForm?

Okay, here's the thing.  I'm using myfaces 1.1.4 within a portlet running under liferay.  And it's actually working.  I'm really pleased (kudos the the developers).

But I want to be able to adjust the portlet window state.  This is accomplished by setting the p_p_state parm to either normal, maximized, or minimized in either a form submission or within a url.

Based upon view source, it appears as though when org.apache.myfaces.shared_impl.renderkit.html.HtmlFormRendererBase uses the external context to build the action link, it is getting portal state from somewhere because the value is same as the current state of the portlet.

But if I want to go from normal to maximized when a form is being submitted I need to get in there and edit the link before it is finalized and html issued to the browser.

So anyway, long story short I extended org.apache.myfaces.taglib.html.HtmlFormTag to have a tag with my additional attribute (yes I included all other attributes so the tag defn would be complete), I extended javax.faces.component.html.HtmlForm so I could include my new attribute and  save/restore state.

However, to achieve my ultimate goal I also extended org.apache.myfaces.renderkit.html.HtmlFormRenderer.  In the extension class I overrode encodeBegin to contain the following:

public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
	if (component instanceof MyForm) {
		FCWrapper wrapper = new FCWrapper(facesContext, (MyForm) component);
		super.encodeBegin(wrapper, component);
	} else {
		super.encodeBegin(facesContext, component);
	}
}

If it is not a MyForm object (which it should be), it just lets the super do all the work.

If it is a MyForm, I create a FacesContext wrapper so that I have control over the ExternalContext that is fed to super.encodeBegin() when it is building the action URL.  In my wrapper, I let the regular ExternalContext build the action URL and then I either add the portlet window state (if it wasn't there before) or I change the window state (if it was there but not the value I need).

Everything appeared kosher, but alas I'm getting odd results.  My URL is encoding correctly, the form and it's child components all render correctly (by examining the 'view source' output), but the encoding is incomplete.  The form tag doesn't get closed, and the mystical javascript clear_blah_blah_blah() function is not written out either.

If I don't use my form tag, everything gets closed correctly (although I no longer have access to change the window state).

Now I was already bitten once by using the wrong component family (we had standardized on using our own family strings and I repeated this when creating the form extension) not knowing that by not being a javax.faces.Form family object I'd get errors re: using command links outside of forms.

So basically my question is, has anyone else extended HtmlFormRender with any success?  Anyone offer some ideas about where to begin tracking down the non-form-tag-closure issue?  Have a better suggestion as to how I should implement the parm change on the server side during rendering?

Thanks in advance and sorry for the verbosity.

Dave Nebinger
dnebinger@tbbgl.com
dnebing@gmail.com