Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SelectOneMenu ajax and s:selectItems

843844Aug 5 2008
Hi everyone,

I'm having a problem with selectOneMenu and it's ajax support. Since i wasn't able to make it work on the page I'm working on, I have created easy testing page, backing bean and entity bean for testing purpose. But even thought I wasn't able to success. I attend to have combobox with objects of the entity bean and onselect rerender another component. I'm really desperate, cause I was reading through many forums including this. So I would really appreciate if you'll be able to help. Thanks a lot in advance.
This is DummyEntity
@Entity
@NamedQueries( { @NamedQuery(name = "DummyEntity.all", query = "SELECT de FROM DummyEntity de ORDER BY de.id") })
public class DummyEntity
{

	public static List<DummyEntity> all(EntityManager em)
	{
		Query query = em.createNamedQuery("DummyEntity.all");
		return Utils.getResultList(query);

	}

	Long m_id;

	String m_name;

	String m_val;

	@Id
	public Long getId()
	{
		return m_id;
	}

	public String getName()
	{
		return m_name;
	}

	public String getVal()
	{
		return m_val;
	}

	public void setId(Long id)
	{
		m_id = id;
	}

	public void setName(String name)
	{
		m_name = name;
	}

	public void setVal(String value)
	{
		m_val = value;
	}

}
This is Testbean.java
import java.util.List;

import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
import javax.faces.event.ValueChangeEvent;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.Destroy;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

import com.cloudsmith.cssite.entity.DummyEntity;
import com.cloudsmith.cssite.entity.Principal;
import com.cloudsmith.cssite.entity.UserProfile;

@Name("Testing")
@Stateful
@Scope(ScopeType.SESSION)
public class TestBean implements Test
{
	private List<DummyEntity> m_dummy;
	private DummyEntity m_selectedDummy;
	@PersistenceContext(type = PersistenceContextType.EXTENDED)
	private EntityManager m_em;

	public TestBean()
	{

	}

	@Create
	public void Create()
	{
	}

	@Destroy
	public void Destroy()
	{
	}

	public List<DummyEntity> getDummy()
	{
		m_dummy = DummyEntity.all(m_em);
		// m_selectedDummy = m_dummy.get(3);
		return m_dummy;
	}

	public DummyEntity getSelectedDummy()
	{
		return m_selectedDummy;
	}

	@Remove
	public void Remove()
	{
	}

	public void selectedDummyListener(ValueChangeEvent event)
	{
		PhaseId phaseId = event.getPhaseId();
		// DummyEntity oldValue = (DummyEntity)event.getOldValue();
		DummyEntity newValue = (DummyEntity)event.getNewValue();
		if(phaseId.equals(PhaseId.ANY_PHASE))
		{
			event.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
			event.queue();
		}
		else if(phaseId.equals(PhaseId.UPDATE_MODEL_VALUES))
		{
			if(newValue != null)
			{
				m_selectedDummy = newValue;
			}
		}

		FacesContext context = FacesContext.getCurrentInstance();
		context.renderResponse();

	}

	public void setDummy(List<DummyEntity> dummy)
	{
		m_dummy = dummy;
	}

	public void setSelectedDummy(DummyEntity selectedDummy)
	{
		m_selectedDummy = selectedDummy;
	}
}
This is my testing.xhtml:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
	template="../layout/template.xhtml">

	<ui:define name="body">
		<f:view>
          <h:form>
            <h:selectOneMenu value="#{Testing.selectedDummy.name}" 
            					valueChangeListener="#{Testing.selectedDummyListener()}"
            					onchange="submit();">
            					
            	<s:selectItems value="#{Testing.dummy}" var="dum" label="#{dum.name}"/>
            	<s:convertEntity/>
            	<a4j:support event="onchange" reRender="rep"/>
            </h:selectOneMenu>
      	  </h:form>
      	  <h:outputText value="#{Testing.selectedDummy.val}" id="rep" />
        </f:view>
	</ui:define>
</ui:composition>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 2 2008
Added on Aug 5 2008
0 comments
230 views