On Fri, Aug 31, 2007 at 06:24:58PM +0300, Imants Firsts wrote:
> How do I correctly set up a BeanEditForm for editing a
> hibernate entity?

I don't think I'm even close to writing idiomatic Tapestry 5 (if such a
thing even exists), but here is the pattern I've been using:

EditMyBean.java
-------
public class EditMyBean {

        @ApplicationState
        private MyDBClass _theBean;

        public MyDBClass getTheBean(){return _theBean;}

        public void onActivate(long id){
                _theBean = getDAO().getById(id);
        }
        public long onPassivate(){
                return _theBean.getId();
        }

        @Component(id = "beanEditForm")
        private BeanEditForm _beanEditForm;


        public void onValidate(){
                //Validate the changes. Add errors to the form using
                //_beanEditForm.recordError(String). This will automagically
                //cause the page to redisplay.
        }

        public void onSuccess(){
                getDAO().saveOrUpdate(_theBean);
        }
}
-------

EditMyBean.html
-------
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
<head><title>EditMyBean</title></head>
<body>

<t:beaneditform object="theBean">
                        
<t:parameter name="id">
<!-- Marking the getter or setter with @Nonvisual is far
   - preferable, but this will do in a pinch.
  -->                        
</t:parameter>
                
</t:beaneditform>

</body>
</html>
-------


-- 
njl

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to