I have a DataTable where I want to modify the font size. The user can set the font size with a selectOneMenue component.
Now if I update it with jQuery this only happens the first time. If I want to change the font size by the selectOneMenue the font size is set to default and if I make a refresh (F5) the font size is changed successfully. But I do not want this behaviour.
So I added the reload() function in the script part. If I do this I always get this Firefox Message if I want to reload….. and then it renders the table with default size and shortly after it renders the right font size. So the end product is ok but I do not want this firefox message to appear that has to be submitted and I also want to turn off the prerendering ot the table with the default font size.
Now I have this code
<script>
jQuery(document)
.ready(
function() {
jQuery('#dtSummary')
.css('cssText',
'font-size:#{summaryBean.selectedFont}px !important');
});
function changeFont() {
document.getElementById("dtSummary").style.fontSize = "#{summaryBean.selectedFont}px !important;}";
window.location.reload(true);
}
</script>
<h:form id="form" prependId="false">
<h:panelGroup>
<h:panelGrid columns="3" styleClass="rainstar-form-inline"
columnClasses="rainstar-form-column-left rainstar-form-column-right">
<p:selectOneMenu id="targ" effect="fade"
styleClass="rainstar-input-small2"
value="#{summaryBean.selectedFont}"
valueChangeListener="#{summaryBean.selectionFont_change}"
onchange="changeFont()">
<f:selectItems value="#{summaryBean.fontCollection}" />
<p:ajax update="dtSummary" />
</p:selectOneMenu>
</h:panelGrid>
<p:commandButton value="#{msg.button_print}" icon="ui-icon-print"
styleClass="rainstar-button-right"
action="#{summaryBean.generatePdf()}" ajax="false" />
<p:dataTable id="dtSummary" styleClass="rainstar-form-margin-top"
value="#{summaryBean.eintragList}"
selection="#{summaryBean.selectedEintrag}" selectionMode="multiple"
var="eintrag" rowKey="#{eintrag.it1}">
<p:column id="header" styleClass="ui-state-default">
<div class="ui-dt-c">#{eintrag.it1}</div>
</p:column>
<p:column styleClass="rainstar-table-item"
headerText="#{tableBundleBean.summary_table_nozzles} [mm]">
<h:outputText value="#{eintrag.it2}" />
</p:column>
</p:dataTable>
</h:panelGroup>
</h:form>
You don’t really need jquery here. Try:
Jquery would make sense if you wanted to avoid server roundtrip and rendering for performance reasons for example. In such case the selectMenu widget should not cause a page refresh.