Wednesday, 15 September 2010

session bean - Java EE Application to display current server time in seconds -



session bean - Java EE Application to display current server time in seconds -

here's scce i've written. i'm new java web application programming means it's possible i'm missing something. advice newbie moving forwards appreciated. i've tried referencing bundle name no luck. there should referencing session bean in web.xml? because these files in war file within deployed ear file. should note i'm using java server faces, , ee7.

glassfish4 error /index.xhtml @10,78 binding="#{serversessionbean.time}": target unreachable, identifier 'serversessionbean'

index welcome file

<?xml version='1.0' encoding='utf-8' ?> <!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:h="http://xmlns.jcp.org/jsf/html"> <h:head> <title></title> </h:head> <h:body> current server time is: <h:outputtext binding="#{serversessionbean.time}"/> </h:body> </html>

serversessionbean

package com.incredibleifs; import java.util.calendar; import javax.ejb.stateless; import javax.inject.named; @stateless(description = "a stateless session bean hold server generic business methods such getting date , time") @named() public class serversessionbean implements serversessionbeanlocal { @override public int gettime() { homecoming calendar.getinstance().get(calendar.second); } }

the ejb's aren't visible expression language (el) expressions in jsf. can utilize jsf manage bean , inject ejb or annotating ejb @named annotation makes ejb visible expression language (el) expressions in jsf. @named annotation takes simple name of annotated class, puts first character in lowercase, , exposes straight jsf pages. ejb can accessed directly, without backed or managed beans, jsf pages.

second, using 2 notations specifying different types of session beans in same ejb (@singleton/@stateless).

eg.

ejb:

class="lang-java prettyprint-override">package com.incredibleifs; import javax.ejb.stateless; import java.util.calendar; import javax.ejb.singleton; @stateless @named("serversessionbean") public class serversessionbean implements serversessionbeanlocal { @override public int gettime() { homecoming calendar.getinstance().get(calendar.second); } }

xhtml file:

class="lang-xml prettyprint-override"><?xml version='1.0' encoding='utf-8' ?> <!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:h="http://xmlns.jcp.org/jsf/html"> <h:head> <title></title> </h:head> <h:body> current server time is: <h:outputtext binding="#{serversessionbean.time}"/> </h:body> </html>

note name serversessionbean first character in lowercase.

see also:

the java ee 7 tutorial contexts , dependency injection in java ee 6

java-ee session-bean

No comments:

Post a Comment