I habe been studying Seam framework for a long time. Altough i do not use it at work, i like its approach. It is very interesting. But i have some doubts. After reading Seam in Action book, i think it is not possible you bind more than one parameter to a business method. Something like
@Stateless
public class BusinessObjectImpl implements BusinessObject {
public void doSomething(SomeObject i01, SomeObject i02 and so on...) {
}
}
Am i right ? Because of it, you have two approachs:
//
@Stateless
public class BusinessObjectImpl implements BusinessObject {
@In
private SomeObject input01;
@In
private SomeObject input02;
@In
private SomeObject input03;
@Out
private SomeObject output01;
@Out
private SomeObject output02;
@Out
private SomeObject output03;
public void doSomething() {
// some code
}
}
//
@Stateless
public class BusinessObjectImpl implements BusinessObject {
public void doSomething() {
SomeObject input = Context.get("contextualName");
SomeObject output ...
Context.set("contextualName", output);
}
}
If the first approach is used in a Stateless where it has many methods, so i think it is better you model your business object by using Command pattern. Am i right ? Something like
public class DoSomething implements Command {
@In
private SomeObject input01;
@In
private SomeObject input02;
@Out
private SomeObject output01;
public void execute() {
}
}
And you: what pattern (and good practices) do you use to avoid many member fields in a Stateless business object ?
regards,
No. That's completely wrong. Of course you can have many parameters in Seam methods. It's just Java. This code is fine:
@Stateless
public class BusinessObjectImpl implements BusinessObject {
public void doSomething(SomeObject i01, SomeObject i02) {
}
}
Of course one thing that Seam allows you do to is to inject any other Classes that you may find useful. Maybe like this:
@Stateless
public class BusinessObjectImpl implements BusinessObject {
@In
private AnotherObject anotherObject;
public void doSomething(SomeObject i01, SomeObject i02) {
anotherObject.someMethod(i01, i02);
}
}
EDIT (based on comment):
There are ways of passing multiple parameters from a page using JBoss EL (which allows for objects as parameters). For example
<h:form>
<h:commandButton action="#{firstBean.performAction(secondBean, thirdBean)}">Go</h:commandButton>
</h:form>
Where your SecondBean
and ThirdBean
are already populated in your Session/Conversation (with their relevant @Name
) and your FirstBean
would look something like:
@Name("firstBean")
@Stateless
public class FirstBean {
public void performAction(SecondBean secondBean, ThirdBean thirdBean) {
//stuff
}
}
But this approach isn't exactly elegant as it relies on SecondBean and ThirdBean being in your current Session/Conversation. You may be better off to follow an approach of having a page Controller or Backing Bean. This can be a POJO that then calls your SLSB. For example:
<h:form>
<h:commandButton action="#{backingBean.performAction}">Go</h:commandButton>
</h:form>
And the Backing Bean:
@Name("backingBean")
@Scope(ScopeType.CONVERSATION)
public class BackingBean {
@In
private FirstBean firstBean;
@In
private SecondBean secondBean;
@In
private ThirdBean thirdBean;
public void performAction() {
firstBean.performAction(secondBean, thirdBean);
}
}
Which starts to look a lot like your original question ;-)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.