Tuesday, October 28, 2014

Maven Central Repository as proxy in Nexus manager.

In nexus console

Figure 1. Set Repository Central proxy point to http://repo1.maven.org/maven2/

Figure 2. Add Repository Central proxy into Group Repositories.

The Ordered Group Repositories is used to order repositories, which is applied to look up library respectively.

In settings.xml, create a nexus profile and also active a nexus profile.

<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://172.17.2.212:8089/nexus/content/groups/public</url>
</mirror>
</mirrors>

<profiles>

<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository>
<id>primeface-releases</id>
<url>http://172.17.2.212:8089/nexus/content/repositories/primeface-releases/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>primeface-releases</id>
<url>http://172.17.2.212:8089/nexus/content/repositories/primeface-releases/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
  </profiles>
  
  <activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
  </activeProfiles>

Friday, October 3, 2014

Programatically add tabs and contents using PrimeFaces.

Example code for adding new tabs and contents dynamically.

XHTML
<h:form id="form">
    <p:tabView id="tabview"

               cache="false"

               activeIndex="0"

               dynamic="true"

               binding="#{tabbedView.tabView}">

        <p:tab title="a">

            <p:outputLabel value="aaa" />

        </p:tab>

        <p:tab title="b">

            <p:outputLabel value="bbb" />

        </p:tab>

        <p:tab title="c">

            <p:outputLabel value="ccc" />

        </p:tab>

    </p:tabView>

    <p:outputLabel value="dynamic content" />

    <p:inputText id="dynamicText" value="#{tabbedView.dynamicText}" />

    <p:commandButton value="add tab"

                     process="@this,dynamicText"

                     update="tabview"

                     actionListener="#{tabbedView.addNewTab}">

    </p:commandButton>
    
</h:form>


ManagedBean
@ManagedBean

public class TabbedView {

    private TabView tabView;

    private String dynamicText;

    @PostConstruct

    public void init() {

        tabView = new TabView();

    }

    public TabView getTabView() {

        return tabView;

    }

    public void setTabView(TabView tabView) {

        this.tabView = tabView;

    }

    public String getDynamicText() {

        return dynamicText;

    }

    public void setDynamicText(String dynamicText) {

        this.dynamicText = dynamicText;

    }


    public void addNewTab(ActionEvent event) {

        OutputLabel label = new OutputLabel();

        label.setValue(dynamicText);

        Tab newTab = new Tab();

        newTab.setTitle(UUID.randomUUID().toString());

        newTab.getChildren().add(label);

        tabView.getChildren().add(newTab);

    }

}

Thursday, October 2, 2014

Default p:selectOneRadio selection in Primefaces.

This is my demonstration which present how to default p:selectOneRadio value in p:dataTable
XHTML
<h:form>

    <p:dataTable var="catalog" value="#{radioView.catalogs}">

        <p:column headerText="City">

            <p:selectOneRadio id="city"

                              value="#{catalog.city}"

                              columns="3">

                <f:selectItems value="#{radioView.cities}"

                               var="c"

                               itemLabel="#{city}"

                               itemValue="#{city}"/>

            </p:selectOneRadio>

        </p:column>

    </p:dataTable>

    <p:commandButton value="changeSelection"

                     process="@form"

                     update="@form"

                     actionListener="#{radioView.changeSelection}"/>

    <p:commandButton value="submit"

                     process="@form"

                     update="@form"

                     actionListener="#{radioView.submit}"/>

</h:form>


ManagedBean
@ManagedBean
public class RadioView {

    private List<Catalog> catalogs;
    private List<String> cities;

    @PostConstruct
    public void init() {
        cities = new ArrayList<String>();
        cities.add("San Francisco");
        cities.add("London");
        cities.add("Paris");

        //default radio value
        Catalog c1 = new Catalog("San Francisco");
        Catalog c2 = new Catalog("London");
        Catalog c3 = new Catalog("Paris");
        Catalog c4 = new Catalog("London");

        catalogs = new ArrayList<Catalog>();
        catalogs.add(c1);
        catalogs.add(c2);
        catalogs.add(c3);
        catalogs.add(c4);
    }
    public List<Catalog> getCatalogs() {
        return catalogs;
    }
    public void setCatalogs(List<Catalog> catalogs) {
        this.catalogs = catalogs;
    }
    public List<String> getCities() {
        return cities;
    }
    public void changeSelection(ActionEvent event){
        for (Catalog catalog : catalogs) {
            catalog.setCity("San Francisco");
        }
    }
    public void submit(ActionEvent event) {
        for (Catalog catalog : catalogs) {
            System.out.println(catalog.getCity());
        }
    }
}


Domain
public class Catalog implements Serializable{

    private String city;
    public Catalog(String city){
        this.city = city;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }
}