You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by James Richards <ja...@northps.com> on 2006/05/24 19:24:47 UTC

Locating components by id

Hello,

I am trying to implement a state mechanism similar to the "flowState" component described in "Taming JSF 1.1":

http://bug.sakaiproject.org/confluence/pages/viewpage.action?pageId=4981

I have a PaginationState class:

public class PaginationState extends UIComponentBase implements Serializable {...}

which is configured as a component

  <component>
    <component-type>com.foo.faces.state.PaginationState</component-type>
    <component-class>com.foo.faces.state.PaginationState</component-class>
  </component>

I would like to use this pagination state to coordinate paging of a custom HtmlDataTable extension:

  <component>
    <component-type>com.foo.faces.CustomPaginationHtmlDataTable</component-type>
    <component-class>com.foo.faces.component.CustomPaginationHtmlDataTable</component-class>
  </component>


I declare the paginationState and custom table in the view which should exhibit the custom behavior:

<foo:paginationState id="paginationState" bean="#{aForm}"/>
<foo:customPaginationDataTable id="facilityLedgerData"
						 styleClass="data"
						 rowClasses="oddRow,evenRow"
						 columnClasses="width125,width100,width100,width100,width100,width300,buttons"
						 footerClass="footer"
						 var="entry"
						 rows="#{aForm.handler.rows}"
						 value="#{aForm.model}"
						 cellspacing="1"
						 width="100%"
						 preserveSort="true"
						 rowIndexVar="index">
...
</foo:customPaginationDataTable>

The custom table wants to override the "getFirst" property in cases where the paginationState is of a particular value.  I am having trouble, however locating the UIComponent instances:

	public int getFirst() {
System.out.println("Overriding getFirst(): state is " + paginationState);
		int fRwIdx = super.getFirst();
		int rwCnt = super.getRowCount();
		FacesContext ctx = FacesContext.getCurrentInstance();
		UIViewRoot vwRt = ctx.getViewRoot();
		List vwChld = vwRt.getChildren();

for(Iterator itr = vwChld.iterator(); itr.hasNext(); ) {
	UIComponent chld = (UIComponent)itr.next();
	System.out.println("CHILD IS:" + chld.getId());
}
		PaginationState pgSt = (PaginationState)vwRt.findComponent(":paginationState");
		if (pgSt == null) {
			System.out.println("NO PAGETODISPLAY COMPONENT");
		} else {
			System.out.println("GOT PAGETODISPLAY COMPONENT:" + pgSt);
			System.out.println("HASVALUE:" + pgSt.getValueBinding("value").getValue(ctx));
			System.out.println("HASBEAN:" + pgSt.getBean());
		}
		if (rwCnt < BaseSearchHandler.DISPLAY_ROWS) {
			return super.getFirst();
		}
		return getCustomFirstRow();
	}


In the above, I try to find paginationState from the UIViewRoot but am, so far, unable to locate it using either ":paginationState" or "paginationState".  I can locate the managed bean upon which pagination state depends but not any of the defined view components.

Is there any way in MyFaces to locate a particular UIComponent by ID?

Thanks for any help,

James