Thanks Alan, but what if there are 10+ components as in my case? It would be pretty cumbersome to inject every single one of them.

Alan Chandler wrote:

On Tuesday 07 March 2006 20:11, Leo Sakhvoruk wrote:
Hi everyone,

I'm trying to manipulate components inside a form and am having trouble
casting them correctly. What class should components be cast to since
they're enhanced?

I found the easiest way is to inject them as per this example


        @InjectComponent("newrole")
        public abstract TextField getNewRoleField();

        public void updateRoles() {             
                if (getButtonClicked() < 0) {
                        /*
                         * Create a new role
                         */
                        ValidRole vr = getNewRole();
                        if (!(vr.getName() == null || vr.getName().equals(""))) 
{
                                try{
                                        vr.create();
                                } catch (DatabaseException e) {
                                        ValidationDivDelegate delegate = 
getDelegate();
                                        
delegate.setFormComponent(getNewRoleField());
                                        
delegate.record(getMessages().getMessage("error.naming"),ValidationConstraint.CONSISTENCY);
                                        return;
                                }
                                setNewRole(null);  //Clear out the field so its 
not detected next time
                        }
                }
        }
}


Reply via email to