p:printer prints rowIndex

UI Components for JSF
Post Reply
mikloman
Posts: 27
Joined: 18 Nov 2009, 00:23

26 May 2010, 02:15

Hi
What is the reason, that the p:printer print the rowIndex on each dataTable which is hidden on the website?

I think, that shouldnt be the desired affect, or?

Is this a bug in the lib?

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

29 May 2010, 11:32

Can you post your code so we can have a look?

mikloman
Posts: 27
Joined: 18 Nov 2009, 00:23

29 May 2010, 11:43

Hi
i had at the moment exactly looked for this again. I think, that the problem ist, that the printer didnt look, whiche td is hidden. If i put a style="display:none" in one of this rowIndex-td's so the result will be correct. Means that he didnt print that row. So i think there should be a workaround in datatable. So that the attribute display is not only defined in the css but also in the element itself for each rowIndex....

But i didnt know if i do something wrong. But there are no attributes like excludeColumn which is definied for exaple in the dataexporter.

Here is the jsf-code:

Code: Select all

     		<h:commandLink>
			<p:graphicImage value="resources/images/excel.png" />
			<p:dataExporter encoding="Utf-8" type="xls" target="tableMitarbeiterExport" fileName="absolvierteUebungen" />
		</h:commandLink>

		<h:commandLink>
			<p:graphicImage value="resources/images/pdf.png" />
                        <p:dataExporter encoding="Utf-8" type="pdf" target="tableMitarbeiterExport" fileName="absolvierteUebungen"/>
		</h:commandLink>

		<h:commandLink>
			<p:graphicImage value="resources/images/csv.png" />
			<p:dataExporter encoding="Utf-8" type="csv" target="tableMitarbeiterExport" fileName="absolvierteUebungen" />
		</h:commandLink>

		<h:commandLink>
			<p:graphicImage value="resources/images/xml.png" />
			<p:dataExporter encoding="Utf-8" type="xml" target="tableMitarbeiterExport" fileName="absolvierteUebungen" />
		</h:commandLink>

              <h:commandLink id="lnk">
                  <p:graphicImage value="resources/images/printer.png" />
                  <p:printer id="anz_mitarbeiter" target="tableMitarbeiter"/>
              </h:commandLink>
            
           <p:dataTable id="tableMitarbeiter"  var="item" value="#{mitarbeiterListController.absolvierteUebung}">
              <p:column>
                <f:facet name="header">
                    <h:outputText value="Bezeichnung" />
                </f:facet>
                    <h:outputText value="#{item.bezeichnung}" />
            </p:column>

            <p:column>
                <f:facet name="header">
                        <h:outputText value="Anzahl" />
                </f:facet>
                    <h:outputText value="#{item.anzahl}" />
            </p:column>

            <p:column>
                <f:facet name="header">
                    <h:outputText value="Datum" />
                </f:facet>
                <h:outputText escape="false" value="#{item.datum}"/>
            </p:column>

           <p:column>
                <f:facet name="header">
                    <h:outputText value="Schiffe" />
                </f:facet>
               <h:outputText escape="false" value="#{item.schiffe}"/>
            </p:column>
        </p:dataTable>

            <p:dataTable style="display:none" id="tableMitarbeiterExport"  var="item" value="#{mitarbeiterListController.absolvierteUebung}">
              <p:column styleClass="">
                <f:facet name="header">
                    <h:outputText value="Bezeichnung" />
                </f:facet>
                    <h:outputText value="#{item.bezeichnung}" />
            </p:column>

            <p:column>
                <f:facet name="header">
                    <h:outputText value="Anzahl" />
                </f:facet>
                <h:outputText value="#{item.anzahl}" />
            </p:column>

            <p:column>
                <f:facet name="header">
                    <h:outputText value="Datum" />
                </f:facet>
                <h:outputText escape="false" value="#{item.datum_pdf}"/>
            </p:column>

           <p:column>
                <f:facet name="header">
                    <h:outputText value="Schiffe" />
                </f:facet>
               <h:outputText escape="false" value="#{item.schiffe_pdf}"/>
            </p:column>
        </p:dataTable>
