Actions not hitting methods (always)
ryanwaggoner Mar 11, 2009 6:03 PMHi guys,
I have just been getting into Seam and am pretty new. I am sorry in advance if my problem just comes from me not looking hard enough, but I think I have looked pretty hard, at least for what I know.
So, I have my Setup province page...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" 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:a="http://richfaces.org/a4j"> <ui:composition template="/layout/template.xhtml"> <ui:define name="title"> Province Setup </ui:define> <ui:define name="content"> <h:form id="form"> <h:outputText styleClass="bfont" value="Province Setup" /> <!-- Country Drop down box --> <h:panelGrid columns="2"> <h:outputText value="Country" /> <h:selectOneMenu value="#{provinceCountry}"> <!-- Only country is Canada for now --> <f:selectItem itemValue="CAN" itemLabel="Select A Country" noSelectionLabel="Select Country" /> <f:selectItem itemValue="CAN" itemLabel="Canada" /> <a:support event="onchange" action="#{stateBean.getStatesByCountry}" reRender="showProvinces" /> </h:selectOneMenu> </h:panelGrid> <!-- Provinces Drop down box --> <s:div id="showProvinces"> <h:panelGrid columns="2"> <h:outputText value="Province" /> <h:selectOneMenu onkeydown="enterTab();" value="#{state}"> <s:selectItems value="#{provinceList}" var="provinceString" label="#{provinceString.siStateCode}" noSelectionLabel="Select Province" /> <a:support event="onchange" eventsQue="foo" reRender="provinceTaxRates" requestDelay="1000" /> <s:convertEntity /> </h:selectOneMenu> </h:panelGrid> </s:div> <!-- Tax Rate Box --> <s:span id="provinceTaxRates"> <rich:dataTable value="#{state.taxItems}" var="stateTax" rowClasses="seamDisplayTableRowOne,seamDisplayTableRowTwo" rules="cols"> <f:facet name="header">Taxes</f:facet> <h:column> <h:outputText value="Name: " /> <h:inputText value="#{stateTax.siName}" /> </h:column> <h:column> <h:outputText value="Tax Rate: " /> <h:inputText value="#{stateTax.siTaxRate}" /> </h:column> <h:column> <h:commandButton value="Remove Tax" action="#{stateBean.deleteTax}" /> </h:column> </rich:dataTable> <!-- New Tax Table --> <s:div id="newTaxInput"> <h:panelGrid columns="1"> <rich:panel> <f:facet name="header"> <h:outputText value="New Tax for #{state.siStateCode}" /> </f:facet> <h:column> <h:outputText value="Name: " /> <h:inputText value="#{stateTax.siName}" /> </h:column> <h:column> <h:outputText value="Tax Rate: " /> <h:inputText value="#{stateTax.siTaxRate}" /> </h:column> <h:column> <a:commandButton value="Save Tax" eventsQue="foo" action="#{stateBean.addTax}" reRender="provinceTaxRates" /> </h:column> </rich:panel> </h:panelGrid> </s:div> </s:span> </h:form> </ui:define> </ui:composition> </jsp:root>
And my stateBean class looks like...
import java.util.List; import javax.ejb.Remove; import javax.ejb.Stateful; import org.hibernate.Hibernate; import org.jboss.seam.annotations.Begin; import org.jboss.seam.annotations.Conversational; import org.jboss.seam.annotations.Destroy; import org.jboss.seam.annotations.Factory; import org.jboss.seam.annotations.FlushModeType; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Out; import org.jboss.seam.annotations.datamodel.DataModel; import org.jboss.seam.annotations.datamodel.DataModelSelection; import com.savageservices.dobi.BaseBean; import com.savageservices.dobi.shared.entity.SiDepartment; import com.savageservices.dobi.shared.entity.SiState; import com.savageservices.dobi.shared.session.State; import com.savageservices.dobi.timeAndBilling.entity.SiStateTax; @Stateful @Name("stateBean") @Conversational @SuppressWarnings("all") public class StateBean extends BaseBean implements State { @DataModelSelection("stateList") @Out(required = false) @In(required = false) private SiState state; @DataModel private List<SiState> stateList; @DataModel private List<SiState> provinceList; @In(required = false) private SiStateTax stateTax; @In(required = false) SiDepartment department; @In(required = false) String provinceCountry; @Destroy @Remove public void destroy() { state = null; stateList = null; department = null; } /** * Loads all states in the United States and orders them by state code. */ @Factory("stateList") @Begin(join = true, flushMode = FlushModeType.MANUAL) public void setup() { String sql = "FROM SiState where siCountry = 'USA' order by siStateCode"; stateList = entityManager.createQuery(sql).getResultList(); for (SiState state : stateList) { Hibernate.initialize(state.getTaxItems()); } state = user.getCurrentDepartment().getState(); } /** * Method to return a list of provinces names based on the country passed in */ @Factory("provinceList") @Begin(flushMode = FlushModeType.MANUAL, join = true) public void getStatesByCountry() { if(provinceCountry == null) provinceCountry = "CAN"; // query to get all states that have a country that matches the // province.getCountry property String hql = "FROM SiState " + "WHERE siCountry = '" + provinceCountry + "'"; // Run the query and put the result in an SiState list to cast into // provinces later provinceList = entityManager.createQuery(hql).getResultList(); } @Begin(flushMode = FlushModeType.MANUAL, join = true) public void selectState() { } /** * Method to delete a Tax from this state */ @Begin(flushMode = FlushModeType.MANUAL, join = true) public void deleteTax() { // Remove the taxItem from the state state.getTaxItems().remove(stateTax); // Remove the state Tax from the DB entityManager.remove(stateTax); entityManager.flush(); } /** * Method to add a Tax to this state */ @Begin(flushMode = FlushModeType.MANUAL, join = true) public void addTax() { // Add the new tax to the state's list of taxes state.getTaxItems().add(stateTax); // Set the stateTax state, to the current state stateTax.setState(state); // Save the stateTax entityManager.merge(stateTax); entityManager.flush(); } }
The problem is, when I load information in the span: provinceTaxRates, and the RemoveTax button that is loaded with it is clicked, nothing happens (aside from the page being loaded.)
After I hit the Add Tax button and stateBean.addTax() is called, my remove tax button begins to work.
Is the reason obvious?