You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by James Reynolds <Ja...@intermountainmail.org> on 2006/03/16 21:02:48 UTC

[Shale]/jsf Referencing a component

I'm enjoying the helper methods extended from the AbstractViewController
and I'd like to send a message to a particular component.  For example,
here's the slick error() method.

protected void error(javax.faces.component.UIComponent component,
                     java.lang.String summary)

I'm not sure how to reference the desired component.  Can I refer to the
component with its ID?

Thanks


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [Shale]/jsf Referencing a component

Posted by Craig McClanahan <cr...@apache.org>.
On 3/16/06, James Reynolds <Ja...@intermountainmail.org> wrote:
>
>
> I'm enjoying the helper methods extended from the AbstractViewController
> and I'd like to send a message to a particular component.


Good idea :-).

  For example,
> here's the slick error() method.
>
> protected void error(javax.faces.component.UIComponent component,
>                      java.lang.String summary)
>
> I'm not sure how to reference the desired component.  Can I refer to the
> component with its ID?


You can't use a component identifier, because the method signature quoted
above requires a component *instance*.  There are two reasonable approaches
to how you can acquire such a component reference.

* Use the UIComponent.findComponent() method, perhaps on the
  root UIViewRoot component, to find the component instance for
  the specified client id.  NOTE -- the "Proposed Final Draft 2" version
  of the JSF 1.2 spec has added an additional related option here.

* Use the "binding" attribute on your JSP tag to attach the component
  instance into your backing bean.  The most common use case I've had
  for this is when you want to implement pagination on a table component
  (but the same principle applies to the question you are asking).  Consider
  a component with the following JSP custom tag:

    <h:dataTable ... binding="#{mybean.table}" .../>

  In the backing bean class referenced by the managed bean name
  "mybean", you need to define a property for the component itself,
  as opposed to its value:

    private HtmlDataTable table = null;
    public HtmlDataTable getTable() { return this.table; }
    public void setTable(HtmlDataTable table) { this.table = table; }

Using the latter approach, any event handler method in the same backing bean
has direct access to the component instance -- without even having to know
its id.  The same sort of approach can be used to expose component instances
needed for the first parameter to methods like error().

If you think, on the other hand, that we should also support passing a
string (the client id) instead of the component instance, please file an RFE
in the issue tracking system:

  http://issues.apache.org/bugzilla/

Under product "Struts" and category "Shale".

Thanks


Craig