3 Replies Latest reply on Mar 29, 2011 12:51 PM by Alexey Kazakov

    How to create seam web project programmatically?

    Tamas Szabo Newbie

      Hi!

       

      I want to create a seam web project programmatically like I can create a simple java project with JDT. Could someone provide me some information about the issue?

        • 1. How to create seam web project programmatically?
          Alexey Kazakov Master

          Just create a Java project using JDT API and then enable Seam support for the project:

           

          IProject project = ...;  // Your Java project.

           

          org.jboss.tools.common.model.util.EclipseResourceUtil.addNatureToProject(project, org.jboss.tools.seam.core.ISeamProject.NATURE_ID);  // Enables Seam builder and nature.

                                        if(!project.hasNature(org.jboss.tools.jst.web.kb.IKbProject.NATURE_ID)) {

                                                  org.jboss.tools.common.model.util.EclipseResourceUtil.addNatureToProject(project, org.jboss.tools.jst.web.kb.IKbProject.NATURE_ID); // Enables JBoss Tools KnowledgeBase builder/nature required by Seam/JSF code completion/validation/hyperlinks.

                                        }

                                        org.jboss.tools.common.model.util.EclipseResourceUtil.addBuilderToProject(project, org.eclipse.wst.validation.internal.plugin.ValidationPlugin.VALIDATION_BUILDER_ID);  // Enables WST validation which is required by Seam validation.

          Or you can create a WTP dynamic web project instead of plain Java project if you want a full JSF support on XHTML/JSPs.

          • 2. How to create seam web project programmatically?
            Tamas Szabo Newbie

            Hi!

             

            I have created my web project with this code segment finally:

             

            SeamProjectWizard wizard = new SeamProjectWizard();

            wizard.init(PlatformUI.getWorkbench(), null);

            WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wizard);

            dialog.open();

                   

                    if (dialog.getReturnCode() == Dialog.OK) {

                       

                        try {

                            ejbProjectName = wizard.getDataModel().getStringProperty(ISeamFacetDataModelProperties.SEAM_EJB_PROJECT);

                            System.out.println("ejb project name "+ejbProjectName);

                        }

            ...

             

            I want to retrieve the ejb project's name, but I get an exception using the above. Can someone suggest a solution?

            • 3. How to create seam web project programmatically?
              Alexey Kazakov Master

              You should use model of Seam facet instead of Seam wizard:

              ...

              Set<Action> actions = wizard.getFacetedProjectWorkingCopy().getProjectFacetActions();

              for (Action action : actions) {

                     if(ISeamFacetDataModelProperties.SEAM_FACET_ID.equals(action.getProjectFacetVersion().getProjectFacet().getId())) {

                          IDataModel seamFacetModel = (IDataModel)action.getConfig();

                          ejbProjectName = seamFacetModel.getStringProperty(ISeamFacetDataModelProperties.SEAM_EJB_PROJECT);

                          break;

                     }

              }