Using JSP, you just want to check layout of the page but you need to deploy
and start the application server. Have you ever had such experiences?
Or have you experienced to cooperate with a designer?
With S2JSF, you don't need such troubles anymore.
The template view of S2JSF is HTML, not JSP, and it makes you free to
such irritated things.
。
Same as Seasar2 requirements, JDK1.4 or higher is required.
All you need to do is just extract S2JSFVx.x.x.zip and import unzipped s2jsfdirectory
to Eclipse workspace(File -> import -> Existing Project into workspace)
The samples of S2JSF is prepared separately, so download and extract it.
Same as before, import unzipped file to Eclipse workspace.
This sample makes the use of Tomcat5 and
Tomcat Plugin.
If you do not intall these, please install before trying these samples.
Starting Tomcat, you can see S2JSF samples as accesing http://localhost:8080/s2jsf-example/ on your browser.
Let's go to http://localhost:8080/s2jsf-example/hello/hello.html?message=aaa.
It must display "Hello aaa" as you see.From this sample, you can get things described below:
The first line in the fig.1, xmlns:m="http://www.seasar.org/maya" specifies namespace.
This URL(http://www.seasar.org/maya) must be fixed.The prefix, which is "m" in the sample, you can use anything you want to use,
"m" is used in the custom.
The next attribute, m:extends, points out extending layout.
To provide consistent look & feel, the layout of pages are constructed by header, menu, body, and footer.
This is very usual need.For corresponding such needs, S2JSF provides function that defining layout of the page in
the based page, and in the each individual pages extends the base page and overwrites specific parts of its page.
So, let's see layout.html.
See the link tag at line 4.By inject attribute, s:link is specifeid.
How to specify this tag is same as the case of JSP.
Prefix of this tas, "s", is described in WEB-INF/classes/jsf.dicon(or WEB-INF/src)
In jsf.dicon, a relevant part is as follows.
In the inserted page, the content that is to be inserted in the insert tag without
the name attribute is described. In other way, you can write a tag for preview outside of insert tag.
In such situation, the outside of insert tag is ignored at the runtime.
For next, let's see menu.html.
Page changing name is specified when the link is clicked by the action attribute of the anchor tag.
There are two ways to use action attribute.
One is to type ${parameter_name.method.name} to call JavaBeans method.
The other is simply to describe string.This way is for changing the specific page.
This page that is named hello is configured at WEB-INF/faces-config.xml.
We are goint to see as follwing part.
By using from-outcome tag, you can specify the page changing name.
Actual path is spcified by to-view-id tag.
If describing redirect tag, the page is redirected.If not, it is forwarded.
Let's back to menu.html.
The child tag of anchor should be specified f:param for giving parameter to changing page.
Let's back to layout.html.
At the line 17 of layout.html, <span m:inject="s:insert" m:name="body"/> defines the body part.
Giving a name by name attribute like this, the page that extended this layout overwrite the contents
by defining <span m:inject="s:insert" m:name="body">...,</span> again.
Take a look at the line 7 of hello.html.You see <span m:inject="f:param" m:name="layoutTitle" m:value="Hello"/>.
It puts the value to layoutTitle, which is defined at layout.html.
To give parameters to parent page, f:param tag is put as the child of body tag.
Between the line 8 to 10 of hello.html, <span m:inject="s:insert" m:name="body"> overwrite the parent page's contents.
To output string to HTML, <span></span> should be used.For example, it should be like
<span m:value="#{message}">hoge</span> at the line9 of hello.html.
We call #{...} as ValueBinding, and we use it when value should be dynamically arranged.
When defining like #{foo}, S2JSF retrieves by the order of request, parameter, session, S2Container and
the first found one is set as value.For example, output should be the content of message parameter
at the line 8 and 9 of figure.1, and "hoge" text of body tag, which is dummy for just checking layout,
is ignored at that time.
When coding like #{foo.property}, S2JSF retrieves #{foo} as we described before,
and then put property.
When you need dynamically changed texts at HTML, value attribute of span tag is needed in this way.
Head tag is ignored when runtime.It is only for preview on browser.
<span m:inject="h:messages" m:globalOnly="false" m:showDetail="true"/> at the line.10,
it is a preparation for output messages when occuring errors.
While globalOnly attribute is true, only global error message, which is not specific input related,
should be displayed.In other way, all error messages are out when globalOnly attribute is false.
<input type="text" m:value="#{addDto.arg1}"/> at line 11 means that input/output tag
works with JavaBeans property. Input value is stored to JavaBeans property if validation is OK.
If NG, input value remains the page.Such input/output well-management is the benefit of using JSF.
With Struts, we need to use String type to store value tempolary at ActionForm.
With JSF, we don't need to do this.
Where do we describe addDto?addDto is described in examples/jsf/dicon/add.dicon as follows:
addDto is managed in request scope if instance attribute of component tag is true as wee see in add.dicon.
And add.dicon is included by app.dicon, which is the parent configuration file.
fig09.app.dicon(partial)
<include path="examples/jsf/dicon/add.dicon"/>
Back to fig07, add.html, <input type="submit" value="calculate" m:action="#{addAction.calculate}"/> at line14
works as calling JavaBeans method(addAction.calculate) when button is clicked.
These features, such as describing as #{varname.methodname} at action attribute of button or link tag, are called MethodBinding.
Methods called by MethodBinding should not have arguments and it's return value should be String.
So, where addAction at line14 is defined?
addAction defines at add.dicon as follows.