Primefaces outputlabel behaves as escape = "false" - jsf

I am using primefaces 4.0 and I am having problems with p:outputLabel.
When It is mixed with any other primefaces component it behaves like escape="false"
This field is not processed even if I specify escape="true"
Example:
I have the following html code:
<h:form>
<p:outputLabel value="<b>TEXT</b>" escape="true"></p:outputLabel>
<h:outputLabel value="<b>TEXT</b> " escape="true"></h:outputLabel>
</h:form>
And for the Output I have this
<b>TEXT</b> <b>TEXT</b>
Which is expected behavior. (I am willing to see HTML tags as text).
But when I will add any other primefaces tag like in example:
<h:form>
<p:outputLabel value="<b>TEXT</b>" escape="true"></p:outputLabel>
<h:outputLabel value="<b>TEXT</b> " escape="true"></h:outputLabel>
<p:commandButton value="button"></p:commandButton>
</h:form>
Now even I have escape="true" I get
TEXT TEXT and then the button.
Does any one have experience with this how should I fix this.
Any suggestion.

I solved this issue.
I had this into my pom
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.12</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.12</version>
</dependency>
I just downgraded to 2.1.11 and everything works fine.

Related

How do I get PrimeFaces DataTable to sort?

I just can't get sorting working. I'm not sure if this should be posted in the Rain forums, because I am just using PrimeFaces for the first time, and purchased/installed the Rain layout. So I'm not sure whether Rain is causing this or not.
I define a standard p:dataTable and use:
<p:column headerText="Name" field="name" filterMatchMode="contains" />
And sort does not work.
Here is my p:dataTable definition:
<p:dataTable id="table" widgetVar="table" stripedRows="true" reflow="true"
value="#{viewBean.dtos}"
var="dto" selection="#{viewBean.dtos}" rowKey="#{dto.id}" paginator="true"
rows="10" rowSelectMode="add">
My PrimeFaces version:
<!-- https://mvnrepository.com/artifact/org.primefaces/primefaces -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>10.0.0-RC2</version>
</dependency>
You are using a PrimeFaces version that has some bugs related to sort/filter data tables.
Like this:
DataTable/TreeTable: sortBy not working with client saving state method
You can apply the workarond, but you may face other issues, so
it will be better if you switch to PrimeFaces 11, using the: PrimeFaces migration guide 10.0.0 -> 11.0.0

JSF Primefaces 10: How to set p:datePicker's maxdate attribute to tens years from now, dynamically?

Am using Java 1.8, Primefaces 10.0.0 on Tomcat 8.5.55... Am fairly new to JSF UI programming. Have a custom date JSTL tag where I need to dynamically set the maxdate to be 10 years from now when using the calendar widget (p:datePicker) - this is generic so that's why I can't place it inside a custom bean. It needs to be set declaratively inside my input.xhtml file (see below):
pom.xml:
<properties>
<primefaces-version>10.0.0</primefaces-version>
<primefaces-extension-version>10.0.1</primefaces-extension-version>
</properties>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>${primefaces-version}</version>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>primefaces-extensions</artifactId>
<version>${primefaces-extension-version}</version>
</dependency>
input.xhtml (custom taglib located inside ..src/main/webapp/WEB-INF/tags/input.xhtml):
<ui:composition xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:d="http://www.mycompany.com/jsf/facelets"
xmlns:ui="http://java.sun.com/jsf/facelets">
<p:datePicker id="#{id}" value="#{bean[property]}" rendered="#{rendered}"
disabled="#{disabled}"
pattern="MM/dd/yyyy"
required="#{required}" requiredMessage="#{requiredMessage}" timeZone="#{timeZone}"
mindate="1/1/2011"
maxdate="#{LocalDate.now().plusYears(10)}"
mask="99/99/9999">
<c:if test="#{not empty event}">
<p:ajax event="#{event}" update="#{update}"/>
<p:ajax event="dateSelect" update="#{update}" oncomplete="#{oncomplete}"/>
</c:if>
</p:datePicker>
</ui:composition>
My mindate works - I can not go before 1/1/2011 in my calendar widget.
But I can go well past 2031 inside my calendar widget.
How can I set the maxdate to 10 years from now only in the input.xhtml file?

p:inputSwitch Listener only executes once

I´m having a Problem with the Input Switch of Primefaces and the ajax change event for it. My Setup is following
<p:inputSwitch id="idOfTheSwitch"
style="width: 40px"
value="#{form.booleanWhichGetsChanged}">
<p:ajax listener="#{form.methodWhichShouldGetCalled()}"/>
</p:inputSwitch>
The Problem here is the listener executes the Method in the Beans just once.
public void methodWhichShouldGetCalled() {
// Should do something every time the Input Switch is getting switched.
// Loads filtered Data
}
Versions:
<!-- JSF -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.2</version>
</dependency>
<!-- Primefaces -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>6.2.18</version>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>primefaces-extensions</artifactId>
<version>6.2.10</version>
</dependency>
The Standard event for ajax ist change, isn´t it?
The Name of the Beans and the Method is changed for Stackoverflow.

