Dynamic UI Components and Seam Managed Persistent Context.Bug ?
amontobin Jun 20, 2008 1:05 AMHi Seam Users,
I'm trying to create a dynamic interface with buttons and input create on the fly. I've got a controller which is responsible to build the interface and to respond to different actions. My problem is that i cannot use a seam manage persistent context :
The Exception is : @In attribute requires non-null value: sayhello.entityManager
I try with a static page (CommandButton and AjaxCommandButton)
1. Persistent Context OK
2. Persistent Context EXTENDED OK
3. In (SMPC) OK
WIth a dynamic page :
1. Persistent COntext OK
2. Persistent Context EXTENDED OK
3. In (SMPC) NOK. Exception
Have you any ideas to help ?
Thank you very much,
Sebastien
Seam 2.0.1.SP1
Here is the code of the controller :
@Stateful
@Name("sayhello")
@Scope(SESSION)
public class SayHelloController implements SayHelloControllerLocalInterface {
        @In
        EntityManager entityManager;
        private String name;
        public String getName() {
                return name;
        }
        public void setName(String name) {
                this.name = name;
        }
        public String getMessage() {
                return "Hello " + getName();
        }
        public String submit() {
                testpersist();
                return null;
        }
        public String back() {
                return null;
        }
        public String testpersist() {
                SiteImpl site = new SiteImpl();
                site.setName("test");
                site.setUrl("test");
                entityManager.persist(site);
                return null;
        }
        public void test() {
                testpersist();
        }
        public void processAction(ActionEvent e) {
                testpersist();
        }
        private HtmlPanelGrid grid;
        public HtmlPanelGrid getGrid() {
                if (grid == null) {
                        Application app = FacesContext.getCurrentInstance().getApplication();
                        grid = (HtmlPanelGrid) app.createComponent(HtmlPanelGrid.COMPONENT_TYPE);
                        grid.setStyle("width : 100%;");
                        grid.setColumns(1);
                        grid.getChildren().add(getTestButton());
                }
                return grid;
        }
        public void setGrid(HtmlPanelGrid grid) {
                this.grid = grid;
        }
        private HtmlAjaxCommandButton testButton;
        public HtmlAjaxCommandButton getTestButton() {
                if (testButton == null) {
                        // Button RemoveFromCart
                        testButton = HtmlAjaxCommandButtonFactory.createRemoveCartButton();
                        Faces.setMethodExpression(testButton, "#{sayhello.testpersist}", "actionExpression", String.class, new Class[] {});
                }
                return testButton;
        }
        public void processAction(javax.faces.event.ActionEvent event) throws javax.faces.event.AbortProcessingException {
                testpersist();
        }
        public String getBinding() {
                return "sayhello";
        }
        @Remove
        public void destroy() {
        }
}
Here is the code of the page :
<html xmlns="http://www.w3.org/1999/xhtml"
     xmlns:ui="http://java.sun.com/jsf/facelets"
     xmlns:h="http://java.sun.com/jsf/html"
     xmlns:f="http://java.sun.com/jsf/core"
     xmlns:s="http://jboss.com/products/seam/taglib"
     xmlns:c="http://java.sun.com/jstl/core"
     xmlns:a4j="http://richfaces.org/a4j">
<head>
   Name!
</head>
<body>
        <f:view>
        <h:form id="form">
                <h:panelGrid binding="#{sayhello.grid}"/>
        </h:form>
    </f:view>  
</body>
</html>