You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Galen Meurer <si...@galenmeurer.com> on 2004/03/13 04:44:41 UTC
how to retrieve property metadata in component declaration?
Help! I can't find this in the documentation / javadocs -- it's got to be
there but my eyes are bugging out.
Harish once wrote that he used properties on non-validating components as a
marker to apply business rule validation. (This was in "Re: Final Answer?
Forcing Fields to Upper-case"). His example was:
<component id="clientList" type="PropertySelection">
<!-- This is simply a meta property that I read and evaluate it if
it has an "ognl: " prefix -->
<property name="entityField"
value="ognl: @xyz.FieldTokens@CLIENT_ID" />
<binding name="value" expression="client" />
<binding name="model" expression="clientListModel" />
</component>
I'm trying to do something very similar, but I can't figure out how to get
to properties declared inside the component declaration like in Harish's
example. The example in the TIA book for this retrieves properties at the
page specification level.
_pageType = page.getSpecification().getProperty("page-type");
Obviously, component.getSpecification().getProperty(NAME) is the analogous
choice, but it seems like that is looking in the
com/apache/tapestry/form/PropertySelection.jwc specification and not the
component declaration? At least, I can't seem to get at the property this
way -- it's quite possible I'm just making some other silly mistake.
Anyone know how can I get at the property metadata declared as in above
example?
Best,
Galen Meurer
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: how to retrieve property metadata in component declaration?
Posted by Galen Meurer <si...@galenmeurer.com>.
Sweet! Harish, thanks so much!
I do plan to implement the kind of validation that you described in the
first post, but I'm also using this to decorate the FieldLabel. There was
some discussion about that, I think, so in case this is of interest, here's
what I'm doing (caveat: I JUST wrote this, it is not yet battle-tested).
This is from a component specification:
<component id="selectStatusLabel" type="FieldLabel">
<binding name="field" expression="components.selectStatus"/>
<binding name="displayName"
expression='getMessage("organizationStatus")'/>
</component>
<component id="selectStatus" type="PropertySelection">
<property name="required" value="true"/>
<binding name="model" expression='getPicklistSelectionModel("status")'/>
<binding name="value" expression="organization.status"/>
<binding name="submitOnChange" expression="false"/>
</component>
This is from the form's validation delegate:
public void writeLabelPrefix(IFormComponent component, IMarkupWriter
writer, IRequestCycle cycle) {
if (isRequired(component)) {
writer.begin("span");
writer.attribute("class", "required-label");
}
}
public void writeLabelSuffix(IFormComponent component, IMarkupWriter
writer, IRequestCycle cycle) {
if (isRequired(component)) {
writer.end();
}
}
private boolean isRequired(IFormComponent component) {
boolean required = false;
IValidator validator = getValidator(component);
if (null != validator) {
if (validator.isRequired()) {
required = true;
}
} else {
// component.getProperty() is NOT the same thing
IComponentSpecification specification =
component.getContainer().getSpecification();
IContainedComponent comp =
specification.getComponent(component.getId());
if (null != comp) {
String requiredProperty = comp.getProperty("required");
if ("true".equalsIgnoreCase(requiredProperty)) {
required = true;
}
}
}
return required;
}
Best,
Galen;
----- Original Message -----
From: "Harish Krishnaswamy" <hk...@comcast.net>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Friday, March 12, 2004 8:04 PM
Subject: Re: how to retrieve property metadata in component declaration?
> This is the missing piece from the other message. This should answer
> your question.
>
> In my page class ... simply pass the page instance to this method (i.e.
> this).
>
> private void loadComponentFieldMap(IComponent comp)
> {
> IComponentSpecification compSpec = comp.getSpecification();
>
> String compId, entityField, searchEntityField;
> IComponent child;
>
> for (Iterator itr = compSpec.getComponentIds().iterator();
> itr.hasNext();)
> {
> compId = (String) itr.next();
>
> entityField =
> compSpec.getComponent(compId).getProperty("entityField");
> searchEntityField =
> compSpec.getComponent(compId).getProperty("searchEntityField");
>
> child = comp.getComponent(compId);
>
> if (entityField != null)
> _componentFieldMap.put(getEntityFieldName(entityField),
> child);
>
> else if(searchEntityField != null &&
> searchEntityField.equals("yes"))
> loadComponentFieldMap(child);
> }
> }
>
> -Harish
>
>
> Galen Meurer wrote:
>
> >Help! I can't find this in the documentation / javadocs -- it's got to be
> >there but my eyes are bugging out.
> >
> >Harish once wrote that he used properties on non-validating components as
a
> >marker to apply business rule validation. (This was in "Re: Final Answer?
> >Forcing Fields to Upper-case"). His example was:
> >
> ><component id="clientList" type="PropertySelection">
> ><!-- This is simply a meta property that I read and evaluate it if
> >it has an "ognl: " prefix -->
> ><property name="entityField"
> >value="ognl: @xyz.FieldTokens@CLIENT_ID" />
> ><binding name="value" expression="client" />
> ><binding name="model" expression="clientListModel" />
> ></component>
> >
> >I'm trying to do something very similar, but I can't figure out how to
get
> >to properties declared inside the component declaration like in Harish's
> >example. The example in the TIA book for this retrieves properties at the
> >page specification level.
> >
> >_pageType = page.getSpecification().getProperty("page-type");
> >
> >Obviously, component.getSpecification().getProperty(NAME) is the
analogous
> >choice, but it seems like that is looking in the
> >com/apache/tapestry/form/PropertySelection.jwc specification and not the
> >component declaration? At least, I can't seem to get at the property this
> >way -- it's quite possible I'm just making some other silly mistake.
> >
> >Anyone know how can I get at the property metadata declared as in above
> >example?
> >
> >Best,
> >Galen Meurer
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: how to retrieve property metadata in component declaration?
Posted by Harish Krishnaswamy <hk...@comcast.net>.
This is the missing piece from the other message. This should answer
your question.
In my page class ... simply pass the page instance to this method (i.e.
this).
private void loadComponentFieldMap(IComponent comp)
{
IComponentSpecification compSpec = comp.getSpecification();
String compId, entityField, searchEntityField;
IComponent child;
for (Iterator itr = compSpec.getComponentIds().iterator();
itr.hasNext();)
{
compId = (String) itr.next();
entityField =
compSpec.getComponent(compId).getProperty("entityField");
searchEntityField =
compSpec.getComponent(compId).getProperty("searchEntityField");
child = comp.getComponent(compId);
if (entityField != null)
_componentFieldMap.put(getEntityFieldName(entityField),
child);
else if(searchEntityField != null &&
searchEntityField.equals("yes"))
loadComponentFieldMap(child);
}
}
-Harish
Galen Meurer wrote:
>Help! I can't find this in the documentation / javadocs -- it's got to be
>there but my eyes are bugging out.
>
>Harish once wrote that he used properties on non-validating components as a
>marker to apply business rule validation. (This was in "Re: Final Answer?
>Forcing Fields to Upper-case"). His example was:
>
><component id="clientList" type="PropertySelection">
><!-- This is simply a meta property that I read and evaluate it if
>it has an "ognl: " prefix -->
><property name="entityField"
>value="ognl: @xyz.FieldTokens@CLIENT_ID" />
><binding name="value" expression="client" />
><binding name="model" expression="clientListModel" />
></component>
>
>I'm trying to do something very similar, but I can't figure out how to get
>to properties declared inside the component declaration like in Harish's
>example. The example in the TIA book for this retrieves properties at the
>page specification level.
>
>_pageType = page.getSpecification().getProperty("page-type");
>
>Obviously, component.getSpecification().getProperty(NAME) is the analogous
>choice, but it seems like that is looking in the
>com/apache/tapestry/form/PropertySelection.jwc specification and not the
>component declaration? At least, I can't seem to get at the property this
>way -- it's quite possible I'm just making some other silly mistake.
>
>Anyone know how can I get at the property metadata declared as in above
>example?
>
>Best,
>Galen Meurer
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org