I created some composite components and need to pass attribute that could be used as "target" in Primefaces p:dataExporter and "datasource" in p:columnToggler.
First attr. "FormID" works as expected, but second one "tableID" do not. It is used under contextMenu. Code:
<composite:interface>
<composite:attribute name="FormID"/>
<composite:attribute name="tableID"/>
</composite:interface>
<composite:implementation>
<p:contextMenu for="#{cc.attrs.FormID}">
<p:submenu label="Export">
<p:menuitem value="Export to XLS" onclick="$('#exportToXLS').click()" />
</p:submenu>
<p:menuitem value="Columns" onclick="$('#toggler').click()" />
</p:contextMenu>
<p:commandLink id="toggler" type="button" />
<p:columnToggler datasource="#{cc.attrs.tableID}" trigger="toggler" />
<p:commandLink id="exportToXLS" ajax="false" width="24">
<p:dataExporter type="xls" target="#{cc.attrs.tableID}"
fileName="fileXls" />
</p:commandLink>
</composite:implementation
Here is github repo with project with code where my problem occur: https://github.com/ntokarsk/PrimefacesTest
Problem solved.
I still don't know why previous solution didn't work - but this solution works. I have just read some old post and learn that menuitem is commandLink itself so I move p:dataExporter into menuItem and it works :D
1 thing is still missing - columnTrigger doesn't work. Any idea?
here's the code:
<composite:interface>
<p:menuitem value="Export to XLS" ajax="false">
<p:dataExporter type="xls" target=":#{cc.attrs.FormID}:#{cc.attrs.tableID}"
postProcessor="#{edycjaDanychCentrumBean.postProcessXLS}"
fileName="daneCentrumDataTable" />
</p:menuitem>
<p:menuitem value="Export to PDF" ajax="false">
<p:dataExporter type="pdf" target=":#{cc.attrs.FormID}:#{cc.attrs.tableID}"
fileName="daneCentrumDataTable" />
</p:menuitem>
</p:submenu>
<p:menuitem value="Delete" icon="ui-icon-close" />
<p:menuitem id="toggler" value="Columns" icon="ui-icon-calculator">
<p:columnToggler datasource=":#{cc.attrs.FormID}:#{cc.attrs.tableID}" trigger="toggler" />
</p:menuitem>
</p:contextMenu>
</composite:implementation>
Related
I want to use JSR303 Bean Validation for my JSF+PrimeFaces frontend. I have an entity annotated with #Size(min=2, max=5). When I enter some wrong input and submit the form, then the action method is not invoked, which is correct as the validation has failed, but I don't get any message on the frontend under the element. I suppose, that some messages resources are not loaded correctly.
Here is my page:
<h:form id="profile-form" styleClass="profile-form">
<h2>#{txt['interview.profile.form.title']}</h2>
<p:outputPanel id="profile-panel" styleClass="profile-panel">
<tc:textarea id="text_de" value="#{profileBean.profile.textDe}" label="#{txt['interview.profile.text_de']}" validateBeanDisabled="true"/>
</p:outputPanel>
<p:outputPanel id="profile-actions-panel" styleClass="interview-actions-panel profile-actions-panel">
<p:commandButton value="#{txt['global.save']}" action="#{profileBean.saveProfile}" update="profile-form" />
</p:outputPanel>
</h:form>
The <tc:textArea> is just a composite component:
<composite:interface>
<composite:attribute name="value" required="false" />
<composite:attribute name="label" required="false" />
<composite:attribute name="id" required="false" />
<composite:attribute name="validateBeanDisabled" required="false" default="true" />
</composite:interface>
<composite:implementation>
<div class="form-line float-left">
<span class="label">#{cc.attrs.label}</span>
<span class="input bigWidth">
<p:inputTextarea value="#{cc.attrs.value}" id="#{cc.attrs.id}">
<f:validateBean disabled="#{cc.attrs.validateBeanDisabled}"/>
</p:inputTextarea>
<p:message id="#{cc.attrs.id}-validation" for="#{cc.attrs.id}" />
</span>
</div>
</composite:implementation>
Here is my faces-config.xml:
<application>
<locale-config>
<default-locale>de</default-locale>
</locale-config>
<resource-bundle>
<base-name>texts</base-name>
<var>txt</var>
</resource-bundle>
What am I doing wrong? Do I need to include something else on classpath? Thanks.
I want to format a link like currency. Does anyone know a good way of dealing with such an issue? I'm using Mojarra, JSF 2, PrimeFaces. Usage of a <f:facet> would be ideal, like in following example:
<h:link outcome="/somePage.xhtml">
<f:facet name="value">
<h:outputText value="#{result.price}">
<f:convertNumber type="currency" currencySymbol="€" minFractionDigits="2" maxFractionDigits="2" locale="de" />
</h:outputText>
</f:facet>
<f:param name="id" value="#{result.id}" />
<f:param name="windowId" value="" />
<f:param name="parentWindowId" value="#{windowId}" />
</h:link>
It look much like that you're overcomplicating things. The <f:facet name="value"> is completely unnecessary. The <h:link> component's support for it is also not listed anywhere in the tag documentation.
This works as expected:
<h:link outcome="/somePage.xhtml">
<h:outputText value="#{result.price}">
<f:convertNumber type="currency" currencySymbol="€" minFractionDigits="2" maxFractionDigits="2" locale="de" />
</h:outputText>
<f:param name="id" value="#{result.id}" />
<f:param name="windowId" value="" />
<f:param name="parentWindowId" value="#{windowId}" />
</h:link>
I need to show and hide component in my JSF 2-PrimeFaces application, please find my code below for the same:
<p:outputLabel for="online_offer" value="Online offer#{msg._question_mark}" styleClass="font-size-1em font-weight-bold input-panel-main" />
<p:panel>
<h:panelGrid columns="1">
<p:selectBooleanButton id="online_offer" value="#{QckPstBen.offer.isExpired}" onLabel="Yes" offLabel="No" onIcon="ui-icon-check" offIcon="ui-icon-close" >
<f:ajax event="click" render="#form" />
</p:selectBooleanButton>
</h:panelGrid>
</p:panel>
<h:outputLabel value=" " />
<h:panelGroup rendered="#{QckPstBen.offer.isExpired}">
<p:outputLabel for="website" value="Website/link to the offer#{msg._colon}" styleClass="font-size-1em font-weight-bold input-panel-main" />
<p:panel>
<h:panelGrid columns="1">
<p:inputText id="website" required="true" size="38" />
<p:watermark for="website" value="www.discountbox.in" />
</h:panelGrid>
</p:panel>
</h:panelGroup>
But it doesnt work, any clue
PrimeFaces components doesn't support <f:ajax>. Use <p:ajax> instead.
<p:selectBooleanButton ...>
<p:ajax update="#form" />
</p:selectBooleanButton>
Note that I omitted the event attribute, it defaults here to click already.
Place rendered on children of <h:panelGroup> instead or place a container of some sort around it, for example p:panel.
This may be OBE by now but...
When referencing the page bean, don't I recall in the #{} context, the convention of using lowercase for class names and method/attributes of the page bean (i.e. not #{QckPstBen.offer.isExpired} but #{qckPstBen.offer.isExpired}?
I have a form with 4 fields (2 dates, 2 selectOne).
My Bean is SessionScoped.
When I change the values in the form once, and click on submit, the applications works fine.
But when I want to change the values in form again, nothing happens. no change nor execution.
My Form looks like:
<ui:define name="sidebar">
<p:panel header="Select Values">
<h:form id="graphform">
<p:growl id="msg" />
<p:panelGrid columns="1">
<h:outputLabel for="servervalue" value="Servervalue: " />
<p:selectOneMenu value="#{graph.servervalue }" id="servervalue">
<f:selectItems value="#{formconst.SERVERVALUES}" />
</p:selectOneMenu>
<h:outputLabel for="startdate" value="Startdate: " />
<p:calendar disabledWeekends="false" size="10" pattern="dd.MM.yyyy"
showOtherMonths="true" maxlength="10"
mindate="#{formconst.MINDATE }" maxdate="#{formconst.MAXDATE}"
showButtonPanel="true" navigator="true" readOnlyInputText="true"
id="startdate" value="#{graph.startdate }" showOn="button"
required="true" />
<h:outputLabel for="enddate" value="Enddate: " />
<p:calendar disabledWeekends="false" size="10" pattern="dd.MM.yyyy"
showOtherMonths="true" maxlength="10"
mindate="#{formconst.MINDATE }" maxdate="#{formconst.MAXDATE }"
showButtonPanel="true" navigator="true" readOnlyInputText="true"
id="enddate" value="#{graph.enddate }" showOn="button"
required="true" />
<h:outputLabel for="filter" value="Filter: " />
<p:selectOneMenu value="#{graph.filter }" id="filter">
<f:selectItems value="#{formconst.GENERALFILTER}" />
</p:selectOneMenu>
</p:panelGrid>
<p:separator />
<p:panelGrid columns="2">
<p:commandButton value="Submit" update="#all"
action="#{ graph.updateChart }" />
<p:commandButton value="Reset" update="#all"
action="#{ graph.resetChart }" />
</p:panelGrid>
</h:form>
</p:panel>
</ui:define>
<ui:define name="content">
<h:form id="linechart">
<p:lineChart value="#{graph.cartesianChartBean.chartmodel }"
enhancedLegend="true" legendPosition="nw" xaxisAngle="50" />
</h:form>
</ui:define>
The same happens when I change SessionScoped to ViewScoped or RequestScoped.
I can change the values only one time.
I use primefaces 3.2 with apache myFaces 2.0.2 on WebSphere Application Server 8.0
Best Regards Veote
I implemented an ordering mechanism to sort the result of a table (loaded from a database). All beans are requestScoped and I make a new query to the db each time the user sort the result.
My problem is that it works well the first time, but my table is reset if I click twice.
After googling, I found that I used the same idea described here (thx Balusc ;) ).
In more details, I created a custom component to put in each header of the columns:
<composite:interface>
<composite:attribute name="label" required="true" shortDescription="The label of the link"/>
<composite:attribute name="action" required="true" shortDescription="The action for sorting"/>
<composite:attribute name="columnName" required="true" shortDescription="The identifier of the column"/>
<composite:attribute name="update" required="true" shortDescription="The id of element to update"/>
<composite:attribute name="sortColumn" required="true" shortDescription="The column which we want sort"/>
<composite:attribute name="sortOrder" required="true" shortDescription="The order of sort"/>
</composite:interface>
<composite:implementation>
<h:panelGroup
rendered="#{cc.attrs.sortColumn!=cc.attrs.columnName}">
<p:commandLink action="#{cc.attrs.action}"
update="#{cc.attrs.update}"
value="#{cc.attrs.label}"
styleClass="sortable">
<f:param name="sortOrder" value="ASCENDING" />
<f:param name="sortColumn" value="#{cc.attrs.columnName}" />
</p:commandLink>
</h:panelGroup>
<h:panelGroup
rendered="#{cc.attrs.sortColumn==cc.attrs.columnName and cc.attrs.sortOrder=='DESCENDING'}">
<p:commandLink action="#{cc.attrs.action}"
update="#{cc.attrs.update}"
value="#{cc.attrs.label}"
styleClass="desc">
<f:param name="sortOrder" value="ASCENDING" />
<f:param name="sortColumn" value="#{cc.attrs.columnName}" />
</p:commandLink>
</h:panelGroup>
<h:panelGroup
rendered="#{cc.attrs.sortColumn==cc.attrs.columnName and cc.attrs.sortOrder=='ASCENDING'}">
<p:commandLink action="#{cc.attrs.action}"
update="#{cc.attrs.update}"
value="#{cc.attrs.label}"
styleClass="asc">
<f:param name="sortOrder" value="DESCENDING" />
<f:param name="sortColumn" value="#{cc.attrs.columnName}" />
</p:commandLink>
</h:panelGroup>
</composite:implementation>
And I defined two hidden fields in the form of my jsf page:
<h:inputHidden value="#{myBean.sortOrder}" />
<h:inputHidden value="#{myBean.sortColumn}" />
If someone could explain where I am wrong?