Thursday, 24 June 2010

JSF 2.0 My First Look

Heard enough about JSF 2.0 to look into it today. Step 1was to find an IDE which supported it but unfortunately JDeveloper 11g didn't, so for the first time in a long time I had to move into another IDE and NetBeans IDE seemed the way to go here.

Although I just created some very basic demos it didn't take long to get into building tables from collections and other more useful demos. Few things really impressed me about JSF 2.0.

1. Finally I can add references to my model attributes as follows without the need to use a h:outputText component

#{TaskBean.info}

2. You can simply use a default bean name for backing beans without the need to declare beans with managed-bean in faces-config.xml. You simple put @ManagedBean above the class definition.

@ManagedBean(eager=true)
@SessionScoped
public class CalculatorManagedBean implements Serializable {
public static char[] operands = { '+', '-', '*', '/' };

3. The use of Facelets, not JSP, as the standard technology for all your JSF pages. So you name your page pas.xhtml and can reference it as pas.jsf as long as your web.xml contains the following.


<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>


4. No real need to define explicit navigation rules. If your bean methods return a a string as follows then the resulting page pas.xhtml will be called.

return "pas";

Hope to spend more time on JSF 2.0 and of course there is more to it then just this but thats a good enough start for me.

Monday, 21 June 2010

Query a RAC Cluster to get Connected users

While testing FCF with JDBC it's often useful to know how many connections I have on each instance within the cluster. Sure it's easy enough to get the instance I am connected to from the JDBC side , but if you run a query as follows using the GV$ tables on the RAC cluster you can get the info as follows for all the connections within your pool.

SQL Query

col username format a10
col service_name format a20
col host_name format a30
col instance_name format a15

select s.username, s.service_name, i.INSTANCE_NAME, i.HOST_NAME
from gv$session s, gv$instance i
where i.INST_ID = s.INST_ID
and s.username = 'SCOTT'
and s.service_name = 'HASERVICE'
/

Note: You will need to replace the username / service name with your details.

Results

  
SQL> @users

USERNAME SERVICE_NAME INSTANCE_NAME HOST_NAME
---------- -------------------- --------------- ------------------------------
SCOTT HASERVICE orcl1 apemrac1.au.oracle.com
SCOTT HASERVICE orcl1 apemrac1.au.oracle.com
SCOTT HASERVICE orcl1 apemrac1.au.oracle.com
SCOTT HASERVICE orcl1 apemrac1.au.oracle.com
SCOTT HASERVICE orcl2 apemrac2.au.oracle.com
SCOTT HASERVICE orcl2 apemrac2.au.oracle.com
SCOTT HASERVICE orcl2 apemrac2.au.oracle.com
SCOTT HASERVICE orcl2 apemrac2.au.oracle.com
SCOTT HASERVICE orcl2 apemrac2.au.oracle.com
SCOTT HASERVICE orcl2 apemrac2.au.oracle.com

10 rows selected.

Wednesday, 16 June 2010

trimDirectiveWhitespaces with JSTL

While using JSP I always use JSTL to avoid any use of java on the JSP itself. To get a quick world cup 2010 tipping competition up and running I found that my response pages using JSTL contained just way to much white space. Luckily in the JSP 2.1 world we can use the page directive trimDirectiveWhitespaces to easily remove that unwanted white spaces. Basically it's done as follows


<%@ page
contentType="text/html;charset=windows-1252"
trimDirectiveWhitespaces="true" %>

So to see how well this works simply use the code below in JDeveloper 10.1.3 (JSP 2.0) and then in JDeveloper 11g (JSP 2.1) and view the source of the page after running it.

Note: When running this code in JDeveloper 10.1.3 you will have to remove trimDirectiveWhitespaces="true" as it does not support that.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charset=windows-1252" trimDirectiveWhitespaces="true" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
<title>JSP 2.1 - trimDirectiveWhitespaces JSTL demo</title>
</head>
<body>
<h2>JSP 2.1 - trimDirectiveWhitespaces JSTL demo</h2>

<c:forEach var="row" begin="1" end="5">
<c:choose>
<c:when test="${row == 1}">
<font color="green">
<c:out value="At row 1"/>
</font>
<br />
</c:when>
<c:otherwise>
<c:choose>
<c:when test="${row != 1}">
<font color="Red">
<c:out value="Not at row 1"/>
</font>
</c:when>
<c:otherwise>
<c:out value="Should never get here"/>
</c:otherwise>
</c:choose>
<br />
</c:otherwise>
</c:choose>
</c:forEach>

</body>
</html>

Thursday, 3 June 2010

Tam and her DBA Blog

Tam has entered the world of blogging and someone who I would frequently go to whenever I had RAC/DBA issues. In fact she would sit right next to me for a year or so. She is now leaving Oracle in a few days but her blog will continue and has some very useful RAC/RDBMS/EM information. Worth a read that's for sure.

http://sosdba.wordpress.com/

Thanks Tam.