Sorry, the words are german....

Output is:
rowIndex | Description | Number | Date | Ship

It should be:
Description | Number | Date | Ship

Thanks and regards
Manuel

mikloman
Posts: 27
Joined: 18 Nov 2009, 00:23

29 May 2010, 12:09

I had looked now in the source.

I think there will be a easy workaround.

there is in the datatablerenderer.java the line, which write this rowIndex as td in the context.

Code: Select all

			//rowIndex
			writer.startElement("td", null);
			writer.write(String.valueOf(dataTable.getRowIndex()));
			writer.endElement("td");
			
I think i will add a new line like this:

Code: Select all

			//rowIndex
			writer.startElement("td", null);
			writer.writeAttribute("style", "display:none", null);
                       writer.write(String.valueOf(dataTable.getRowIndex()));
			writer.endElement("td");
But I think i must change something for the th too.

Greats
Manuel

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

30 May 2010, 17:16

Manuel, I'd appreciate if you can try this change locally and share results with us. We can apply this change if it fixes the printer issue and does not break anything which I don't that it will. We currently hide the rowIndex column with css with adding;

Code: Select all

th.yui-dt-hidden, td.yui-dt-hidden {
	display: none;
}
When printing it seems to be ignored so as you are trying we might need to add this declaratively as well.

mikloman
Posts: 27
Joined: 18 Nov 2009, 00:23

30 May 2010, 17:38

Hi cagatay
thanks for all the works firs. Its great what you are doing... And primefaces will be one of the best and cleares framworks which i knows that it exist. Great and thanks...

No i have tried it myself with firebug. I think my small workaround will works fine.
If i add in the rendered datatable , means in the <td> of this table a style="display:none" with firebut and make after a print, then the printer works correct. I think, that the jqprinter didnt realise, that there will be an external css , where this property is defined.

But if i add this new line writer.writeAttribute("style", "display:none") nothing is shown (rendered) on the page.
There is no style attribut for eacht td. I think, that the yui-datatable will remove my attributs, if the javascript is executed. I didnt understand this. But i'm not the hero in javascript.

But is there a way to rerender the table after js is executed, to add this attribute with java again?

I hope you understand what i means.

Thanks
Miklomant

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

30 May 2010, 22:02

Problem is even we add this attribute with javascript after table is displayed by underlying YUI, it will be lost in printing process. I think we need to make the css work in printing as well. Maybe adding the same styles to a css with media type set to print would solve it. For more information take a look at;

http://www.css-help.com/css-mediaprint.htm

So maybe you can add a css to your page like;

Code: Select all

<link rel="stylesheet" type="text/css" href="/print.css" media="print"/>
which only has;

Code: Select all

th.yui-dt-hidden, td.yui-dt-hidden {
   display: none;
}

mikloman
Posts: 27
Joined: 18 Nov 2009, 00:23

30 May 2010, 22:41

I had tried this too. But it wasnt possible for me to fix this bug. Ok, i hadn't exactly done what you had described bevor. Maybe this works. ..??
But i have now an other soltution for me. I have added a new Javascript-Line in DatatableRenderer.java. So it will add the display:none as an element-attribut directly to all rows with class "yui-dt-col-rowIndex" in it after the widget-datatable is rendered. I think that shold solve the problem without any problems in other modules or stuff. But if the solution where you had described with your css-definitions will work, i think i will do it like this. Its the better solution. More like best practises in programming i think. If i have time, i will try it myself.

From DataTableRenderer.java (last 3 lines in encodeScript(FacesContext facesContext, DataTable dataTable))

Code: Select all

               ....
		writer.write("});\n");
		writer.write("YAHOO.util.Dom.setStyle(YAHOO.util.Dom.getElementsByClassName('yui-dt-col-rowIndex'), 'display', 'none');");
		writer.endElement("script");
Thanks and regards
Mikloman

steeveherris
Posts: 3
Joined: 17 Jun 2010, 05:34

28 Jun 2010, 16:36

Here is a answer to your question that printer is printing to all rows due to the inbuilt process. In order to get rid of it need to change the settings. Try it will work.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 57 guests