[JBoss Seam] - Re: What is the common pattern for selecting objects?
by grettke_spdr
Here is what I came up with. I am posting it in order to elicit comments on my approach (code review) and also in case this is right and anyone else needs to use selectItems with a custom converter when you want to populate it using objects. In the interest of brevity this is not a compilable
In other words, does this look like the typical approahc for solving a problem like this?
This is the object Contact from which folks can choose. This is a once off selection (for now atleast), so these are not persisted. Once one is chosen, it will become an embedded entity.
| protected String name = "";
| protected String title = "";
| protected String role = "";
| protected String phoneNumber = "";
| protected String emailAddress = "";
|
There are two components: a user facing (form-like) component that stores the users selections (this will become an entity) and then the action.
| priority1DataUf: the "form" data, users selection goes here
| priority1RequestAction: the action itself, it also exposes a property that is the list of contacts from which the user may choose "contacts"
|
On the page itself:
| <h:selectOneRadio id="contactSelector"
| value="#{priority1DataUf.contact}"
| layout="pageDirection"
| required="true">
| <s:selectItems value="#{priority1RequestAction.contacts}"
| var="contact"
| label="#{contact.title} #{contact.name}: #{contact.phoneNumber}"/>
| <s:convertEntity/>
| <rms:contactListConverter/>
| </h:selectOneRadio>
|
Finally, the converter. The converter assumes that it would only be used for Contacts. Contact checks for equality using NAME and TITLE. Those are the values used by the equals method on the class. The lifecycle is that the page gets loaded, and the converters gettAsString is called taking in a Contact and returning the value to populate the html control. That value roughly the key for that object in priority1RequestAction.contacts (althought it is not a map now, perhaps it ought to be). The user makes a selection on the page and submits it, and then the converter takes that key. It gets the value binding for the selectItems and tries to find an object with that key. If it finds it, that value is returned.
| public Object getAsObject(FacesContext context,
| UIComponent comp,
| String value)
| throws ConverterException {
|
| Object result = null;
| try {
| if (Contact.validItem(value)) {
| // comp is "this" component, the one in which the tag lives.
| // This converter may live inside, for example, a
| // javax.faces.component.html.HtmlSelectOneRadio
|
| // We need to iterate through its children to get the list of Contacts
| // from the <s:selectItems>
| List children = comp.getChildren();
|
| for (Object child : children) {
| // Its children include UIComponent(s)
| if (child instanceof UIComponent) {
| UIComponent c = (UIComponent) child;
| // The value binding for a component is the data to which it is
| // bound. An example here is:
| // /priority1.xhtml @118,94 value="#{priority1RequestAction.contacts}":
| // ValueExpression[#{priority1RequestAction.contacts}]
| ValueBinding b = c.getValueBinding("value");
| // The class of the value binding is an interface, java.util.List, since we
| // provide java.util.List<contact>.
| // b.getType(context) -> interface java.util.List
| // At this point we assume it is a list of Contacts
| List<Contact> contacts =
| (List<Contact>) b.getValue(context);
| for (int i = 0; i < contacts.size(); i++) {
| Contact contact = contacts.get(i);
| if(Contact.getItem(contact).equals(value))
| {
| result = contact;
| break;
| }
| }
| }
| }
| }
| } catch (Exception e) {
| throw new ConverterException(
| "ContactListConverter error: " + e.toString());
| }
| if (result == null) {
| throw new ConverterException(
| "A valid Contact itemString is required");
| }
| return result;
| }
|
| public String getAsString
| (FacesContext
| context,
| UIComponent
| component,
| Object
| object)
| throws ConverterException {
| String result;
| if (object == null) {
| result = null;
| } else {
| result = Contact.getItem((Contact) object);
| }
| return result;
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4052694#4052694
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4052694
18Â years, 10Â months
[JBoss Seam] - Re: Question about explicit conversation id
by bsmithjj
I @In(jected) the conversation component into my bean and then added some code to dump the conversation id in the method invokation. It looks like that's working correctly, it's the SeamTest.FacesRequest that appears to be losing track of the conversation id.
New AccessRequestManager2.startRequest() Code:
| @Begin(id="DraftAccessRequestID:#{draftAccessRequestMaster.id}",join=true)
| public void startRequest() {
| log.info("draftAccessRequestMaster.id = "+draftAccessRequestMaster.getId());
| log.info(conversation);
| log.info("conversation.id = "+conversation.getId());
| log.info("conversation.parentId = "+conversation.getParentId());
| }
|
with the following output during execution:
| 14:12:28,093 INFO com.evergreen.accesscontrol.impl.AccessRequestManager2Bean.(startRequest:59) - draftAccessRequestMaster.id = 6
| 14:12:28,093 INFO com.evergreen.accesscontrol.impl.AccessRequestManager2Bean.(startRequest:60) - org.jboss.seam.core.Conversation@1fcb845
| 14:12:28,093 INFO com.evergreen.accesscontrol.impl.AccessRequestManager2Bean.(startRequest:61) - conversation.id = DraftAccessRequestID:6
| 14:12:28,093 INFO com.evergreen.accesscontrol.impl.AccessRequestManager2Bean.(startRequest:62) - conversation.parentId = null
| 14:12:28,124 INFO com.evergreen.accesscontrol.AccessRequestManager2Test.(info:94) - conversationId = 1
|
So I see that the desired conversation id, DraftAccessRequestID:6, is being created the way I would like, however, the SeamTest.FacesRequest is not reflecting this.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4052692#4052692
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4052692
18Â years, 10Â months
[JBoss Seam] - Re: Problem with @Transactional
by gustajz
Yes, I using this.
The transaction works, but not correctly.
In this code.
| try {
| log.debug("will be delete...");
| projetoManager.remove(selected.getId()); <---- generates a exception
| log.debug("deleted??"); <--- after execption... this continue...
| FacesMessages.instance().add("{0} has been removed.", new Object[] { selected.getNome() });
| } catch (Throwable e) {
| addMessage("Faild to remove"); <--- not printed
| }
|
this is my faces-config
| <faces-config>
| <application>
| <view-handler>
| org.jboss.seam.ui.facelet.SeamFaceletViewHandler
| </view-handler>
| <el-resolver>org.jboss.seam.jsf.SeamELResolver</el-resolver>
| <locale-config>
| <default-locale>pt_BR</default-locale>
| <supported-locale>pt_BR</supported-locale>
| <supported-locale>en_US</supported-locale>
| </locale-config>
| <message-bundle>MessageBundle</message-bundle>
| </application>
|
| <lifecycle>
| <phase-listener>
| org.jboss.seam.jsf.TransactionalSeamPhaseListener
| </phase-listener>
| </lifecycle>
| </faces-config>
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4052688#4052688
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4052688
18Â years, 10Â months
[JBoss Seam] - Re: Timer not starting from method with @Create annotation.
by maniappan
Tried it, didn't get any exception, got more line in addition to what I posted before..
| 2007-06-08 22:42:49,066 DEBUG [org.jboss.ejb.txtimer.TimerImpl] Timer was not registered with Tx, resetting state: [id=4,target=[target=jboss.j2ee:service=EJB3,ear=yoscarebase.ear,jar=jboss-seam.jar,name=Dispatcher],remaining=-11966,periode=0,in_timeout]
| 2007-06-08 22:42:49,066 DEBUG [org.jboss.ejb.txtimer.TimerImpl] setTimerState: expired
| 2007-06-08 22:42:49,067 DEBUG [org.jboss.ejb.txtimer.TimerImpl] killTimer: [id=4,target=[target=jboss.j2ee:service=EJB3,ear=yoscarebase.ear,jar=jboss-seam.jar,name=Dispatcher],remaining=-11967,periode=0,expired]
| 2007-06-08 22:42:49,068 DEBUG [org.jboss.ejb.txtimer.GeneralPurposeDatabasePersistencePlugin] Unable to remove timer for: 4
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4052681#4052681
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4052681
18Â years, 10Â months