Wicket RAD and JTA

View: New views
7 Messages — Rating Filter:   Alert me  

Wicket RAD and JTA

by wadi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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




Re: Wicket RAD and JTA

by wfaler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hmm, not sure what the problem is here, I have used both LOCAL and container managed JTA transactions without any problem. If you are using a container managed transaction, are you sure you using a DataSource defined in Glassfish, and that it has everything set up correctly?

As for the afterSubmit(), as it implies, it is called after the DataRequestCycle has already done an "intermediate" commit on the database to write everything into the database before the next page is rendered.

Re: Wicket RAD and JTA

by wadi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi wfaler! The problem was that I used a form instead of a div for the form..Now I have to figure out how to change the textfield labels, internationalization (create button in spanish) and see why the AjaxDefaultTableBean doesn't show the content of the table(how do I select wich columns to show?)
Any help is welcome,
Thanks in advance,
Regards,
Wadi


Re: Wicket RAD and JTA

by wfaler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
Assuming you are using the bean-based approach here (as there are no others implemented yet :D ):

The textlabels for form components and table headers follow Wicket's localization model, but with the key being the fully qualified name of the field, for instance:
the property "name" in the class com.myorg.MyBean would be:
com.myorg.MyBean.name=This is the form label for Name

You can put this in a properties file either corresponding to the page the component is in, or the application.properties, for instance:
MyPage.properties or MyApplication.properties

For tables, you use the annotations in org.wicketrad.propertytable.annotation, you can use @LabelProperty to just display a property on a row, @BookmarkableLinkProperty to create a link that is bookmarkable and so on.
The ordering of columns follows the same rules as for forms, either using the @Order annotation, or failing that, the alphabetical order of fields.

Hope that helps!

Re: Wicket RAD and JTA

by wadi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

WOW!Thanks! You just save me a lot of time!Tanks again!!!!!

Re: Wicket RAD and JTA

by wadi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi All again. I could solve the i18n problem. The thing is that I don't understand how to change the text of an input item of a custom panel, let's say FilterPanel:
<input type="submit" value="Filter" wicket:id="button"/>

How can I change the value="Filter"  without changing the html and rebuilding the project?
Thanks in advance,
Wadi

Re: Wicket RAD and JTA

by wfaler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
Sorry for the late reply:
Hmm, I don't remember right off the bat - but I think there should be a "IModel buttonModel" constructor argument for the filter panel, if there is not, it is probably an omission, bit since it has a wicket:id I would presume that it has this.

So: simply put in your IModel with the text into that argument, and it should render your custom label.

wadi wrote:
Hi All again. I could solve the i18n problem. The thing is that I don't understand how to change the text of an input item of a custom panel, let's say FilterPanel:
<input type="submit" value="Filter" wicket:id="button"/>

How can I change the value="Filter"  without changing the html and rebuilding the project?
Thanks in advance,
Wadi