ERLEDIGT
NEIN
NEIN
ANTWORTEN
13
13
ZUGRIFFE
590
590
EMPFEHLEN
-
Hallo ihr lieben
Ich habe da ein kleines Problem. In meinem Webprojekt bestücke ich in einem Stateful-Bean eine Variable. Wenn ich das Bean dann woanders wieder einbinde ist der Wert null, warum?
Ich binde das Bean wie folgt ein:
Code :1 2
@EJB private Manager manager;
was mache ich falsch?
-
Hi,
Nutzt Du ein Framework ?
Eventuell muss dann die Lebensdauer der bean angegeben werden, z.B. per :
@Scope(ScopeType.SESSION)
ist natürlich nur Spekulation, aber probieren kann man es ja mal
Eine andere Möglichkeit ist, dass du bei der @In annotation das Feld required setzt :
@In(required=true)
dann siehst Du warum der Wert NULL ist aufgrund der geworfenen exceptions.
Edit :
Falls du kein Framework verwendest musst du (statt @In) anscheinend :
@TransactionAttribute (TransactionAttributeType.REQUIRED)
über die Stateful Session Bean setzen.
Grüße,
TonteriaGeändert von Tonteria (09.08.10 um 17:52 Uhr)
-
Ich benutze Seam als Framework.
Die Scope-Annotation hab ich bereits in meinem Bean. Wenn ich die In-Annotation verwende bekomme ich bei laden der Application einen Fehler weil der Wert null ist, was aber auch bei ersten Laden normal ist, da ich die Variable erst im weiteren Verlauf der Application setzte.
Es wundert mich etwas das auf der Client-Seite der Wert korrekt angezeigt wird und wenn ich dann den Wert in einem anderen Bean abrufen will er null ist. Ich habe das Gefühl, dass eine neue Instance von dem Bean erzeugt wird und darum der Wert null ist. Aber es ist doch korrekt das Bean so einzubinden wie ich das oben mache, oder?
-
Hmm,
@EJB habe ich in Seam noch nicht gesehen/verwendet. Ich gehe davon aus, dass man es nicht benötigt. @In ist für das Injizieren einer Bean in eine andere.
Probier mal :
@In(create=true)
oder
@In(create=true, required=false)
, heisst eine Leere Instanz wird erstellt und die Werte können später gesetzt werden.Geändert von Tonteria (10.08.10 um 09:47 Uhr)
-
Ach so....
Geht das überhautp die Werte aus einem StatefulBean in einem anderen StatefulBean zu verwenden?
-
Hey,
geht glaub ich schon, weiß nur nicht ob es der Intention, durch die Stateful Beans die HTTP-Session zu ersetzen, gerecht wird. Stateful Beans sind m.E.n. nur für Session handling. Funktionieren sollte es trotzdem. Kannst du nicht die stateful-bean in eine entity-bean umwandeln ?
-
Umwandeln nicht, aber du hast recht, ich könnte für die Werte die ich über die ganze Application brauche eine Entity-Bean schreiben.
Das probiere ich mal.Geändert von ceene (10.08.10 um 10:10 Uhr)
-
Wie mache ich das denn am besten?
Ich hab jetzt ein Entity-Bean
in dem soll der Client gespeichert werden, damit ich den dann über die Application über verwenden kann.Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
@Entity public class ClientMerker implements Serializable { @Id @Column(name="CLIENT_ID") private long clientId; @Column(name="COMPANY_NAME") private String companyName; private String zip; private String city; @Column(name="CITY_DISTRICT") private String cityDistrict; ......
Wie muss ich das Entity-Bean denn in den Statefull-Beans einbinden?Geändert von ceene (10.08.10 um 10:27 Uhr)
-
Kommt drauf an, wie du die Daten manipulieren willst. Soll die Stateful bean ein/eine Reihe von Formularen managen ? Wenns nur ein Formular ist, reicht conversation-scope.
Der UnitName wird in der persistence.xml spezifiziert.PHP-Code:
import everything.needed.*;
@Name("clientformular")
@Stateful
@Scope(ScopeType.CONVERSATION)
public class ClientAction implements ClientInterface {
@In (create=true, required=false)
@Out
private package.ClientMerker clientmerker;
@PersistenceContext (type = PersistenceContextType.EXTENDED, unitName="name")
private EntityManager em;
...
}
Beispiele sind auch auf seamframework.org zu finden. Leider ist die Seite sehr langsam zur Zeit.
-
Hab das so wie du beschrieben hast eingebaut
Code :1 2
@In(required=false, create=true) @Out ClientMerker clientmerker;
Bekomme aber einen Fehler beim Starten des Applikations-Servers
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
...... at java.lang.Thread.run(Unknown Source) Caused by: javax.el.ELException: /login.xhtml @43,53 value="#{managerxq.clientList}": Error reading 'clientList' on type org.javassist.tmp.java.lang.Object_$$_javassist_50 at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:76) at javax.faces.component.UISelectItems.getValue(UISelectItems.java:141) ... 48 more Caused by: javax.ejb.EJBException: org.jboss.seam.RequiredException: @Out attribute requires non-null value: managerxq.clientmerker at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:63) at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83) at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:83) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77) at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.stateful.StatefulContainer.localInvoke(StatefulContainer.java:206) at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:119) at $Proxy202.getClientList(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.jboss.seam.util.Reflections.invoke(Reflections.java:20) at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31) at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:72) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:57) at org.jboss.seam.interceptors.RemoveInterceptor.aroundInvoke(RemoveInterceptor.java:40) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69) at org.jboss.seam.interceptors.SynchronizationInterceptor.aroundInvoke(SynchronizationInterceptor.java:31) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69) at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:103) at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:50) at org.javassist.tmp.java.lang.Object_$$_javassist_50.getClientList(Object_$$_javassist_50.java) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at javax.el.BeanELResolver.getValue(BeanELResolver.java:62) at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53) at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72) at org.apache.el.parser.AstValue.getValue(AstValue.java:97) at org.apache.el.ValueExpressionImpl 11:58:32,906 ERROR [STDERR] .getValue(ValueExpressionImpl.java:186) at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71) ... 49 more Caused by: org.jboss.seam.RequiredException: @Out attribute requires non-null value: managerxq.clientmerker at org.jboss.seam.Component.outjectAttribute(Component.java:1396) at org.jboss.seam.Component.outjectAttributes(Component.java:1387) at org.jboss.seam.Component.outject(Component.java:1246) at org.jboss.seam.interceptors.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:48) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69) at org.jboss.seam.interceptors.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:27) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69) at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:103) at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:53) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118) at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:71) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79) .......
Wo auf der Seite sind denn die Beispiele ich finde da nicht wirklich wasGeändert von ceene (10.08.10 um 12:04 Uhr)
-
Hey, schreib bei @Out(required=false) ... oder lass das @Out besser ganz weg, es ist nicht essentiell, dient nur dazu dass properties leichter adressiert werden können.
Für den Anfang solltest du dir die Beispiele unter :
http://docs.jboss.com/seam/latest/en.../tutorial.html ansehen, wenn du auf exceptions stößt, such entweder bei seamframework.org oder frag hier nach. Ich hoffe du hast Erfolg
Viel weiter bin ich auch noch nicht
-
Ok jetzt geht es........
Ich danke dir vielmals
Werd mir das tutorial nochmal angucken.
Danke nochmal
-
lol, was geht ? Der JBoss fährt hoch aber das gewünschte Verhalten ist doch jetzt nicht schon da oder ? Das wäre ziemlich seltsam für Seam-Verhältnisse

