Showing posts with label J2EE. Show all posts
Showing posts with label J2EE. Show all posts

8/14/07

JSF code snippet: integrating JSF pages into a plain old JSP


A simple way to include a JSF page into a bigger JSP (sure there's other ways, but this one is easy):
the JSF page must be a subview:

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<f:subview id="myJSFSubview">
.....
</f:subview>

The tricky part is how to include it in the JSP, in a way that is independent of the main JSP. But you just need to include like this:

<% pageContext.include("myJSFpage.jsf"); %>

7/25/07

Finally! I'm a Sun Certified Enterprise Architect for J2EE Technology

I got the final results today, and now I can say I'm a SCEA!
First I took the multiple choice test, then I submitted the assignment (a UML design for a J2EE system) and finally an essay about the assignment.
The fact that is based in the 1.2 spec of J2EE is not THAT important, as is only 20% of the total. I learned many things and validated some other things I already knew.
Later I'll post more details on the assignment.

At least somebody else says that I'm an software architect too!

6/22/07

JSF code snippet: Page scope with Tomahawk save state component

JSF code snippet: Page scope with Tomahawk save state component
By default, JSF backing beans can be only in session or request scope. Having a "page" scope is very useful, so the state is maintained between requests, but is discared when you abandon the page (and not kept in the session). You can easily achieve this by using the UI save state component from MyFaces Tomahawk project.
The bean saved by saveState must be serializable (if you have a dataModel don't forget to declare it transient) and declared of request scope in faces-config.xml

In the jsp
< t:saveState id="saveState" value="#{BackingBean}" />

In web.xml
< context-param>
< param-name> javax.faces.STATE_SAVING_METHOD < /param-name>
< param-value>client < /param-value>
< /context-param>

< filter>
< filter-name>extensionsFilter < /filter-name>
< filter-class> org.apache.myfaces.component.html.util.ExtensionsFilter < /filter-class>
< /filter>


In faces-config.xml
< navigation-rule>
< from-view-id>/myScreen.jsp < /from-view-id>
< navigation-case>
< from-outcome>cancel < /from-outcome>
< to-view-id>/myScreen.jsp < /to-view-id>
< /navigation-case>
< /navigation-rule>
< managed-bean>
< managed-bean-name>BackingBean < /managed-bean-name>
< managed-bean-class>myPackage.BackingBean < /managed-bean-class>
< managed-bean-scope>request < /managed-bean-scope>
< /managed-bean>

The navigation rule to the same screen on cancel has the nice effect of clearing the saved values. That makes implementing a "Clear" button just that easy.

6/21/07

JSF code snippet: No data found message for a table

A short one: display a message when there's no results to display in the dataTable

< h:dataTable value="#{BackingBean.tableModel}"
... rest of the dataTable configuration
>
..... dataTable columns ...
< /h:dataTable>

< h:panelGrid width="100%" rendered="#{BackingBean.tableModel.rowCount == 0}">
< value="#{msgs.noResults}">
< /h:panelGrid>



The datatable will render only the column titles, and then the panel grid with the message will be rendered

UPDATE: I just noticed that while posting, the JSF tags got completely messed up, should be fixed now

6/19/07

JSF code snippet: parent-child lists

(I'm extracting a collection of JSF code snippets from my projects to keep them in a easily accessible place)
Here is an example of parent-child drop downs with multiple child selection, and the list of childs is not rendered until a parent is selected...

In the JSF page:

code:

...
< h:selectOneMenu id="parent" immediate="true"
value="#{BackingBean.selectedParent}"
valueChangeListener="#{BackingBean.changeParent}"
onchange="submit()" />
< f:selectItems value="#{BackingBean.parentsList}" >
< /h:selectManyListbox>

...
< h:selectManyListbox id="childs"
value="#{BackingBean.selectedChilds}"
rendered="#{BackingBean.parentId !=-1 }"
size="4" >
< f:selectItems value="#{BackingBean.childsList}" />
< /h:selectManyListbox>

...

In the backing bean:

code:


...
public void changeParent(ValueChangeEvent event)
{
Long parentId = (Long) event.getNewValue();
selectedChilds=new Long[0];
childList = getChildList(parentId);
}

...

5/11/07

Sun Certified Enterprise Architect part 1 completed!


Good news! I just passed the first part of SCEA with a score of 89%.
Now comes the assignment part, it should be less stressful as there is no time limit and involves arhitecting a solution for a small system and document it in UML diagrams (that’s what I’m supposed to do for a living! :-) )
I must say it didn’t feel very difficult. First I bought Mark Cade’s “Sun Certified Enterprise Architect for J2EE Technology Study Guide” is a little bit short, but is a great overview of the topics and expectations of the exam. Is a truly study guide. I got good notes also from scea yahoogroups list. The mailing list is almost useless, but the files section has good resources.
www.moelholm.com has the best (free) exam simulator, if you pass the mock tests, surely you’ll pass the exam. www.leocrawford.org.uk has a very good review of the important stuff . I read it the day before the test. If you want more links, comments, details, let me know, I'll be happy to share them...
Now, I want to start the part 2 ASAP :-)

(UPDATE 05/14/2007: More links)
Java certification success, Part 4: SCEA
Good (although the stateful session bean lifecycle diagram is incorrect), can be a study guide similar to Cade's book but even shorter. You need to register to download it
Pete Morgan's Sun Certified Enterprise Architect Part 1 Notes
Nice notes, once you learned the topics, this will help you to keep them on your mind
CertMag on the Web Programming Success: The SCEA Certification
A guide to the certification and useful links, some of them old though

And of course, there's plenty of discussion in Javaranch's saloon, like this notes.

(UPDATE 05/17/2007: More links)
I found also this collection of links at Ideartis

4/25/07

JavaServer Faces in the real wolrd


I wrote a paper presenting the JSF framework: JavaServer Faces in the real world. I used JSF last year to build custom functionality integrated into a workflow portal. I'm pretty satisfied with the result. I know JSF has been criticized an some of the points are valid, but I think is better than Struts and far better than JSP/Servlets alone. The ability to integrate components from different libraries (like the Tomahawk components) makes development very easy. Also AJAX integration is very promising (although is not as straightforward as it should be).
Read the paper and tell me what you think...