You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by TappApp <ta...@comcast.net> on 2005/10/06 05:10:29 UTC
When/How to programatically modify a component before render.
Hello,
First off, I'm using Tapesty 3, not 4.
I have a page, that has a custom component I created on it.
That custom component has a web template, and a number of other components
embedded in it.
I need to programatically set one of the parameters in one of the components
embedded in the custom component.
I had NO PROBLEM doing this, when the "AddressElements" (see code below)
component was part of the page spec, but now that I've added the component
to my custom component, I get this error :
"Page recorder for page InvestorCreateListing is locked after a commit(),
but received a change to property stateCode of component
InvestorCreateListing/EditListing.AddressElements."
Here's the code in my custom component :
/**
* @see org.apache.tapestry.BaseComponent#renderComponent(
org.apache.tapestry.IMarkupWriter,
* org.apache.tapestry.IRequestCycle)
*/
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
{
if (!cycle.isRewinding())
{
initStateCode();
}
super.renderComponent(writer, cycle);
}
/**
*
*/
private void initStateCode()
{
AddressElements addressElements = (AddressElements)
getComponent("AddressElements");
if (addressElements.getStateCode() == null)
{
addressElements.setStateCode("TX");
}
}
I'm trying to give the "stateCode" an initial value if it does not already
have one.
What am I doing wrong ?
Thanks in advance,
TappApp
Re: When/How to programatically modify a component before render.
Posted by Matthew Wheaton <md...@gmail.com>.
Hi Ron,
I've tried to do what you suggest to no avail.
I have a component that takes a parameter "address", and some properties
that need initial values based on some values with the object represented by
parameter "address".
However, when the methods specified in the initial-value parameter of the
property-specification is called, the Address they expect is null.
I'm positive I'm passing in an address to the component, because other,
editable fields of the address are visible on the form.
Here's my address spec file :
Note, all the components that use the "address" param, like "addressLineOne"
work fine. It just seems the property-specs can't use the address yet ?
Below the address spec, is the methods that are called in the property spec,
and the values of the address is null
<component-specification allow-body="no"
allow-informal-parameters="no"
class="
com.ughm.app.view.tapestry.components.entities.address.AddressElements">
<description>
Elements for an address.
</description>
<parameter name="address"
required="yes"
direction="in"
type="com.ughm.entities.address.Address"/>
<property-specification name="stateCode"
type="java.lang.String"
persistent="yes"
initial-value="setInitialStateCode(address)"/>
<property-specification name="zip"
type="java.lang.String"
persistent="yes"
initial-value="setInitialZip(address)"/>
<property-specification name="stateModel"
type="org.apache.tapestry.form.IPropertySelectionModel"
persistent="no"/>
<component id="addressLineOne" type="ValidField">
<binding name="displayName" expression="getL10N('addressLineOne')"/>
<binding name="validator" expression="page.requiredStringValidator"/>
<binding name="value" expression="address.lineOne"/>
</component>
<component id="addressLineTwo" type="TextField">
<binding name="displayName" expression="getL10N('addressLineTwo')"/>
<binding name="value" expression="address.lineTwo"/>
</component>
<component id="inputState" type="ValidPropertySelection">
<binding name="displayName" expression="getL10N('state')"/>
<binding name="value" expression="stateCode"/>
<binding name="model" expression="stateModel"/>
<binding name="validator" expression="page.requiredStringValidator"/>
</component>
<component id="inputZip" type="ValidField">
<binding name="displayName" expression="getL10N('userZip')"/>
<binding name="validator" expression="page.zipValidator"/>
<binding name="value" expression="zip"/>
</component>
</component-specification>
Methods follow :
public String setInitialStateCode(Address address)
{
log.debug("initial state code address : " + address);
if (address != null)
{
if (getStateCode() == null)
{
State state = address.getState();
if (state != null)
{
return state.getCode();
}
}
}
return null;
}
public String setInitialZip(Address address)
{
log.debug("initial zip address : " + address);
if (address != null)
{
if (getZip() == null)
{
PostalCode postalCode = address.getPostalCode();
if (postalCode != null)
{
return postalCode.getCode();
}
}
}
return null;
}
On 10/6/05, Ron Piterman <rp...@gmx.net> wrote:
>
> You don't need to.
>
> lets say your parent component P takes a parameter A.
> you want to manipulate A and pass it to one or more components inside of
> P (child components, C1..Cx).
>
> So, you don't use the A binding directly, instead you use a property in
> your component class which delivers the manipulated data:
>
> <property name="b" initial-value="manipulate(a)"/>
>
> <component-specification...>
> <component id="C1" ...>
> <binding name="a" value="b"/>
> ...
>
> now in your component class
>
> private abstract A getA();
>
> public B manipulate(A a) {
> // do something with getA() and deliver the result...
> }
>
>
>
> ציטוט TappApp:
> > Hello,
> >
> > First off, I'm using Tapesty 3, not 4.
> >
> > I have a page, that has a custom component I created on it.
> > That custom component has a web template, and a number of other
> components
> > embedded in it.
> >
> > I need to programatically set one of the parameters in one of the
> components
> > embedded in the custom component.
> >
> > I had NO PROBLEM doing this, when the "AddressElements" (see code below)
> > component was part of the page spec, but now that I've added the
> component
> > to my custom component, I get this error :
> >
> > "Page recorder for page InvestorCreateListing is locked after a
> commit(),
> > but received a change to property stateCode of component
> > InvestorCreateListing/EditListing.AddressElements."
> >
> > Here's the code in my custom component :
> >
> > /**
> > * @see org.apache.tapestry.BaseComponent#renderComponent(
> > org.apache.tapestry.IMarkupWriter,
> > * org.apache.tapestry.IRequestCycle)
> > */
> > protected void renderComponent(IMarkupWriter writer, IRequestCycle
> cycle)
> > {
> > if (!cycle.isRewinding())
> > {
> > initStateCode();
> > }
> > super.renderComponent(writer, cycle);
> > }
> >
> > /**
> > *
> > */
> > private void initStateCode()
> > {
> > AddressElements addressElements = (AddressElements)
> > getComponent("AddressElements");
> > if (addressElements.getStateCode() == null)
> > {
> > addressElements.setStateCode("TX");
> > }
> > }
> >
> >
> > I'm trying to give the "stateCode" an initial value if it does not
> already
> > have one.
> >
> > What am I doing wrong ?
> >
> > Thanks in advance,
> > TappApp
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
Re: When/How to programatically modify a component before render.
Posted by Ron Piterman <rp...@gmx.net>.
You don't need to.
lets say your parent component P takes a parameter A.
you want to manipulate A and pass it to one or more components inside of
P (child components, C1..Cx).
So, you don't use the A binding directly, instead you use a property in
your component class which delivers the manipulated data:
<property name="b" initial-value="manipulate(a)"/>
<component-specification...>
<component id="C1" ...>
<binding name="a" value="b"/>
...
now in your component class
private abstract A getA();
public B manipulate(A a) {
// do something with getA() and deliver the result...
}
ציטוט TappApp:
> Hello,
>
> First off, I'm using Tapesty 3, not 4.
>
> I have a page, that has a custom component I created on it.
> That custom component has a web template, and a number of other components
> embedded in it.
>
> I need to programatically set one of the parameters in one of the components
> embedded in the custom component.
>
> I had NO PROBLEM doing this, when the "AddressElements" (see code below)
> component was part of the page spec, but now that I've added the component
> to my custom component, I get this error :
>
> "Page recorder for page InvestorCreateListing is locked after a commit(),
> but received a change to property stateCode of component
> InvestorCreateListing/EditListing.AddressElements."
>
> Here's the code in my custom component :
>
> /**
> * @see org.apache.tapestry.BaseComponent#renderComponent(
> org.apache.tapestry.IMarkupWriter,
> * org.apache.tapestry.IRequestCycle)
> */
> protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
> {
> if (!cycle.isRewinding())
> {
> initStateCode();
> }
> super.renderComponent(writer, cycle);
> }
>
> /**
> *
> */
> private void initStateCode()
> {
> AddressElements addressElements = (AddressElements)
> getComponent("AddressElements");
> if (addressElements.getStateCode() == null)
> {
> addressElements.setStateCode("TX");
> }
> }
>
>
> I'm trying to give the "stateCode" an initial value if it does not already
> have one.
>
> What am I doing wrong ?
>
> Thanks in advance,
> TappApp
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: When/How to programatically modify a component before render.
Posted by Ivano <i....@mclink.it>.
Hello
once in the render method it's too late to change the properties.
Your component could implement
org.apache.tapestry.event.PageRenderListener with method
pageBeginRender(PageEvent event) {
if ( !event.getRequestCycle().isRewinding() ) {
initStateCode();
}
}
the page should automatically register the listener and execute the
code, right before rendering.
But I would rather suggest initializing the property through the jwc
specification "initial-value" parameter or when the component class is
instantiated, in the finishLoad() method for example.
In this way, the property will show the initial value if not changed
externally with the setter method, and you do initialize it only once.
Hope it helps.
See ya.
>Hello,
>
>First off, I'm using Tapesty 3, not 4.
>
>I have a page, that has a custom component I created on it.
>That custom component has a web template, and a number of other components
>embedded in it.
>
>I need to programatically set one of the parameters in one of the components
>embedded in the custom component.
>
>I had NO PROBLEM doing this, when the "AddressElements" (see code below)
>component was part of the page spec, but now that I've added the component
>to my custom component, I get this error :
>
>"Page recorder for page InvestorCreateListing is locked after a commit(),
>but received a change to property stateCode of component
>InvestorCreateListing/EditListing.AddressElements."
>
>Here's the code in my custom component :
>
>/**
>* @see org.apache.tapestry.BaseComponent#renderComponent(
>org.apache.tapestry.IMarkupWriter,
>* org.apache.tapestry.IRequestCycle)
>*/
>protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
>{
>if (!cycle.isRewinding())
>{
>initStateCode();
>}
>super.renderComponent(writer, cycle);
>}
>
>/**
>*
>*/
>private void initStateCode()
>{
>AddressElements addressElements = (AddressElements)
>getComponent("AddressElements");
>if (addressElements.getStateCode() == null)
>{
>addressElements.setStateCode("TX");
>}
>}
>
>
>I'm trying to give the "stateCode" an initial value if it does not already
>have one.
>
>What am I doing wrong ?
>
>Thanks in advance,
>TappApp
>
>
>
--
Ivano Pagano
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org