Works like a charm!  I used the binding method and now I'm off and
running.

Thanks! 

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Craig
McClanahan
Sent: Thursday, March 16, 2006 1:42 PM
To: Struts Users Mailing List
Subject: Re: [Shale]/jsf Referencing a component

On 3/16/06, James Reynolds <[EMAIL PROTECTED]> 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


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to