I'm using Tapestry 5.0.14. You can download the project from
http://static.raibledesigns.com/downloads/basic-tapestry.zip.

Matt


Robert Zeigler wrote:
> 
> Hi Matt,
> 
> Hm, that's an odd exception.
> The way BeanEditForm works is to lookup an "editor block" for each  
> property, based on the "datatype" for that property (datatype is  
> determined by the DataTypeAnalyzer service; lookup of the block is the  
> job of the BeanBlockSource service).  The information needed for each  
> of the editor blocks to function is stashed in a  
> "PropertyEditContext", which is made available to the blocks by the  
> BeanEditor component via the Enviromental service.  Which is why I'm  
> saying your exception looks weird: it's saying that the  
> PropertyEditContext wasn't available from the environment.  Since this  
> presumably happens while rendering the bean editor, it's weird,  
> because property edit context /should/ be available!
> 
> The mailing list strips attachments; can you post the project elsewhere?
> Also, what version of t5?
> 
> Robert
> 
> On May 2, 2009, at 5/210:46 PM , mraible wrote:
> 
>>
>> I was able to fix the problem by commenting out field.isRequired()  
>> in the
>> following method:
>>
>>
>>    public void insideLabel(Field field, Element labelElement) {
>>        if (inError(field)) {
>>            addErrorClassToCurrentElement("error");
>>        }/*
>>        if (field.isRequired()) {
>>            labelElement.raw(" *");
>>        }*/
>>
>>    }
>>
>> Is there a way to use similar logic and prevent the exception from
>> happening?
>>
>> Thanks,
>>
>> Matt
>>
>>
>> mraible wrote:
>>>
>>> I tried using your hint by changing my template to the following:
>>>
>>> <t:layout title="message:personDetail.title"
>>>          heading="message:personDetail.heading"  
>>> menu="literal:PersonMenu"
>>>          xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd 
>>> ">
>>>
>>>    <t:messagebanner t:id="message" type="type"/>
>>>
>>>    <form t:id="personForm" clientValidation="true">
>>>        <t:errors/>
>>>
>>>        <div class="t-beaneditor">
>>>            <t:beaneditor t:id="person" object="person" exclude="id"/>
>>>
>>>            <div class="t-beaneditor-row" style="text-align: center">
>>>                <input type="submit" id="save"
>>> value="message:button.save"/>
>>>                <input t:type="submit" t:id="delete" id="delete"
>>> value="message:button.delete"/>
>>>                <input t:type="submit" t:id="cancel" id="cancel"
>>> value="message:button.cancel"/>
>>>            </div>
>>>        </div>
>>>    </form>
>>>
>>>    <script type="text/javascript">
>>>        Form.focusFirstElement($("personForm"));
>>>    </script>
>>>
>>> </t:layout>
>>>
>>> Unfortunately, I still get the same error when trying to view this  
>>> page:
>>>
>>>     [exec] ERROR [btpool0-3] PersonForm.run(78) | Render queue  
>>> error in
>>> AfterRender[PersonForm:person.loop]: Failure reading parameter  
>>> 'validate'
>>> of component core/PropertyEditBlocks:datefield: No object of type
>>> org.apache.tapestry5.services.PropertyEditContext is available from  
>>> the
>>> Environment.  Available types are org.apache.tapestry5.RenderSupport,
>>> org.apache.tapestry5.ValidationDecorator,
>>> org.apache.tapestry5.ValidationTracker,
>>> org.apache.tapestry5.internal.services.ClientBehaviorSupport,
>>> org.apache.tapestry5.services.FormSupport,
>>> org.apache.tapestry5.services.Heartbeat.
>>>     [exec] org.apache.tapestry5.ioc.internal.util.TapestryException:
>>> Failure reading parameter 'validate' of component
>>> core/PropertyEditBlocks:datefield: No object of type
>>> org.apache.tapestry5.services.PropertyEditContext is available from  
>>> the
>>> Environment.  Available types are org.apache.tapestry5.RenderSupport,
>>> org.apache.tapestry5.ValidationDecorator,
>>> org.apache.tapestry5.ValidationTracker,
>>> org.apache.tapestry5.internal.services.ClientBehaviorSupport,
>>> org.apache.tapestry5.services.FormSupport,
>>> org.apache.tapestry5.services.Heartbeat. [at
>>> classpath:org/apache/tapestry5/corelib/components/BeanEditor.tml,  
>>> line 3,
>>> column 47]
>>>     [exec]     at
>>> org 
>>> .apache 
>>> .tapestry5 
>>> .internal 
>>> .structure 
>>> .ComponentPageElementImpl.invoke(ComponentPageElementImpl.java:909)
>>>     [exec]     at
>>> org 
>>> .apache.tapestry5.internal.structure.ComponentPageElementImpl.access 
>>> $200(ComponentPageElementImpl.java:50)
>>>     [exec]     at
>>> org.apache.tapestry5.internal.structure.ComponentPageElementImpl 
>>> $6.render(ComponentPageElementImpl.java:189)
>>>     [exec]     at
>>> org 
>>> .apache 
>>> .tapestry5 
>>> .internal.services.RenderQueueImpl.run(RenderQueueImpl.java:68)
>>>     [exec]     at
>>> org 
>>> .apache 
>>> .tapestry5 
>>> .internal 
>>> .services.PageRenderQueueImpl.render(PageRenderQueueImpl.java:108)
>>>     [exec]     at
>>> $ 
>>> PageRenderQueue_12104869ca2.render($PageRenderQueue_12104869ca2.java)
>>>     [exec]     at
>>> $ 
>>> PageRenderQueue_12104869c9b.render($PageRenderQueue_12104869c9b.java)
>>>     [exec]     at
>>> org.apache.tapestry5.services.TapestryModule 
>>> $15.renderMarkup(TapestryModule.java:1128)
>>>     [exec]     at
>>> com.company.webapp.services.AppModule$1.renderMarkup(AppModule.java: 
>>> 138)
>>>
>>> Here is my PersonForm.java class:
>>>
>>> package com.company.webapp.pages;
>>>
>>> import org.apache.tapestry5.ioc.annotations.Inject;
>>> import org.apache.tapestry5.annotations.Component;
>>> import org.apache.tapestry5.annotations.InjectPage;
>>> import org.apache.tapestry5.annotations.Property;
>>> import org.apache.tapestry5.annotations.Persist;
>>> import org.apache.tapestry5.annotations.Service;
>>> import org.apache.tapestry5.corelib.components.EventLink;
>>> import org.apache.tapestry5.corelib.components.Form;
>>> import org.apache.tapestry5.PersistenceConstants;
>>>
>>> import org.appfuse.service.GenericManager;
>>> import com.company.model.Person;
>>>
>>> import org.slf4j.Logger;
>>>
>>> import java.util.List;
>>>
>>> public class PersonForm extends BasePage {
>>>    @Inject
>>>    private Logger log;
>>>
>>>    @Inject
>>>    @Service("personManager")
>>>    private GenericManager<Person, Long> personManager;
>>>
>>>    @Persist @Property
>>>    private Person person;
>>>
>>>    public Person getPerson() {
>>>        return person;
>>>    }
>>>
>>>    /**
>>>     * Allows setting person object from another class (i.e.  
>>> PersonList)
>>>     *
>>>     * @param person an initialized instance
>>>     */
>>>    public void setPerson(Person person) {
>>>        this.person = person;
>>>    }
>>>
>>>    @InjectPage
>>>    private PersonList personList;
>>>
>>>    @Component(id = "personForm")
>>>    private Form form;
>>>
>>>    private boolean cancel;
>>>    private boolean delete;
>>>
>>>    void onValidateForm() {
>>>        if (!delete && !cancel) {
>>>            // manually validate required fields or annotate the  
>>> Person
>>> object
>>>            /*if (foo.getProperty() == null ||
>>> user.getProperty().trim().equals("")) {
>>>                form.recordError("Property is a required field.");
>>>            }*/
>>>        }
>>>    }
>>>
>>>    void onActivate(Long id) {
>>>        if (id != null) {
>>>            person = personManager.get(id);
>>>        }
>>>    }
>>>
>>>    Object onSuccess() {
>>>        if (delete) return onDelete();
>>>        if (cancel) return onCancel();
>>>
>>>        log.debug("Saving person...");
>>>
>>>        boolean isNew = (getPerson().getId() == null);
>>>
>>>        personManager.save(person);
>>>
>>>        String key = (isNew) ? "person.added" : "person.updated";
>>>
>>>        if (isNew) {
>>>            personList.addInfo(key, true);
>>>            return personList;
>>>        } else {
>>>            addInfo(key, true);
>>>            return this;
>>>        }
>>>    }
>>>
>>>    void onSelectedFromDelete() {
>>>        log.debug("Deleting person...");
>>>        delete = true;
>>>    }
>>>
>>>    void onSelectedFromCancel() {
>>>        log.debug("Cancelling form...");
>>>        cancel = true;
>>>    }
>>>
>>>    Object onDelete() {
>>>        personManager.remove(person.getId());
>>>        personList.addInfo("person.deleted", true);
>>>        return personList;
>>>    }
>>>
>>>    Object onCancel() {
>>>        return personList;
>>>    }
>>> }
>>>
>>> I've attached my project which you should be able to run with "mvn
>>> jetty:run -Ph2". To reproduce, go to http://localhost:8080/ 
>>> personform and
>>> login with admin/admin.
>>>
>>> Thanks,
>>>
>>> Matt
>>>
>>>
>>>
>>>
>>> Thiago H. de Paula Figueiredo wrote:
>>>>
>>>> Em Sat, 02 May 2009 15:31:15 -0300, mraible <m...@raibledesigns.com>
>>>> escreveu:
>>>>
>>>>> I have the a Person.java object that I'm trying to use the  
>>>>> BeanEditForm
>>>>> component with. It has no Tapestry annotations in it. Is it  
>>>>> possible to
>>>>> use the BeanEditForm component with it?
>>>>
>>>> Yes. By the way, I've never used any Tapestry annotation in my  
>>>> POJOs.
>>>>
>>>>> <t:layout title="message:personDetail.title"
>>>>>          heading="message:personDetail.heading"
>>>>> menu="literal:PersonMenu"
>>>>>
>>>>> xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
>>>>>
>>>>>    <t:beaneditform object="person" id="personForm" exclude="id">
>>>>>        <t:parameter name="buttons">
>>>>
>>>> You're trying to override the edition block of a non-existent  
>>>> BeanModel
>>>> property. Try adding add="buttons" to the BeanEditForm.
>>>>
>>>> Hint: instead of using BeanEditForm in this case, use a Form, an  
>>>> Errors
>>>> and a BeanEditor. You'll have complete control on how to add the  
>>>> submit
>>>> input (and any other thing you need). BeanEditForm = Form + Errors +
>>>> BeanEditor + submit input.
>>>>
>>>> -- 
>>>> Thiago H. de Paula Figueiredo
>>>> Independent Java consultant, developer, and instructor
>>>> http://www.arsmachina.com.br/thiago
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>>>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>>>
>>>>
>>>>
>>>
>>>
>>
>> -- 
>> View this message in context:
>> http://www.nabble.com/Problem-using-BeanEditForm-with-a-POJO-tp23349016p23352398.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>> For additional commands, e-mail: users-h...@tapestry.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Problem-using-BeanEditForm-with-a-POJO-tp23349016p23352566.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to