Als Antwort auf deine nächsten Fragen
würd ich dir empfehlen das Beispiel 1.27 durchzugehen, wo die DB-Persistierung durchgenommen wird inklusive EntityManager-Methoden. Werd mir das auch mal genauer zu Gemüte führen.
-
alles geht
JBoss fährt hoch und ich bestücke in einem Bean meine EntityBean und kann es im anderen Bean abrufen......
Alles perfekt
Ähnliche Themen
-
ClassCastException bei Aufruf einer Stateful Session Bean
Von Urmel103 im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 12Letzter Beitrag: 13.02.09, 19:03 -
Array in Session verliert Werte
Von boykottke im Forum PHPAntworten: 10Letzter Beitrag: 25.03.08, 12:29 -
EJB3 - Instanz von Remote Stateful Bean an Client zurückgeben?
Von sepan im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 5Letzter Beitrag: 15.07.07, 14:33 -
Objekt verliert Werte
Von ZeroEnna im Forum Javascript & AjaxAntworten: 9Letzter Beitrag: 27.06.06, 09:08 -
DVD-Menü verliert seine Funktion.
Von BuelentAyyuece im Forum Videoschnitt, Videotechnik & -produktionAntworten: 2Letzter Beitrag: 30.05.05, 22:45





Zitieren
Login




