dimanche 14 septembre 2008

Understanding Outjection in Seam

Seam come with a new concept it's the @Outjection.

Outjection is pushing a variable in one of the contexts of Seam after you invoke a seam component method.


@Name("abean")
public class ABean {

@Out(scope=ScopeType.SESSION)
public String outString = "st_0";

public void call1(){
outString = "st_1";
}


public void call2(){
outString = "st_2";
}

}


When you invoke one of the method (call1 or call2), the context variable "outString" is created in the session context if it doesn't exist yet or is updated if it already exists. But if no invocation is made on "abean" outString exist in no context at all.

Let's see it from this view



<f:facet name="header">Showing outjection</f:facet>
<br/>

<s:link action="#{abean.call1}"> Call 1 </s:link> <br/>

<s:link action="#{abean.call2}"> Call 2 </s:link> <br/>

<h:outputText value="#{outString}" />


The first time you load this view, you see the two link Call 1 and Call 2 but the outputext is empty.

Once you click Call 1 or Call 2 then you get an output st_1 or st_2 respectivly. Actually you'll never see st_0.

The advantage of this design, is that the buisness method doesn't have to notify the context that the variable they deal with has changed.

Aucun commentaire: