:-[] :-|| Vivek Khokhar rambles here :-O :-[]

October 9, 2006

Mysql JavaConnector options

Filed under: java — Vivek Khokhar @ 3:14 am

?zeroDateTimeBehavior=convertToNull

This will handle the all zero Dates problem with mysql

March 20, 2006

Navigation in JSF

Filed under: java — Vivek Khokhar @ 8:48 am

Navigation Rules are specified in faces-config.xml by default.
However, you can assign any other name and even use more than one file to store JSF configuration data. To specify configuration files, use lines like the following in your web.xml file:

<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml,/WEB-INF/faces-config2.xml</param-value>
</context-param>

Navigation rules are just like switch case constructs.

For example :

<navigation-rule>
<from-view-id>/pages/input.jsp</from-view-id>
<navigation-case>
<from-outcome>sayHello</from-outcome>
<to-view-id>/pages/greeting.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>sayGoodbye</from-outcome>
<to-view-id>/pages/goodbye.jsp</to-view-id>
</navigation-case>
<navigation-case>
<to-view-id>/pages/default.jsp</to-view-id>
</navigation-case>
</navigation-rule>

is similar in semantics to following Switch case

Switch(output from input.jsp){
case “sayHello”:
jump to /pages/greeting.jsp
break;
case “sayGoodbye”:
jump to /pages/goodbye.jsp
break;
default:
jump to /pages/default.jsp
break;

}

The <from-action></from-action> adds another level of checking while matching Navigation rules.
for example snippet below.. tells to jump to /pages/hello.jsp if hello was returned from GetSomeBean.someAction
<navigation-case>
<from-action>#{GetSomeBean.someAction}</from-action>
<from-outcome>hello</from-outcome>
<to-view-id>/pages/hello.jsp</to-view-id>
</navigation-case>
Here’s an excellent tutorial for this: http://www.jsftutorials.net/jsf-navigation-by-examples.html

Facelets Explored

Filed under: java — Vivek Khokhar @ 8:46 am

JSF’s Application includes:
a default ActionListener, ELResolver, StateManager, NavigationHandler, and ViewHandler.
Facelets is used as the application’s ViewHandler, represented by the class com.sun.facelets.FaceletViewHandler.

An excellent tutorial for kickstart
https://facelets.dev.java.net/nonav/docs/dev/docbook.html#gettingstarted-dependencies

Points to remember :

1. First you create a template file that will decide the layout of your page in a broader sense. or you can call it default view. Mostly using <ui:insert> tags that can be inserted or overwritten upon by child templates. For example: <ui:insert name=”leftPane”> will define a default leftpane html for your page

2. Next you define Child templates that will override the layout as per their need.
The <ui:composition> uses the template attribute to reference main template for look and feel of the page. Its like inheriting look and feel from a Default layout. This is really a powerful way of reusing UI.
If a child template doesn’t override the insertion point with the specified name (title or body), then the default text from the original template is used.

<ui:define> tags are specified with names that match the <ui:insert> tags used in the parent-template.
<ui:define name=”leftpane”> will replace <ui:insert name=”leftPane”> html definition.
This means that when Facelets builds your page, those blocks of content will be placed appropriately in the template. Any text that happens to reside inside the <ui:composition> tag, but outside of the <ui:define> tags is not displayed in the rendered output.

For example a child template for registration page:

<ui:composition template=”/Path-to/parent-layout.xhtml”>
<ui:define name=”leftpane”>
HTML for how left pane will look like in registration page
</ui:define>

This text will not appear in output because this is outside define block, you cannot write outside define blocks, it will be ignored.
</ui:composition>
This text will not appear in output because this is outside composition block, you cannot write outside define blocks, it will be ignored

3. Ok what if you want to print some attribute value of a bean.
In JSF you refer to the Beans as follows :
#{GetNameBean.helloAction} where helloAction is either getter function or someother public member function

Powered by WordPress