Home | Tutorials | Smart-Cloud | Smart-EIS | License | FAQ | Contact

Last Updated: March 25, 2021

Smart-Cloud Web project simplfies building Java web applications based on JSF and PrimeFaces. Also, it could be used for plain JSP and Servlets development as well.

Steps:

  1. Create Maven project with the following pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.jalalkiswani</groupId>
	<version>4.0.4</version>
	<artifactId>smart-cloud-web-simple-example</artifactId>
	<packaging>war</packaging>
	<properties>
		<smart-cloud.version>4.0.8</smart-cloud.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>com.jalalkiswani</groupId>
			<artifactId>smart-cloud-web</artifactId>
			<version>${smart-cloud.version}</version>
		</dependency>
		<dependency>
			<groupId>com.jalalkiswani</groupId>
			<artifactId>smart-cloud-standalone</artifactId>
			<version>${smart-cloud.version}</version>
			<scope>provided</scope>
		</dependency>
	</dependencies>
	<build>
		<finalName>app</finalName>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.8.1</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<version>3.2.3</version>
				<configuration>
					<failOnMissingWebXml>false</failOnMissingWebXml>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

If you are using Eclipse, be sure to refresh your project (select your project→ right click→ Maven→ Update Project)

  1. Create xhtml page at src/main/webapp/index.xhtml with the following contents:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
	xmlns:h="http://xmlns.jcp.org/jsf/html"
	xmlns:f="http://xmlns.jcp.org/jsf/core"
	xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
	<h:form>
		<p:autoUpdate />
		<p:growl />
		<p:panelGrid columns="2" style="margin:auto">
			<f:facet name="header">
				<h:outputText value="Smart-Cloud-Web Demo" />
			</f:facet>
			<p:outputLabel value="Please enter you name: " />
			<p:inputText value="#{controller.name}" />
			<f:facet name="footer">
				<p:commandButton value="Say Hello" action="#{controller.sayHello()}" />
			</f:facet>
		</p:panelGrid>
	</h:form>
</h:body>
</html>
  1. Create controller (JSF Managed Bean) at src/main/java/com/app/Controller.java with the following contents:

package com.app;

import javax.faces.bean.ManagedBean;

import com.jk.web.faces.mb.JKManagedBean;

@ManagedBean(name = "controller")
public class Controller extends JKManagedBean {
	String name;

	public String sayHello() {
		success("Hello, " + name);
		return null;// return to the same page when the action finish
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}
  1. Create App class at src/main/java/com/App.java with the following contents:

package com.app;

import com.jk.web.embedded.JKWebApplication;

public class App {
  public static void main(String[] args) {
	JKWebApplication.run();
  }
}

Thats it, now run your App class, in few seconds your browser will open and you should see something like this:

Output

Full example source-code can be found at https://github.com/smartapi-com/smart-cloud-web-simple


Home | Tutorials | Smart-Cloud | Smart-EIS | License | FAQ | Contact