Hello, so I'm trying to post a list of options from a DB I have. I'm getting a massive error in glassfish when I attempt to load the DB. When I remove the selectItems code in the xHTML code, it will run, but the box does not contain any options nor does it have a label. I'm pretty sure I've done everything right except the xhtml part.
Here's what I have on the xHTML page:
HTML Code:
<h:outputLabel for="stateOption" value="#{StateTaxRequest.state}"/>
<h:selectOneMenu id="stateOption"
required="true"
value="#{StateTaxRequest.stateOption}">
<f:selectItems value="#{StateTaxRequest.states}" />
</h:selectOneMenu>
Here's my database code:
@Singleton
@Startup
public class StateTaxConfigBean {
@EJB
private StateTaxRequestBean StateTaxRequest;
@PostConstruct
public void createData() {
StateTaxRequest.createState("1", "Alabama", .02);
}
}
my StateTax code (which I also need help with the query):
/*
@Entity
@Table(name = "STATES")
@NamedQuery(
name = "findState",
query = "SELECT b FROM Book b ORDER BY b.bookId")
public class StateTax implements Serializable {
@Id
private String stateID;
private String state;
private double taxRate;
//supposed to lok like book.java
public StateTax() {
}
public StateTax(String id, String st, double tax) {
this.stateID = id;
this.state = st;
this.taxRate = tax;
}
public String getStateID() {
return stateID;
}
public void setStateID(String stateID) {
this.stateID = stateID;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
}
Here's my request bean as well:
@Stateful
public class StateTaxRequestBean {
@PersistenceContext
private EntityManager em;
private static final Logger logger =
Logger.getLogger("dukesbookstore.ejb.StateTaxRequestBean");
public StateTaxRequestBean() throws Exception {
}
public void createState(String stateID, String stateName, Double taxAmt) {
try {
StateTax state = new StateTax(stateID, stateName, taxAmt);
logger.log(Level.INFO, "Created state {0}", stateID);
em.persist(state);
logger.log(Level.INFO, "Persisted state {0}", stateID);
} catch (Exception ex) {
throw new EJBException(ex.getMessage());
}
}
public List<StateTax> getStates() throws StatesNotFoundException {
try {
return (List<StateTax>) em.createNamedQuery("findState").getResultList();
} catch (Exception ex) {
throw new StatesNotFoundException(
"Could not get states: " + ex.getMessage());
}
}
public StateTax getState(String state) throws StateNotFoundException {
StateTax requestedState = em.find(StateTax.class, state);
if (requestedState == null) {
throw new StateNotFoundException("Couldn't find State: " + state);
}
return requestedState;
}
}