tags:

views:

30

answers:

1

Hi there,

I'm trying to build some select boxes with dependencies on other select boxes. I'm fairly new to Seam - just to add this. Here is my JSF - for test purposes I'm trying to display a dataTable

<f:facet name="header">Profil</f:facet>

<a:form ajaxSubmit="true" reRender="testTable">
    <s:decorate id="techTypeField" template="layout/edit.xhtml">
        <ui:define name="label">Choose tech</ui:define>
           <h:selectOneRadio id="techType" value="#{technologyType}" onchange="submit()">
                <s:selectItems value="#{technologyTypes}" var="elem" label="#{elem.name}" id="typeId"/>
                <s:convertEntity/>
           </h:selectOneRadio>
    </s:decorate>
</a:form>

<div style="clear:both"/>

<h:dataTable var="productLine" id="testTable" value="#{productLines}" rendered="#{productLines.rowCount > 0}">
    <h:column >
        <f:facet name="header">pl</f:facet>
        #{productLine.id}
    </h:column>
</h:dataTable>

My backing bean

package de.ac.dmg.productfinder.workflow;

import java.util.List;

import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.datamodel.DataModel;
import org.jboss.seam.annotations.datamodel.DataModelSelection;
import org.jboss.seam.international.StatusMessages;
import org.jboss.seam.log.Log;

import de.ac.entity.Machine;
import de.ac.entity.ProductLine;
import de.ac.entity.TechnologyType;

@Stateful
@Name("Profil")

public class ProfilBean implements IProfil {
@PersistenceContext
private EntityManager entityManager;

@Logger
private Log log;

@DataModel(value = "technologyTypes")
private List<TechnologyType> technologyTypes;

@DataModelSelection(value = "technologyTypes")
private TechnologyType technologyType;

@DataModel(value = "productLines")
private List<ProductLine> productLines;

@DataModel(value = "machines")
List<Machine> machines;

@In
StatusMessages statusMessages;

// add additional action methods

@Factory("technologyTypes")
public void loadTechTypes() {
    technologyTypes = entityManager.createQuery("Select t from TechnologyType t").getResultList();
}

@Factory("productLines")
public void loadProductLinies() {
    System.out.println(technologyType);
    productLines = entityManager.createQuery("select p from ProductLine p where p.technologyType = :type ")
            .setParameter("type", technologyType).getResultList();
}

public void next() {
    // implement your business logic here
    log.info("Profil.next() action called with: #{Profil.value}");
    statusMessages.add("next #{Profil.value}");
}

@Remove
public void destroy() {
}

}

I can set the tech type on time - after one click it isn't refreshed sadly. What I'm doing wrong here?

+1  A: 

When selecting a 'technology type', you need an action which reloades the product types based on the selected techtype. Something like action=#{Profil.loadProductLines()}

Fortega