This issue arrived when I tried to use a LinkedHashMap to save entries from a database. I don't know to what extent the xhtml code is working, but superficially looks well.
The issue is in this part of the xhtml:
<tbody>
<tr>
<td>Movie:</td>
<!--td>
<h:selectOneMenu id="foundmovieid" value="#{webRental.idmovie}">
<f:selectItems id="movieid" value="#{webMovie.get_all_movies()}"></f:selectItems>
</h:selectOneMenu>
</td-->
<td>
<h:selectOneMenu value="#{webRental.idmovie}">
<f:selectItems value="#{webMovie.availableMovies.entrySet()}" var="entry"
itemValue="#{entry.key}" itemLabel="#{entry.value}" />
</h:selectOneMenu>
</td>
</tr>
</tbody>
</table>
<h:commandButton value="Submit" action="#{webRental.save()}"></h:commandButton>
Here is the WebRental.java:
public class WebRental {
#EJB
private RentalsFacade rf;
private String iduser;
private String idmovie;
//getters and setters
public List<Rentals> get_all_rents() {
return rf.findAll();
}
public void save() {
try {
rf.Save(iduser, idmovie);
} catch (Exception e) {
}
}
}
and the WebMovie.java, whose MoviesFacade has an EntityManager and a way to persist new pbject Movies (id, title, director's name and length):
#Named
#RequestScoped
public class WebMovie {
#EJB
private MoviesFacade mf;
private String id;
private String title;
private String director;
private int length;
private Map<String, String> availableMovies;
//geters and setters
public List<Movies> get_all_movies() {
availableMovies = new LinkedHashMap<>();
List<Movies> found = mf.findAll();
found.forEach((m) -> {
String first = m.getId();
String second = m.getTitle() + ", " + m.getDirector() + ", " + m.getLength() + " minutes.";
availableMovies.put(first,second);
});
return mf.findAll();
}
public void save() {
try {
mf.Save(id, title, director, length);
} catch (Exception e) {
}
}
}
In the xhtml, theres a muted section, which is just what I have to do (get id's and submit them) but in a way that you only see the id's. The unmuted section is the part im having trouble with, since it says that the value is invalid.
To solve this do I have to use "converters"? If so, how do I implement it? If not, what is my error?
Also, in the muted section there is a call to "get_all_movies()", but since it's muted, it shouldnt be called. How do I call that function outside of that muted section so I can delete the whole section after I get the SelectOneMenu with the map working?
Turns out using Maps is very strange...
How I solved this was by removing most of the SelectItems so that it just is:
<f:selectItems value="#{webMovie.availableMovies}" />
And then changing the way I insert everything to the Map like so:
#PostConstruct
public void init() {
availableMovies = new HashMap<>();
mf.findAll().forEach((m) -> {
availableMovies.put((String) m.getTitle() + ", " + m.getDirector() + ", " + m.getLength() + " minutes.",(String) m.getId());
});
//Turns out that, for the selectItems to read properly the map, you have to insert the text you want to be displayed as the key, and then the value as value. I was doing it backwards.
}
That way I dont have to depend on the !--'d section that calls get_all_movies() and I could delete it!
Related
I had a headache with this. I want to choose a book from the 1st list and with that book create a second list to be able to show the details of the book (title, number of pages)
Here is the code:
public class Book {
private int numBook;
private String nameBook;
private String author;
public Book(int numBook, String nameBook, String author) {
super();
this.numBook = numBook;
this.nameBook = nameBook;
this.author = author;
}
public int getNumBook() {
return numBook;
}
public void setNumBook(int numBook) {
this.numBook = numBook;
}
public String getNameBook() {
return nameBook;
}
public void setNameBook(String nameBook) {
this.nameBook = nameBook;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
Class BookData: Load the info in array
public class BookData {
private List<Book> books = new ArrayList<Book>();
public BookData() {
loadBooks();
}
public List<Book> getBooks() {
return books;
}
public void setBooks(List<Book> books) {
this.books = books;
}
public void loadBooks() {
Book b;
for(int i = 0; i<4;i++){
b = new Book(i+1, "Libro "+i+1, "Author "+i+1);
books.add(b);
}
}
}
Class BookViewModel: ViewModel of Listbox
public class BookViewModel {
private static Book selectedBook;
private List<Book> booksData = new ArrayList<Book>(new BookData().getBooks()); // Armo los libros
public List<Book> getBooksData() {
return booksData;
}
public void setBooksData(List<Book> booksData) {
this.booksData = booksData;
}
//Getters and Setter the SelectedCar
#NotifyChange("selectedBook")
public Book getSelectedBook() {
if(selectedBook!=null) {
//setSelectedBook(selectedBook);
new DetailData(selectedBook);
//new ArrayList<>(new DetailData().getDetailsFilterByBook());
//Then here pass the Book Selected
}
return selectedBook;
}
public void setSelectedBook(Book selectedBook) {
this.selectedBook = selectedBook;
}
}
Class Detail: Detail Model of the choose Book
public class Detail {
private int idBook;
private String title;
private int numPages;
public Detail(int idBook, String title, int numPages) {
this.idBook = idBook;
this.title = title;
this.numPages = numPages;
}
public int getIdBook() {
return idBook;
}
public void setIdBook(int idBook) {
this.idBook = idBook;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getNumPages() {
return numPages;
}
public void setNumPages(int numPages) {
this.numPages = numPages;
}
#Override
public String toString() {
return "Detail [idBook=" + idBook + ", title=" + title + ", numPages=" + numPages + "]";
}
}
Class DetailData: Load the data in array
//Clase que se ecarga de manejar la data
public class DetailData {
private List<Detail> details = loadAllDetails();
private List<Detail> detailsFilterByBook;
private static Book bookSelected;
/*public DetailData(){
//Previously all the data is loaded
System.out.println(bookSelected);
detailsFilterByBook = new ArrayList<>();
filterDetailsByBook();
}*/
public void setBookSelected(Book bookSelected){
this.bookSelected = bookSelected;
}
public DetailData(){
this(bookSelected);
}
public DetailData(Book b){
bookSelected = b;
System.out.println(bookSelected);
detailsFilterByBook = new ArrayList<>();
filterDetailsByBook();
}
public List<Detail> loadAllDetails(){
List tmp = new ArrayList<Detail>();
//Libro 1
Detail d1b1 = new Detail(1, "Preview", 15);
Detail d2b1 = new Detail(1, "Inicio", 10);
Detail d3b1 = new Detail(1, "Zk Bind", 50);
//Libro 2
Detail d1b2 = new Detail(2, "Introduccion", 15);
Detail d2b2 = new Detail(2, "JAVA", 100);
Detail d3b2 = new Detail(2, "CSS", 25);
//Libro 3
Detail d1b3 = new Detail(3, "HTML", 35);
Detail d2b3 = new Detail(3, "Javascript", 40);
Detail d3b3 = new Detail(3, "Ajax", 25);
//Libro 4
Detail d1b4 = new Detail(4, "Android", 100);
Detail d2b4 = new Detail(4, "IOS", 100);
tmp.add(d1b1);
tmp.add(d2b1);
tmp.add(d3b1);
tmp.add(d1b2);
tmp.add(d2b2);
tmp.add(d3b2);
tmp.add(d1b3);
tmp.add(d2b3);
tmp.add(d3b3);
tmp.add(d1b4);
tmp.add(d2b4);
return tmp;
}
private void filterDetailsByBook() {
for(Detail d:details){
if(d.getIdBook() == bookSelected.getNumBook())
detailsFilterByBook.add(d);
}
print();
}
public void print(){
System.out.println("Imprimiendo detalles del libro escogido");
for(Detail d: detailsFilterByBook){
System.out.println(d);
}
}
public List<Detail> getDetails() {
return details;
}
public void setDetails(List<Detail> details) {
this.details = details;
}
public List<Detail> getDetailsFilterByBook() {
return detailsFilterByBook;
}
public void setDetailsFilterByBook(List<Detail> detailsFilterByBook) {
this.detailsFilterByBook = detailsFilterByBook;
}
}
Class: DetailViewModel:ViewModel of the second ListBox
public class DetailViewModel {
private List<Detail> detailsData = new ArrayList<>();
#NotifyChange("detailsData")
public void refreshList(){
System.out.println("REFRESH");
detailsData = new ArrayList<>(new DetailData().getDetailsFilterByBook());
}
public List<Detail> getDetailsData() {
return detailsData;
}
#NotifyChange("detailsData")
public void setDetailsData(List<Detail> detailsData) {
this.detailsData = detailsData;
}
}
Here is the zul file
<window title="" border="none" height="100%" apply="org.zkoss.bind.BindComposer" viewmodel="#id('vm') #init('book.BookViewModel')">
<listbox model="#bind(vm.booksData)" selecteditem="#bind(vm.selectedBook)" emptymessage="No car found in the result">
<listhead>
<listheader label="Num Libro"/>
<listheader label="Libro"/>
<listheader label="Autor"/>
</listhead>
<template name="model" var="book">
<listitem>
<listcell label="#bind(book.numBook)"/>
<listcell label="#bind(book.nameBook)"/>
<listcell label="#bind(book.author)"/>
</listitem>
</template>
</listbox>
<separator height="100px"/>
<window title="" border="none" height="100%" apply="org.zkoss.bind.BindComposer"
viewModel="#id('vm') #init('detail.DetailViewModel')">
<listbox model="#bind(vm.detailsData)" emptyMessage="No existen datos que presentar">
<listhead>
<listheader label="Num Capitulos"/>
<listheader label="Titulo del Cap"/>
</listhead>
<template name="model" var="detail">
<listitem>
<listcell label="#bind(detail.idBook)"/>
<listcell label="#bind(detail.title)"/>
<listcell label="#bind(detail.numPages)"/>
</listitem>
</template>
</listbox>
</window>
</window>
I try in the second listbox (At begin have to be empty), show the details of the book everytime when a book in the 1st listbox is selected. I get the correct info. When I choose a book, I get the correct details of that book, but my second listbox does'nt show anything. I will apreciate all the help. PD: Sorry for the english
Oke, there are more points to say on this code then you imagine.
Never use static for a user/session variable.
In your VM you have the following code :
private static Book selectedBook;
Imagine that I select Book 1 and you select 2 seconds later Book 2.
Because it's static, I'm also having Book 2 selected, while mine view isn't aware of it.
This means the GUI and server side are out of sync => never a good thing.
If you could be able to sync the view with the selected item, this means that you select book 2 for me and I'll be searching the number of the Ghost Busters.
With ZK, always use ListModel interface to give collections to GUI.
While returning List<Book> works pretty good, you need to understand the consequences of this action.
A List or Grid expect an implementation of ListModel and if you don't give it, there will be one created every time you notify the list of a change.
While this is a nice to have feature it also removes the intelligence of a listmodel and the GUI rendering will be a lot more.
An example is always more clear :
We have a Collection of 9 items and we will append 1 to it.
Adding 1 Object to the List and notifying it implies that all the content rendered of the Listbox will be removed and then adding all the content again to the Listbox.
This means that we are removing and adding 9 lines who aren't changed.
Adding 1 Object to a ListModel, even without notifying the ListModel of a change will result in an action where there is only 1 item appended to the Listbox. This is the intelligence of a ListModel => adding and removing items will be persisted to the GUI without overhead.
So your code should be looking like this :
private Book selectedBook;
private final ListModelList<Book> booksData = new ListModelList<Book>(new BookData().getBooks()); // Armo los libros
Why not working to the interface and why final?
So I just told you about the interface ListModel and yet, I'm setting an implementation of ListModel as code, even while we learn to work against interfaces.
The simple reason is that ListModel doesn't have methods for appending and removing items while the implementation do have it.
So I make a decision to work against that object in stead of casting it when I need the methods.
Remember, the global getter for the booksData can look like this :
public ListModel<Book> getBooksData() {
return booksData;
}
So here we hide the implementation of ListModelList to the outside.
The reason for final is that you will forcing yourself or other people who are going through the code to use the clear() method in stead of making a new ListModelList.
It's just not needed to create a new instance of it.
Using 2 viewmodel's
Your making yourself difficult of using 2 VM's.
But while it's sometimes a good idea to do this I'll be helping you to get your problem solved.
Your first problem is one of a naming kind.
Viewmodel 1 => called vm in the zul.
Viewmodel 2 => called vm in the zul.
You see it coming? who will listen when I cry to vm?
let's call the viewmodel of the details detailVM
viewModel="#id('detailVM') #init('detail.DetailViewModel')"
The second problem is that your detail viewmodel doesn't have any clue of the first listbox.
What do I want to say is that your second viewmodel should be holding the correct info of the selected item of the first listbox.
Zul code should be looking like this :
<window title="" border="none" height="100%" apply="org.zkoss.bind.BindComposer" viewmodel="#id('vm') #init('book.BookViewModel')">
<div apply="org.zkoss.bind.BindComposer"
viewModel="#id('detailVM') #init('detail.DetailViewModel')">
<listbox model="#init(vm.booksData)" selecteditem="#bind(detailVM.selectedBook)" emptymessage="No book found in the result">
<listhead>
<listheader label="Num Libro"/>
<listheader label="Libro"/>
<listheader label="Autor"/>
</listhead>
<template name="model" var="book">
<listitem>
<listcell label="#load(book.numBook)"/>
<listcell label="#load(book.nameBook)"/>
<listcell label="#load(book.author)"/>
</listitem>
</template>
</listbox>
<separator height="100px"/>
<listbox model="#init(detailVM.detailsData)" emptyMessage="No existen datos que presentar">
<listhead>
<listheader label="Num Capitulos"/>
<listheader label="Titulo del Cap"/>
</listhead>
<template name="model" var="detail">
<listitem>
<listcell label="#load(detail.idBook)"/>
<listcell label="#load(detail.title)"/>
<listcell label="#load(detail.numPages)"/>
</listitem>
</template>
</listbox>
</div>
</window>
So I set you up with the correct zul, and now it's up to you to modify the viewmodels.
Remember that I set selectedBook in detailVM so now it's not needed in the first viewmodel.
I don't write everything for you, otherwise you wouldn't learn from it.
Some small things left to say.
You see I change the listbox model to #init and not #bind.
A model is always read only, so please NEVER NEVER NEVER use #bind.
#load is the highest annotation you could use, and this is only the case when you will create a new instance for the ListModel, witch is hardly needed.
Labels, are also not updatable in your GUI.
Again #bind is over the top, #load should be used in normal situations (when the value can change, so most commonly) or #init when the value will never change, but if you use #load I'll be happy already.
Hope this could set you to the right direction.
If you have any other question, just comment below.
Now I'm using play2.2.1, and I know Java, but I don't know Scala.
And if you learn PlayFramework even just a little bit, you will know Scala is used in some extent in the framework. This is just a background about me. The question is why is Tuple2 used in below code although the number of passing values is one not plural.
This is the controller's code:
//Action for making a message
public static Result add() {
Form<Message> f = new Form(Message.class);
List<Member> mems = Member.find.select("name").findList();
List<Tuple2<String, String>> opts =
new ArrayList<Tuple2<String, String>>();
for(Member mem: mems) {
opts.add(new Tuple2(mem.name, mem.name));
}
return ok(add.render("fill-in form", f, opts));
}
This is the Model's code:
#Entity
public class Member extends Model {
#OneToMany(cascade = CascadeType.ALL)
public List<Message> messages = new ArrayList<Message>();
#Id
public Long id;
#Required(message = "This item is Required")
public String name;
#Email(message = "Please Fill in a message")
public String mail;
public String tel;
public static Finder<Long, Member> find = new Finder<Long, Member>(Long.class, Member.class);
#Override
public String toString() {
String ids = "{id:";
for (Message m: messages) {
ids += " " + m.id;
}
ids += "}";
return ("[id:" + id + ", message:" + ids + ", name:" + name + ", mail:" + mail + ", tel:" + tel + "]");
}
public static Member findByName(String input) {
return Member.find.where().eq("name", input).findList().get(0);
}
}
This is the View's code:
#(msg:String, form1: Form[models.Message], opts: List[Tuple2[String, String]])
#main("Sample page") {
<h1>ADD MESSAGE</h1>
<p>#msg</p>
#helper.form(action = routes.Application.create) {
#(helper.select (
field = form1("name"),
options = opts
))
#(helper.textarea (
field = form1("message")
))
<input type="submit">
}
}
Again, why is Tuple2, which contains two String values, used despite one value passed from the controller to the view?
If the information I showed here is not enough, please give me a comment.
The role of a tuple is to provide multiple values in a single instance. Perhaps it's a bit like an unnamed class? To summarise the comments and give a clear example, the structure of the <option> tag in a <select> structure is
<option value="internal-value">shown-value</option>
We use it often for foreign key situations - the foreign key value is in "internal-value" and the name or other attribute from the linked table is in the shown-value.
If you use the play helper #select to generate it, you should provide a Seq of tuple2s - i.e. two strings for each option. The first for the internal value, and the second for the displayed value. I use a defining but that is just one way to do it. For example:
#defining(for (a <- AppType.all()) yield (a.id.toString,a.name)) { appTypeList =>
#select(
apiForm("forApp"),
appTypeList,
'class -> "form-control",
'_default -> "-- None Selected --",
'_label -> "App Type"
)
}
You can generate it yourself manually if you have some special needs or reason not to use the helper (or you can write your own helper :) ). For example:
<select name="forApiType" id="forApiType">
#ApiType.all().map { a =>
<option value="#a.id" #if(a.id==apiType.id) {selected}>
#a.name
</option>
}
</select>
Hello i have the following problem.
I have a search page lets call it search.xhtml and you can search for a bar-code. This value is unique so the result is always one or zero objects from the database
<p:panelGrid columns="1" style="margin:20px;">
<h:form>
<p:messages id="messages" globalOnly="true" showDetail="false" />
<p:message for="barcode" />
<p:inputText id="barcode" value="#{searchForm.barCode}"
required="true" requiredMessage="Value needed" />
<p:commandButton value="search"
action="#{searchForm.searchBarcode}" id="search"/>
</h:form>
</p:panelGrid>
This is the backingbean:
#ManagedBean
#ViewScoped
public class SearchForm extends BasePage {
private Long barCode;
#ManagedProperty("#{daoManager}")
public DaoManager daoManager;
public void setDaoManager(DaoManager daoManager) {
this.daoManager = daoManager;
}
public Long getBarCode() {
return barCode;
}
public void setBarCode(Long barCode) {
this.barCode = barCode;
}
public String searchBarcode() {
//request to dao to get the object
DataList<Data> data = daoManager.findbybarcode(barCode);
if (data.size() == 0) {
this.addMessage(FacesMessage.SEVERITY_ERROR,
"Not Found: " + barCode);
return null;
} else {
getFacesContext().getExternalContext().
getRequestMap().put("id", data.getId());
return "details";
}
}
So if i go to my details page which expect the parameter id this isnt send to the detail page.
backing bean details page:
#ManagedBean
#ViewScoped
public class DetailBean extends BasePage implements Serializable {
#PostConstruct
public void init() {
if (id != null) {
//Go on with the stuff
} else {
addMessage(FacesMessage.SEVERITY_ERROR,"Object not found");
}
}
}
What am i doing wrong? And is this wrong use of JSF? I know i can generate a list and the click on the result but thats not what i want. Also i can take the barcode from the first bean and pass it as a parameter but i want the details page only to accept the id from the objects. So is my thinking wrong? Or is there a solution to get it like this?
If I understand correctly, you wish to pass the ID of the barcode to the details page and yes this is possible.
getFacesContext().getExternalContext().getRequestMap().put("id", data.getId());
The following line is putting the ID parameter into the request that the client just sent you, but the navigation action to details will result in a different request. Try this instead:
return "details?faces-redirect=true&id=" + data.getId();
This will return an HTTP GET navigation action with the ID of the barcode passed as a request parameter in the request.
I'm trying to create a form using Spring #MVC 3.0. This form is supposed to let the user update the flavor of a soup, but I'm running into some issues. Here are my relevant model classes (assume all the getters and setters are there):
public class Soup {
String name, flavor, mainIngredient;
public String toString()
{
return "name: " + this.name + ", flavor: "
+ this.flavor + ", main: " + this.mainIngredient;
}
}
public class SmallMeal {
List<Soup> soups;
}
public class Menu {
String id;
SmallMeal smallMeals;
}
This part of the application allows the user to edit the soups. Here's the controller:
public class MenuController {
#RequestMapping(value="/soupForm", method = RequestMethod.GET)
public String updateSoups(
#PathVariable("menuId") String menuId,
ModelMap model)
{
Menu menu = // ... looked up with a DAO.
if (menu != null)
{
model.addAttribute("menu", menu);
for (Soup s : menu.getSmallMeal().getSoups())
{
System.out.println("soup: " + s.toString());
}
}
return "soupEditor";
}
#RequestMapping(value="/soupForm", method = RequestMethod.POST)
public String updateSoups(
#ModelAttribute("menu") Menu menu,
BindingResult result, SessionStatus status)
{
for (Soup s : menu.getSmallMeal().getSoups())
{
System.out.println("soup: " + s.toString());
}
return "redirect:soupUpdated";
}
}
And here's the soupForm JSP:
<form:form modelAttribute="menu">
<c:forEach var="soup" varStatus="stat" items="${menu.smallMeal.soups}">
<label>${soup.name} flavor</label>
<form:input path="smallMeal.soups[${stat.index}].flavor" />
</c:forEach>
</form:form>
Now, when I first request the page, I get an output similar to this:
name: tortilla, flavor: spicy, mainIngredient: tortillas
name: crab bisque, flavor: crab, mainIngredient: crab
And after I submit the form (after updating the flavor for tortilla), I would get an output similar to:
name: null, flavor: delicious, mainIngredient: null
name: null, flavor: null, mainIngredient: null
What's going wrong? Why isn't the rest of the data of the object being bound?
Turns out that the #SessionAttributes annotation was the answer.
#Controller
#SessionAttributes("menu")
public class MenuController {
/* ... */
}
After that was added, the data currently existing on the object persisted.
I am trying to debug an issue with the following code:
<h:panelGroup id="items">
<ui:repeat value="#{itemController.items}" var="item">
<h:form>
<h:inputText id="title" value="#{item.fields['Title']}"/>
<a4j:commandButton action="#{dao.storeItem(item)}" value="Save" render="#form"/>
</h:form>
</ui:repeat>
</h:panelGroup>
The above works if a collection is displayed in the view directly. However, if the ui:repeat starts empty, and items are added through an AJAX request, and the ui:repeat rerendered, the forms break. Specifically the model is not updated, nor actions triggered. I want to understand why.
Right now my guess is that if the ui:repeat starts empty, the form component is not created at all. Can anyone verify this, or provide the correct explanation?
ADDITIONAL INFO
Here are relevant parts of the controller, I have also tried ViewScoped, and long-running conversations:
#Named
#ConversationScoped
public class ItemController implements Serializable
{
private static final long serialVersionUID = 1L;
#Inject
private HibernateDAO dao;
public List<Item> getItems()
{
return dao.getItems();
}
public void uploadListener(final FileUploadEvent event)
{
final UploadedFile item = event.getUploadedFile();
final FacesContext context = FacesContext.getCurrentInstance();
final Application application = context.getApplication();
final String messageBundleName = application.getMessageBundle();
final Locale locale = context.getViewRoot().getLocale();
final ResourceBundle resourceBundle = ResourceBundle.getBundle(messageBundleName, locale);
final String msg = resourceBundle.getString("upload.failed");
final String detailMsgPattern = resourceBundle.getString("upload.failed_detail");
try
{
CSVImporter.doImport(item.getInputStream(), dao, item.getName());
}
catch (ParseException e)
{
final Object[] params = {item.getName(), e.getMessage()};
final String detailMsg = MessageFormat.format(detailMsgPattern, params);
final FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, detailMsg);
context.addMessage("uploadForm:uploader", facesMsg);
}
catch (TokenMgrError e)
{
final Object[] params = {item.getName(), e.getMessage()};
final String detailMsg = MessageFormat.format(detailMsgPattern, params);
final FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, detailMsg);
context.addMessage("uploadForm:uploader", facesMsg);
}
}
}
The dao simple fetches the items from a database. Here is the relevant fileupload code:
<h:form id="uploadForm" enctype="multipart/form-data">
<h:message id="message" showDetail="true" for="uploader" errorClass="error" warnClass="warning" infoClass="info" fatalClass="fatal"/>
<rich:fileUpload id="uploader"
fileUploadListener="#{itemController.uploadListener}"
maxFilesQuantity="1"
acceptedTypes="csv"
render="items message" />
</h:form>
Okay posting it here because it will be longer than comments .
It works for me which is probably not what you wanted to hear :( but I had to teak few minor things . Firstly in controller add
public void storeItems(Item item)
{
dao.storeItems();
}
then change this
<a4j:commandButton action="#{dao.storeItem(item)}" value="Save" render="#form"/>
to
<a4j:commandButton action="#{itemController.storeItem(item)}" value="Save" render="#form"/>
That however is probably not the real issue and I think that is around here
CSVImporter.doImport(item.getInputStream(), dao, item.getName());
basically I am expecting that the method above would have uploaded data from where dao.getItems(); can fetch it. So put a breakpoint at public List<Item> getItems() and once file has been upload and render="items message" renders the items panel group again it should will hit this method and at that time see if dao.storeItems() is bringing any data back which it should. Reply back then and we will take it from there.
Update below to avoid running dao fetch twice.
You can not avoid two calls to your get thats part of JSF lifeCycle and is normal.
How ever you can avoid hitting the database twice as you should too but refactoring your code along the lines of
private List<Item> items;
public List<Item> getItems()
{
return items;
}
#PostConstruct
public void init()
{
this.items = dao.getItems();
}
public void uploadListener(FileUploadEvent event) throws Exception{
......
CSVImporter.doImport(item.getInputStream(), dao, item.getName());
this.items = dao.getItems();
.....
}