[jboss-user] [JBoss Seam] - Re: Conversation versus Session Context

jrosskopf do-not-reply at jboss.com
Sat Feb 17 06:35:09 EST 2007


Hello,

sorry bothering you again.
I don´t fully understand this pattern. 

What I did so far is creating a ComponentBindings-POJO


  | @Name("componentBindings")
  | @Scope(ScopeType.EVENT)
  | public class ComponentBindings {
  | 	@Logger
  | 	Log log;
  | 	
  | 	HtmlPanelGrid selectedItemPreview;
  | 	HtmlPanelGrid selectedItemEditor;
  | 	
  | 	@Create
  | 	public void init() {
  | 		log.debug(LogFormat.INSTANCE.format(LogFormat.L_INSTANCE, ComponentBindings.class.getSimpleName()));
  | 	}
  | 	
  | 	public HtmlPanelGrid getSelectedItemEditor() {
  | 		return selectedItemEditor;
  | 	}
  | 	public void setSelectedItemEditor(HtmlPanelGrid selectedItemEditor) {
  | 		this.selectedItemEditor = selectedItemEditor;
  | 	}
  | 	
  | 	public HtmlPanelGrid getSelectedItemPreview() {
  | 		return selectedItemPreview;
  | 	}
  | 	public void setSelectedItemPreview(HtmlPanelGrid selectedItemPreview) {
  | 		this.selectedItemPreview = selectedItemPreview;
  | 	}
  | }
  | 

My backing bean looks now like this:


  | @Stateful
  | @Name("selectItemFacade")
  | @Scope(ScopeType.CONVERSATION)
  | public class SelectItemFacadeBean implements SelectItemFacade {
  | 	
  | 	@Logger
  | 	Log log;
  | 	
  | 	// Bijection
  | 	@Out
  | 	ItemDescription selectedItemType;
  | 	@Out(required=false)
  | 	Item item;
  | 	
  | 	// Instance
  | 	@In(create=true)
  | 	ComponentBindings componentBindings;
  | 	
  | 	@Create @Begin()
  | 	public void init() {
  | 		this.componentBindings.setSelectedItemPreview((HtmlPanelGrid)FacesContext.getCurrentInstance().getApplication().createComponent(HtmlPanelGrid.COMPONENT_TYPE));
  | 		this.selectedItemType = ItemRegistry.INSTANCE.getDefaultItemDescription();
  | 		updateSelectedItemComponents();
  | 	}
  | 	
  | 	private void updateSelectedItemComponents() {
  | 		if (this.selectedItemType != null && this.componentBindings.getSelectedItemPreview() != null) {
  | 			selectedItemType.getPreviewComponent(FacesContext.getCurrentInstance(), this.componentBindings.getSelectedItemPreview(), this.item);
  | 		}
  | 	}
  | 	
  | 	public Item getItem() {
  | 		return item;
  | 	}
  | 
  | 	public void setItem(Item item) {
  | 		this.item = item;
  | 	}
  | 
  | 	public SelectItem[] getAvailableItemTypes() {
  | 		return ItemRegistry.INSTANCE.getAvailableTypesAsSelectItem();
  | 	}
  | 	
  | 	public ItemDescription getSelectedItemType() {
  | 		return selectedItemType;
  | 	}
  | 
  | 	public void setSelectedItemType(ItemDescription selectedItemType) {
  | 		this.selectedItemType = selectedItemType;
  | 	}
  | 	
  | 	public ComponentBindings getComponentBindings() {
  | 		return componentBindings;
  | 	}
  | 
  | 	public void setComponentBindings(ComponentBindings bindings) {
  | 		this.componentBindings = bindings;
  | 	}
  | 
  | 	// Actions
  | 	@Begin(join=true)
  | 	public void handleItemTypeChange(ValueChangeEvent evt) {
  | 		ItemDescription desc = ItemRegistry.INSTANCE.getDescription((String)evt.getNewValue());
  | 		if (desc != null) {
  | 			this.selectedItemType = desc;
  | 			updateSelectedItemComponents();
  | 			log.debug("Item type changed to " + this.selectedItemType.getLabel());
  | 		}
  | 	}
  | 	
  | 	@Begin(join=true)
  | 	public String edit() {
  | 		log.debug("Action: edit called;");
  | 		
  | 		if (this.selectedItemType != null && this.item == null) {
  | 			log.debug("Creating " + selectedItemType.getLabel() +  " and getting edit Component;");
  | 			this.item = selectedItemType.createItemInstance();
  | 		}
  | 		
  | 		return NavCodes.ACTION_EDIT;
  | 	}
  | 	
  | 	@Destroy @Remove
  | 	public void destroy() { }
  | 	
  | }
  | 

My Page looks now like this:


  | <ui:define name="body">
  | 
  | 	<h:messages globalOnly="true" styleClass="message" />
  | 	<h:form id="panel" >
  | 		<h:panelGrid columns="1">
  | 
  | 			<h:panelGroup>
  | 				<h:selectOneMenu valueChangeListener="#{selectItemFacade.handleItemTypeChange}" 	onchange="submit()">
  | 					<f:selectItems value="#{selectItemFacade.availableItemTypes}" />
  | 					</h:selectOneMenu>
  | 			</h:panelGroup>
  | 
  | 			<h:panelGroup>
  | 				<h:panelGrid binding="#{selectItemFacade.componentBindings.selectedItemPreview}" />
  | 			</h:panelGroup>
  | 
  | 			<h:panelGroup>
  | 				<h:commandButton id="edit_button" action="#{selectItemFacade.edit}" />
  | 			</h:panelGroup>
  | 
  | 		</h:panelGrid>
  | 	</h:form>
  | 	
  | </ui:define> 
  | 

But after pushing the edit-button I still get the following exception:

  | javax.faces.el.PropertyNotFoundException: /item/select.xhtml @23,89 binding="#{selectItemFacade.componentBindings.selectedItemPreview}": Target Unreachable, identifier 'selectItemFacade' resolved to null
  | 

I got redirected to the seam debug page. The conversation context contains then:

  | -   Conversation Context (1)
  | org.jboss.seam.core.conversation
  | org.jboss.seam.core.facesMessages
  | org.jboss.seam.core.persistenceContexts
  | org.jboss.seam.core.redirect
  | org.jboss.seam.debug.lastException
  | selectItemFacade
  | selectedItemType
  | 

Can anybody help?
Thank you.
---
Joachim

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4018141#4018141

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4018141




More information about the jboss-user mailing list