You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Emond Papegaaij <e....@emaxx.nl> on 2005/06/24 14:43:15 UTC

Cast to HtmlForm in HtmlFormRendererBase

Hello,

I'm having trouble using the HtmlFormRendererBase class for rendering the 
Struts-faces FormComponent. This component extends UIForm, not HtmlForm. In 
HtmlFormRendererBase in encodeBegin the UIComponent parameter is cast to a 
HtmlForm in the following line:
  UIForm htmlForm = (HtmlForm)component;

This seems odd to me, as a cast to UIForm would suffice. From what I can see 
HtmlFormRendererBase does not depend on the component being a HtmlForm. 
Furthermore the component is only checked to be a UIForm with the following 
line:
  RendererUtils.checkParamValidity(facesContext, component, UIForm.class);

Somewhat further down, in encodeEnd another (what seems to be) redundant check 
for HtmlForm is done (shortened):
  if (component instanceof HtmlForm) {
    target = ((HtmlForm)component).getTarget();
  } else {
    target = (String)component.getAttributes().get(HTML.TARGET_ATTR);
  }

According to the documentation the Map returned by getAttributes() supports 
getting and setting bean properties of the component class. Am I correct in 
that HtmlFormRendererBase should be able to render a subclass of UIForm to 
HTML?

Best regards,
Emond Papegaaij

Re: Cast to HtmlForm in HtmlFormRendererBase

Posted by Bruno Aranda <br...@gmail.com>.
This is the same issue as MYFACES-216. I applied a patch there that
changes the cast to UIForm. The check in the encodeEnd, although
unnecessary (I think) it should not affect the behaviour of the
renderer.

regards,

Bruno

p.s. Now we are having a reorg of the source so I have doubts on how
to create a patch for the share package, so I created the patch from
the same folder of HtmlFormRenderer.java ...

2005/6/24, Emond Papegaaij <e....@emaxx.nl>:
> Hello,
> 
> I'm having trouble using the HtmlFormRendererBase class for rendering the
> Struts-faces FormComponent. This component extends UIForm, not HtmlForm. In
> HtmlFormRendererBase in encodeBegin the UIComponent parameter is cast to a
> HtmlForm in the following line:
>   UIForm htmlForm = (HtmlForm)component;
> 
> This seems odd to me, as a cast to UIForm would suffice. From what I can see
> HtmlFormRendererBase does not depend on the component being a HtmlForm.
> Furthermore the component is only checked to be a UIForm with the following
> line:
>   RendererUtils.checkParamValidity(facesContext, component, UIForm.class);
> 
> Somewhat further down, in encodeEnd another (what seems to be) redundant check
> for HtmlForm is done (shortened):
>   if (component instanceof HtmlForm) {
>     target = ((HtmlForm)component).getTarget();
>   } else {
>     target = (String)component.getAttributes().get(HTML.TARGET_ATTR);
>   }
> 
> According to the documentation the Map returned by getAttributes() supports
> getting and setting bean properties of the component class. Am I correct in
> that HtmlFormRendererBase should be able to render a subclass of UIForm to
> HTML?
> 
> Best regards,
> Emond Papegaaij
>