[Gukulkan]

Learn, develop, play.

Input Eclipse console

For to be able to enter data in the IDE Eclipse console, write these lines, otherwise compiler ignore you


Scanner scanner = new Scanner(System.in);
input = Integer.parseInt(scanner.nextLine());

Now you’ll be able to enter green symbols in the Eclipse console and the program will be waiting for the Enter key

Managed Beans in JSF and XHTML page

So, now we should connect bean with page.

Take this code:

@Named
@SessionScoped
public class HelloBean implements Serializable {

	//business logic and whatever methods...

}

Change it:

@Named("mybean")
@SessionScoped
public class HelloBean implements Serializable {
	public String myMethod(){
            return "Hello!";
        }

}

You can see that we change annotation Named and add one method, which return string “Hello!”  .

Now, show it on page.

<?xml version=”1.0″ encoding=”UTF-8″?>
<ui:composition template=”/WEB-INF/templates/default.xhtml”
xmlns=”http://www.w3.org/1999/xhtml”
xmlns:ui=”http://java.sun.com/jsf/facelets”
xmlns:f=”http://java.sun.com/jsf/core”
xmlns:h=”http://java.sun.com/jsf/html”
xmlns:a4j=”http://richfaces.org/a4j”
xmlns:rich=”http://richfaces.org/rich”
xmlns:my=”http://java.sun.com/jsf/composite/components”>
<ui:define name=”content”>

<h1>#{mybean.myMethod()} Welcome!</h1>
</ui:composition>

You can see string “Hello! Welcome!” on our page.

To be continued!