What is the function of #this exactly?

As far as I know the #this is to denote the current component triggering the event, such as :
<p:commandButton process="#this" ... />
And in JSF 2 Ajax, the #this can also mean the encapsulating component, like :
<h:inputText ...>
<f:ajax execute="#this" ... />
</h:inputText>
And I have one case where using p:datatable, including or excluding #this can have a different impact upon Ajax partial submit
Here's the example, in this case, the process is using #this, and this works as expected, where when process happens first, and then followed by setPropertyActionListener and last, the action is executed :
<p:column>
<p:commandLink
value="#{anggaranDetail.map['code']}"
process="#this infoAnggaranForm:Anggaran"
update="detailDialogForm:Anggaran detailDialogForm:SubAnggaran"
oncomplete="infoAnggaranDialog.hide()"
image="ui-icon ui-icon-search"
action="#{tInputBean.updateAnggaranSubAnggaran}">
<f:setPropertyActionListener value="#{anggaranDetail}"
target="#{infoAnggaranBean.selectedAnggaranDetail}" />
</p:commandLink>
</p:column>
But when I omit the #this from this example, the setPropertyActionListener and the action are never executed, as if they're not there.
I wonder why ? Perhaps #this has some other meaning other than the current component, perhaps the current record in this example ?
Im using tomcat 7, and these are my dependencies :
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0.4-b09</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.4-b09</version>
<scope>compile</scope>
</dependency>
The PrimeFaces process and standard JSF execute attributes should point to spaceseparated component identifiers of components which JSF should process during the entire JSF lifecycle upon an ajax request (get request parameters, validate them, update model, execute action). The process defaults to #form, the current form, and the execute defaults to #this, the current component. In command links/buttons this is mandatory to execute the actions associated with the link/button itself.
However, in your datatable you have process="#this infoAnggaranForm:Anggaran", thus two components to process. If you omit #this but keep the other component, then it will only process/execute the other component and not the link/button component. If you omit the process attribute it will default to #form. If you have more other input components in the same form, then they will also be processed.
Depending on the concrete functional requirement, you could just keep it process="#this infoAnggaranForm:Anggaran", or omit it. JSF will then process/execute at least both the button and the other component, exactly as you want.
See also:
Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes

valueChangeListener and ajax execution order problem on selectOneMenu

I'm currently experiencing a strange phenomena, where setting the value to the model happens before executing valueChangeListener.
Basically what i would like to happen is :
I change the select menu
The new value get submitted using Ajax to update the myBean (using f:ajax)
Execute a query based on the newly submitted value (using valueChangeListener)
Render the table based on the result from the last query
But what happens when i run it is in this order, 1 - 3 - 2 - 4 (not 1 - 2 - 3 - 4 as i imagined)
Here's the part of the UI :
<h:selectOneMenu label="budget" id="budget"
converter="genericConverter"
value="#{myBean.budget}"
valueChangeListener="#{myBean.actionSearch}">
<f:ajax render="myGrid" />
<f:selectItem itemLabel="Choose one .." noSelectionOption="true" />
<f:selectItems ... />
</h:selectOneMenu>
And this is the excerpt from the bean :
public void actionSearch() {
System.out.println("searching with this.budget == " + this.budget);
...
}
public void setBudget(String budget) {
System.out.println("setting budget : " + budget);
this.budget = budget;
}
And this is the output :
searching with this.budget == xxxx
setting budget : yyyy
What i would like is, setting the budget first from the new value selected in the UI, and then start searching based on the new UI. But i dont know how to achieve that.
And im using Tomcat 7 along with these :
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0.4-b09</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.4-b09</version>
<scope>compile</scope>
</dependency>
I wonder what i did wrong ?
Thank you !
The valueChangeListener is executed during Validations phase, before the Update Model Values phase. It is intented to be able to get a handle of both the old and new value so that you can if necessary do some business stuff (logging?) based on the real change. In JSF 1.x this was however more than often (ab)used to invoke actions on a dropdown change only, but it has to be used in combination with onchange="submit()", immediate="true", FacesContext#renderResponse() and other stuffs. The selected value is to be obtained by ValueChangeEvent#getNewValue() (the ValueChangeEvent is supposed to be definied as method's argument).
For JSF 2.x you don't need the valueChangeListener anymore in such case. You're also not interested in the old value anyway. Use the listener attribute of <f:ajax> instead.
<f:ajax listener="#{bean.actionSearch}" />
This will be executed during Invoke Action phase, after Update Model Values phase.

Resources