Posts Tagged seam

Understanding Nested Conversations

I had a bit of epiphany on the subject of nested conversations the other day when I was thinking about them and thought I’d share. I think nested conversations have been a little misunderstood with people unsure of how to use them, myself included, but I think I have found the best way to think of them.

In summary, nested conversations do for regular conversations what conversations do for session scope. With session scope, you cannot have mutliple instances of a named variable, you have to put each variable instance in its own conversation where it will be unique. However, if you want to have multiple instances of a named variable within the conversation, again, you cannot and you have the same problem you have with the session scope, that variables must be unique. Therefore you have to have each variable in its own nested conversation under the main conversation the same way we had the top level conversation under the session scope.

In some weird web app which lets you pick a person and then put costumes on them, you might have a main page where you select the person, and then in separate browser windows you can pick different outfits for that person. You put the selected person value in a different conversation so the value of #{selectedPerson} is local to the conversation allowing multiple selected people in different browser windows. This overcomes the limitations of the session which allows only one value for #{selectedPerson}

However, if you had that conversation open in multiple windows or tabs so you can compare different costumes on that person, there would only be one value of #{selectedCostume} for the conversation shared between all windows. As you select a costume in one window, it would affect all the other windows as they share the variable in that conversation. Using nested conversations would allow the conversation to have different values for the selected costume under the same parent conversation with the same selected person.

Taking it further you could select the person in the top level conversation, select the costume in the nested conversation, and then you could have multiple windows open with further nested conversation letting you pick different shoes to go with that costume. Also, if you change the person in the top level conversation, it will change the selected person for all windows using that conversation or any of its nested conversations.

I’m not sure there is a great need for nested conversations, I’ve never really used them or found the need and I don’t think users open that many browser windows or tabs to create different logic paths within a conversation. I think it is acceptable to limit the data isolation to a single conversation level.

Tags: , ,

Seam is Dead, Long live Seam

With Weld 1.0, the reference implementation of JSR 299 – Java Contexts and Dependency Injection now released, attention at JBoss has no doubt turned to Seam 3 which is going to be built on top of Weld. Red Hat and JBoss are committed to returning innovations back the JCP as is the case with Seam which not only resulted in JSR 299, but has also influenced a number of other JSRs especially JSF 2. With JSR 299 standardizing the Seam ’style’ of development it also brings about a some fundamental game changes for Seam 3 (hence the title) as much of the strength of Seam becomes part of the JEE standards.
Read the rest of this entry »

Tags: , , , ,

Conversational Pitfalls

Seam conversations have certain rules that you need to be aware of when using them. This article came about because for the last couple of years, the same questions have been asked on the Seam forums regarding conversations. It is also a couple of issues that cropped up while I was working on the Seam vs. Spring Web Flow articles. Some of the problems are uncannily similar with similar solutions, so parts of this series may be of interest to non-Seam users. Additionally, it seems like a lot of this stuff will also apply to the conversational pieces of JSR 299 – Contexts and Dependency Injection which will be a part of JEE 6.
Read the rest of this entry »

Tags: , , , , ,

Glassfish, Netbeans and JSF 2.0 Test Drive

I’ve spent some time in the last couple of weeks playing around with Glassfish, Netbeans 6.8 Beta (and milestone 2 before it) and JSF 2.0, and I have to say that this is turning out to be a really good set of development libraries and tools.
Read the rest of this entry »

Tags: , , , , , ,

Logging Conversation Demarcation In Seam

One way to see where your conversations start and end is to use the Seam event model to observe the conversation start and ends.

@Name("conversationListener")
@Scope(STATELESS)
public class ConversationListenerBean implements ConversationListener {

	@Logger
	private Log log;

	@In
	private Conversation conversation;

	@Observer(value="org.jboss.seam.beginConversation")
	public void observeConversationStart() {
		log.debug("Conversation #0 Started",conversation.getId());
	}

	@Observer(value="org.jboss.seam.endConversation")
	public void observeConversationEnd() {
		log.debug("Conversation #0 Ended",conversation.getId());

	}
}

Just add this bean into your project and it will automatically log when you start and end conversations.

Tags: ,

Notes On Choosing A Web Framework

I’m looking at starting a new project and once again find myself choosing between frameworks. Having spent some time evaluating different ones I wrote up some notes to share and get some feedback that might alter my thoughts or opinions. Here’s the criteria I’m using to choose a framework in no particular order.
Read the rest of this entry »

Tags: , , , , , ,

Seam vs Spring Web Flow – vs Wicket

In the fifth part of this four part series, I decided to give a non-conversational framework a try and implemented the same application with Wicket which is a semi-stateless framework.

(update : If you have already read the previous version only chapter 5 is new and has the Wicket example and final comparison.)

Enjoy,

HTML
Single Page HTML
PDF


Tags: , , ,

Timing JSF Requests Using a Phase Listener

One easy way of determining how long it takes to return a page from Seam, and/or JSF is to use a phase listener. This phase listener below logs the end of each phase of the JSF lifecycle and measures the time from the start of the RESTORE_VIEW phase (the first phase in the lifecycle and the start of the request) to the end of the RENDER_RESPONSE phase which is the last one. Logging the end of each stage of the cycle lets you see what else is going on during each phase of the cycle.

public class LogPhaseListener implements PhaseListener {

	public long startTime;

	private static final LogProvider log = Logging
			.getLogProvider(LogPhaseListener.class);

	public void afterPhase(PhaseEvent event) {
		if (event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
			long endTime = System.nanoTime();
			long diffMs = (long) ((endTime - startTime) * 0.000001);
			if (log.isDebugEnabled()) {
				log.debug("Execution Time = " + diffMs + "ms");
			}
		}
		if (log.isDebugEnabled()) {
			log.debug("Executed Phase " + event.getPhaseId());
		}
	}

	public void beforePhase(PhaseEvent event) {

		if (event.getPhaseId() == PhaseId.RESTORE_VIEW) {
			startTime = System.nanoTime();
		}
	}

	public PhaseId getPhaseId() {
		return PhaseId.ANY_PHASE;
	}

}

To use this, simply add the class to your project and insert a new phase listener in the faces-config.xml file.


package.name.LogPhaseListener
  

While it may not be totally accurate, it at least gives you an idea of the scale of the duration of a request (i.e. 68ms versus 394ms). I’ve used this fairly effectively in a few projects to cut out some bottlenecks as well as comparing and contrasting different JSF frameworks.

Tags: , ,

Seam vs Spring Web Flow Part 4 – Conclusion

The last installment is finally ready. After many a re-write and consideration of all the issues to come to a fair conclusion, especially as new versions were coming out and new features are being added, I’m finally able to publish it. Framework Comparisons – are they ever completed? Anyways, here it is in all it’s ….well, it’s here. Enjoy.

HTML
Single Page HTML
PDF

Tags: , ,

Spring vs Seam Part 4 – Coming Soon (honest)

I know it has been a while since I pushed out my last piece on Spring Web Flow vs Seam, but I am still trying to get it ready. With Christmas, software releases at work leading to a hectic work schedule, and other stuff I have limited time. Furthermore, I am still re-writing parts of it, and I end up digressing into related info that is not central to the piece. Also, I am still having difficulty accurately writing up the final conclusion in a fair, and informed manner.
However, hopefully, I will get it completed in the next week here and I can get it released. I may also have some additional material for blog posts.

Tags: , ,