« Return to Thread: Wicket RAD and JTA

Wicket RAD and JTA

by wadi :: Rate this Message:

Reply to Author | View in Thread

Me again...I made the Netbeans Web project to work with wicket. I added my persistence.xml to the META-INF dir but It only works with non-jta resource on glassfish otherwise I get an exception creating the EntityManager. I did a merge between a secure application and a data app. The result is the following:

public abstract class SecureDataApplication extends AuthenticatedWebApplication{
private IServiceFactory serviceFactory = new DefaultServiceFactory();

        public SecureDataApplication(){
                PersistenceUnit.unitName = getDefaultPersistenceUnitName();
        }

        /**
         * Overriden, returns a DataRequestCycle
         */
        @Override
        public RequestCycle newRequestCycle(Request request, Response response) {
                Set<String> set = getPersistenceUnits();
                if(set == null){
                        set = new TreeSet<String>();
                }
                set.add(this.getDefaultPersistenceUnitName());
                return new DataRequestCycle(this,
                                (WebRequest) request, response, set);
        }

        /**
         * Gets the default persistence-unit name, used for most of the default implementations of JPA functionality.
         * @return
         */
        public abstract String getDefaultPersistenceUnitName();

        /**
         * Finds an implementation class for an interface, if the implementation class has a @Service annotation.
         * @param serviceInterface
         * @return
         */
        public Object getService(Class serviceInterface){
                return serviceFactory.getService(serviceInterface);
        }

        /**
         * Same as getService, but can lookup a named service.
         * @param serviceInterface
         * @param name
         * @return
         */
        public Object getService(Class serviceInterface, String name){
                return serviceFactory.getService(serviceInterface, name);
        }

        /**
         * Returns a Set of the names of the JPA persistence units used for OSIV with this application.<br>
         * Override this is you have more persistence units than the default unit.
         * @return
         */
        protected Set<String> getPersistenceUnits(){
                return null;
        }


    @Override
     protected  void init() {
   super.init();
         getSecuritySettings().setAuthorizationStrategy(new IAuthorizationStrategy()
        {

            public boolean isInstantiationAuthorized(Class componentClass)
            {
                if (PaginaSegura.class.isAssignableFrom(componentClass))
                {
                    // Is user signed in?
                    if (((MobileWorksSession)Session.get()).isSignedIn())
                    {
                        // okay to proceed
                        return true;
                    }
                     
                    // Force sign in
                    throw new RestartResponseAtInterceptPageException(LoginPage.class);
                }
                return true;
            }

            public boolean isActionAuthorized(org.apache.wicket.Component component, org.apache.wicket.authorization.Action action) {
                return true;
            }
        });
    }
}

I also have a page where I should see a table with data(Clientes):
@AuthorizeInstantiation("ADMIN")
public final class ClientesPage extends BasePage implements PaginaSegura{
    public ClientesPage() {
        super ();
        add(new BookmarkablePageLink("add", CrearClientePage.class));

                AjaxBeanPropertyTable table = new AjaxBeanPropertyTable("table");
                table.init(new DefaultBeanPropertyTableProvider(Cliente.class), Cliente.class, 10);
                add(table);
    }
}
And a create page:
public final class CrearClientePage extends BasePage {
   
    public CrearClientePage() {
        super ();
        add(new BookmarkablePageLink("backLink", ClientesPage.class));
                add(new Label("beanLabel", "Nuevo Cliente"));
                // initialize the form
        DefaultCreateBeanForm<Cliente> bf=new DefaultCreateBeanForm("form", new Cliente()){
            @Override
                        protected void afterSubmit() {
              setResponsePage(ClientesPage.class);
                        }

                };

                add(bf);
    }

}
And this is the Cliente class:
@Entity
@Table(name = "CLIENTE")
public class Cliente implements Identifiable, Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ID_CLIENTE", nullable = false)
    private Integer id;

    @FieldOrder(3)
    @TextField()
    @Length(min = 3, max = 20)
    public String getMail() {
        return mail;
    }

    public void setMail(String mail) {
        this.mail = mail;
    }

    @FieldOrder(1)
    @TextField()
    @Required
    @Length(min = 3, max = 20)
    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    @FieldOrder(2)
    @TextField()
    @Required
    @Length(min = 3, max = 20)
    public String getTelefono() {
        return telefono;
    }

    public void setTelefono(String telefono) {
        this.telefono = telefono;
    }
    @Column(name = "NOMBRE")
    private String nombre;
    @Column(name = "TELEFONO")
    private String telefono;
    @Column(name = "MAIL")
    private String mail;
    @OneToMany(targetEntity = Empresa.class,
    cascade = {CascadeType.REFRESH, CascadeType.MERGE})
    @JoinTable(name = "CLIENTE_EMPRESA",
    joinColumns = @JoinColumn(name = "ID_CLIENTE"),
    inverseJoinColumns = @JoinColumn(name = "ID_EMPRESA"))
    private List<Empresa> empresa;

    public List<Empresa> getEmpresa() {
        return empresa;
    }

    public void setEmpresa(List<Empresa> empresa) {
        this.empresa = empresa;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }
}
.
The thing is that afterSubmit occurs the data doesn't persist into the db, so It supposed that I should add anything?
On the other hand , is there a way to explicit the TextField label?cause it leaves all in lowercase...
I haven't found to much info about this so any helpfull link would be appreciatted.
Thanks for reading all this !!!
Wadi



 « Return to Thread: Wicket RAD and JTA