I am currently using the
java studio enterprise 8 plattform, jdk 1.5.0
application server 8.1 UR2 and the
jsf 1.1 reference implementation.
The problem is that it gives 3 errors which are the following:
cannot import javax.faces.tree because it seems that the package is not existed in the library.
The other error is that it cannot find the symbol for the method
String actionCommand = event.getActionCommand();
The final error is that it cannot find the symbol for the method
getValueBinding(valueRef);
My packages javax.faces.event.ActionEvent and javax.faces.application.Application seem to work fine.
import java.util.Iterator;
import javax.faces.FactoryFinder;
import javax.faces.application.Application;
import javax.faces.application.ApplicationFactory;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;
import javax.faces.event.PhaseId;
import javax.faces.component.UICommand;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.tree.Tree;
import javax.servlet.ServletContext;
public class AppActionListener implements ActionListener {
public PhaseId getPhaseId() {
return PhaseId.INVOKE_APPLICATION;
}
public void processAction(ActionEvent event) {
String actionCommand = event.getActionCommand();
if ("buy".equals(actionCommand)) {
FacesContext facesContext = FacesContext.getCurrentInstance();
String productId = (String) facesContext.getExternalContext().
getRequestParameterMap().get("productId");
ShoppingCartBean cart =
(ShoppingCartBean) getValueBinding("ShoppingCartBean").
getValue(facesContext);
ProductBean product = getDatabaseUtil(). getProductDetails(productId);
ShoppingItemBean shoppingItem = new
ShoppingItemBean(product.getId(), product.getName(), product.getPrice(), 1);
cart.addShoppingItem(shoppingItem);
}
else if ("order".equals(actionCommand)) {
// insert a record into the database
FacesContext facesContext = FacesContext.getCurrentInstance();
OrderBean order = (OrderBean)
getValueBinding("OrderBean").getValue(facesContext);
ShoppingCartBean cart = (ShoppingCartBean)
getValueBinding("ShoppingCartBean").getValue(facesContext);
getDatabaseUtil().insertOrder(order, cart);
// empty shopping cart
cart.removeShoppingItems();
}
}
private ValueBinding getValueBinding(String valueRef) {
ApplicationFactory factory =
(ApplicationFactory)FactoryFinder.
getFactory(FactoryFinder.APPLICATION_FACTORY);
Application application = factory.getApplication();
return application.getValueBinding(valueRef);
}
private DatabaseUtil getDatabaseUtil() { FacesContext
facesContext = FacesContext.getCurrentInstance();
ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();
return (DatabaseUtil)
servletContext.getAttribute("DATABASE_UTIL");
}
}
If anyone knows anything about what it might be responsible for these errors please let me know.
Thanks