struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig McClanahan" <>
Subject Re: [Shale]/jsf Referencing a component
Date Thu, 16 Mar 2006 20:42:14 GMT
On 3/16/06, James Reynolds <> 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:

Under product "Struts" and category "Shale".



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message