-
1. Re: Disabling rendering in case of empty data table does not work as expected
liuliu Oct 11, 2013 10:54 AM (in response to tomhain)could you show your backing bean code?
-
2. Re: Re: Disabling rendering in case of empty data table does not work as expected
tomhain Oct 11, 2013 12:58 PM (in response to liuliu)This is the relevant part of the Backing Bean:
@RequestScoped @Named public class ParticipationListProducer { @Inject private ParticipationRepository participationRepository; @Inject private Logger log; private List<Participation> participations; private Date trainingDate = new Date(); @Produces @Named public List<Participation> getParticipations() { log.info("GetParticipations called " + participations.size() + " Elements"); return participations; } public void setTrainingDate(Date x) { trainingDate = x; retrieveAllParticipators(); } public Date getTrainingDate() { return trainingDate; } @PostConstruct public void retrieveAllParticipators() { participations = participationRepository.getAllForSpecificDateOrderedByName(trainingDate); } ...
-
3. Re: Disabling rendering in case of empty data table does not work as expected
rhanus Oct 14, 2013 5:13 AM (in response to tomhain)your code should work as you expect:
tag with attribute rendered="#{empty participations}" is displayed when either participations is null or the collection is empty
rendered="#{not empty participations}" has opposite meaning
doublecheck your bean code or did you experience any re-rendering problems ?
-
4. Re: Disabling rendering in case of empty data table does not work as expected
liuliu Oct 14, 2013 6:44 AM (in response to tomhain)I dont know how @produces works, probably the FIRST time "participations" called for rendered, it is empty.
-
5. Re: Disabling rendering in case of empty data table does not work as expected
tomhain Oct 14, 2013 2:51 PM (in response to rhanus)Well, I expected the described behaviour as well - but it is still not working. Honestly, I doublechecked my bean code several times. I can't see the issue. The bean deliveres the correct size of the collection to the jsf page. I don't think, the issue is because of my backing bean.
The page itself gets displayed correctly (besides the empty data table). What do you mean by re-rendering problems? How can I recognize the same ? Is there a way to debug the client side code execution ?
-
6. Re: Disabling rendering in case of empty data table does not work as expected
liuliu Oct 15, 2013 3:19 AM (in response to tomhain)Could you try to replace participations with participationListProducer.participations?
-
7. Re: Disabling rendering in case of empty data table does not work as expected
rhanus Oct 15, 2013 4:48 AM (in response to tomhain)in your bean code the list of participants is produced only once at very beginning of bean lifecycle into the jsf page
when training date is updated the list is not updated anyway
liumin is propably right try to replace producer method with common getter
-
8. Re: Disabling rendering in case of empty data table does not work as expected
tomhain Oct 15, 2013 5:32 AM (in response to rhanus)I tried replacing participations by participationListProducer.participations and removed the @Produces annotiation. Same result :-(
-
9. Re: Disabling rendering in case of empty data table does not work as expected
liuliu Oct 15, 2013 9:12 AM (in response to tomhain)I did the same test, manuelly creat the list in retrieveAllParticipators. your code works with getter.
-
10. Re: Disabling rendering in case of empty data table does not work as expected
tomhain Oct 15, 2013 4:09 PM (in response to liuliu)Thanks for your time you spend on answering my question. However, it is still not working as expected. I really don't know why. I am currently reducing the code step by step to encapsulate the problem area...
-
11. Re: Re: Disabling rendering in case of empty data table does not work as expected
tomhain Oct 15, 2013 4:34 PM (in response to rhanus)Hi Radim,
Radim Hanus schrieb:
in your bean code the list of participants is produced only once at very beginning of bean lifecycle into the jsf page
when training date is updated the list is not updated anyway
liumin is propably right try to replace producer method with common getter
I did not copy the whole JSF in the discussion - for purposes of clarity.
Here is the relvant sourcecode , which updates the table:
<rich:calendar id="trainingCalendar" mode="ajax" popup="false" boundaryDatesMode="scroll" locale="de/DE" buttonLabel="Heute" datePattern="dd.MM.yyyy" dataModel="#{calendarModel}" value="#{participationListProducer.trainingDate}"> <a4j:ajax event="change" render="trainingDate_output participationTable participationAttributes_output popup" /> </rich:calendar>
This works, the table gets updated whenever the date is changed.
-
12. Re: Re: Re: Disabling rendering in case of empty data table does not work as expected
tomhain Oct 15, 2013 5:07 PM (in response to tomhain)This is the whole source code, now:
JSF:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" template="/WEB-INF/templates/default.xhtml" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"> <ui:define name="content"> <h2>Trainingskalender:</h2> <h:outputStylesheet> .tdc { background-color: green; } .wdc { font-weight: bold; font-style: italic; } </h:outputStylesheet> <h:form> <rich:calendar id="trainingCal" mode="ajax" popup="false" boundaryDatesMode="scroll" locale="de/DE" buttonLabel="Heute" datePattern="dd.MM.yyyy" dataModel="#{calendarModel}" value="#{participationListProducer.trainingDate}"> <a4j:ajax event="change" render="output participationTable" /> </rich:calendar> </h:form> <h2><h:outputText id="output" value="#{calendarModel.selectedDate}" /> </h2> <h:panelGroup rendered="#{empty participationListProducer.participations}"> <em>No items available</em> </h:panelGroup> <h:dataTable var="_participation" value="#{participationListProducer.participations}" styleClass="simpletablestyle" rendered="#{not empty participationListProducer.participations}" id="participationTable"> <h:column> <f:facet name="header">Datum</f:facet> #{_participation.trainingItem.trainingDateAsString} </h:column> <h:column> <f:facet name="header">Spieler</f:facet> #{_participation.player.name}, #{_participation.player.firstname} </h:column> </h:dataTable> </ui:define> </ui:composition>
And this is code of the Backing Bean:
@RequestScoped @Named public class ParticipationListProducer { @Inject private ParticipationRepository participationRepository; @Inject private Logger log; private List<Participation> participations; private Date trainingDate = new Date(); private int numberOfParticipators; private int numberOfDriversBack; private int numberOfDriversForth; private int numberOfSeatsForthAvailable; private int numberOfSeatsBackAvailable; private int numberOfSeatsBackRequired; private int numberOfSeatsForthRequired; public int getNumberOfParticipators() { return numberOfParticipators; } public int getNumberOfDriversBack() { return numberOfDriversBack; } public int getNumberOfDriversForth() { return numberOfDriversForth; } public int getNumberOfSeatsBackRequired() { log.info("return numberOfSeatsBackRequired" + numberOfSeatsBackRequired); return numberOfSeatsBackRequired; } public int getNumberOfSeatsForthRequired() { log.info("return numberOfSeatsForthRequired=" + numberOfSeatsForthRequired); return numberOfSeatsForthRequired; } public int getNumberOfSeatsBackAvailable() { return numberOfSeatsBackRequired; } public int getNumberOfSeatsForthAvailable() { return numberOfSeatsForthRequired; } public List<Participation> getParticipations() { log.info("GetParticipations called " + participations.size() + " Elements"); return participations; } public void setTrainingDate(Date x) { trainingDate = x; retrieveAllParticipators(); } public Date getTrainingDate() { return trainingDate; } public String getTrainingDateAsFormattedString() { return DateUtil.getSelectedDateAsFormattedString(trainingDate); } @PostConstruct public void retrieveAllParticipators() { participations = participationRepository.getAllForSpecificDateOrderedByName(trainingDate); calculateParticipationAttributes(); } private void calculateParticipationAttributes() { numberOfParticipators = 0; for (Participation p : participations) { log.info(" Just read -> " + p.getId() + "; " + p.getTrainingItem().getCurrentDate()); if (p.isParticipating()) numberOfParticipators++; if (p.isDrivingBack()) numberOfSeatsBackAvailable = numberOfDriversBack + p.getPlayer().getCarsize(); if (p.isDrivingForth()) numberOfSeatsForthAvailable = numberOfDriversForth + p.getPlayer().getCarsize(); } numberOfSeatsBackRequired = numberOfParticipators - numberOfSeatsBackAvailable; numberOfSeatsForthRequired = numberOfParticipators - numberOfSeatsForthAvailable; } }
@Liumin: Do you see a diffference to your code ? Tx.
-
13. Re: Re: Re: Re: Disabling rendering in case of empty data table does not work as expected
liuliu Oct 16, 2013 3:21 AM (in response to tomhain)not big difference except you creat your list with database, i creat it myself. here is my code, very simple.
@Named @RequestScoped public class TestBean implements Serializable{ private static final long serialVersionUID = 4934630753831928437L; private static Log logger = LogFactory.getLog(TestBean.class); private List<String> header=new ArrayList<String>(); @PostConstruct public void init(){ // this.header.add("header1"); // this.header.add("header2"); } public List<String> getHeader() { return this.header; } }
xhml
<rich:dataTable rendered="#{not empty testBean.header}" value="#{testBean.header}" var="head"> <rich:column > #{head} </rich:column> </rich:dataTable>
BTW I use mojarra 2.1.25
-
14. Re: Re: Re: Re: Disabling rendering in case of empty data table does not work as expected
tomhain Oct 18, 2013 5:25 PM (in response to liuliu)Your code works as expected in my container as well. This is strange, I can't see the big difference to my code and I really don't understand why the 'empty' keyword does not work in my code...
I use jboss-jsf-api 2.1, spec. 2.0.9.