error#malformedXML with ajax requests in JSF - ajax

Context : Weblogic 12.2.1 / JSF 2.1.6 / Richfaces 4.2.2 / Primefaces 3.4
I have a JSF application that was on Weblogic 10.3.6 and that I successfully deploy on Weblogic 12.2.1.
I am facing the following error after each ajax request :
Received 'error#malformedXML' event from <input ...
[200] undefined: undefined
This error usually occurres when the component to be rendered is not present in the page but as you'll see in the following pieces of code, this is not the case :
Java
private int count = 0;
public void commandButton() {
System.out.println("Click");
count++;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
HTML
JSF with Ajax
<h:form>
<h:commandButton value="JSF with ajax">
<f:ajax listener="#{myBean.commandButton}" render="count1" />
</h:commandButton>
<h:outputText id="count1" value="#{myBean.count}" />
</h:form>
The click on this button correctly executes myBean.commandButton but then produces the error described below and does a "refresh" of the page.
Richfaces
<h:form>
<a4j:commandButton value="Richfaces" action="#{myBean.commandButton}" render="count2" />
<h:outputText id="count2" value="#{myBean.count}" />
</h:form>
The click on this button correctly executes myBean.commandButton but then produces the error described below and does a "refresh" of the page.
Primefaces
<h:form>
<p:commandButton value="Primefaces" action="#{myBean.commandButton}" update="count3" />
<h:outputText id="count3" value="#{myBean.count}" />
</h:form>
The click on this button correctly executes myBean.commandButton and renders the output text with the incremented value.
EDIT 1 :
In order to deploy on Weblogic 12.2.1, I had to force Weblogic to use the given JSF 2.1.6 package through the weblogic-application.xml as mentioned here, such as :
<prefer-application-packages>
<package-name>javax.faces.*</package-name>
<package-name>com.sun.faces.*</package-name>
<package-name>com.bea.faces.*</package-name>
</prefer-application-packages>
<prefer-application-resources>
<resource-name>javax.faces.*</resource-name>
<resource-name>com.sun.faces.*</resource-name>
<resource-name>com.bea.faces.*</resource-name>
<resource-name>META-INF/services/javax.servlet.ServletContainerInitializer</resource-name>
<resource-name>META-INF/services/com.sun.faces.spi.FacesConfigResourceProvider</resource-name>
<resource-name>META-INF/resources/javax.faces/jsf.js</resource-name>
</prefer-application-resources>
I am pretty sure that JSF packages are not conflicting since FacesContext.class.getPackage().getImplementationVersion() returns 2.1.6-SNAPSHOT and the wls-cat tool returns the following conflicted packages list and JSF's packages are not among them.
But I notice that even if I force Weblogic to use META-INF/resources/javax.faces/jsf.js from my JSF package, it actually uses the jsf.js file from Weblogic's JSF package :
Web browser jsf.js
Conflicted packages list :
com.google.common.*
com.sun.mail.*
javax.el.*
javax.mail.*
javax.mail.event.*
javax.mail.internet.*
javax.mail.search.*
javax.mail.util.*
javax.persistence.*
javax.persistence.spi.*
javax.servlet.*
javax.servlet.http.*
javax.servlet.jsp.*
javax.transaction.*
javax.transaction.xa.*
javax.validation.*
javax.validation.bootstrap.*
javax.validation.constraints.*
javax.validation.groups.*
javax.validation.metadata.*
javax.validation.spi.*
net.jcip.annotations.*
net.sf.cglib.*
oracle.core.lmx.*
oracle.core.lvf.*
oracle.jdbc.*
oracle.jdbc.connector.*
oracle.jdbc.driver.*
oracle.jdbc.internal.*
oracle.jdbc.oci.*
oracle.jdbc.oracore.*
oracle.jdbc.pool.*
oracle.jdbc.rowset.*
oracle.jdbc.util.*
oracle.jdbc.xa.*
oracle.jpub.runtime.*
oracle.net.ano.*
oracle.net.jndi.*
oracle.net.ns.*
oracle.net.nt.*
oracle.net.resolver.*
oracle.security.o3logon.*
oracle.sql.*
oracle.sql.converter.*
org.aopalliance.aop.*
org.aopalliance.intercept.*
org.apache.commons.*
org.apache.oro.*
org.apache.xerces.*
org.apache.xmlbeans.*
org.bouncycastle.*
org.bouncycastle.asn1.*
org.bouncycastle.crypto.*
org.bouncycastle.i18n.*
org.bouncycastle.jce.*
org.bouncycastle.math.*
org.bouncycastle.ocsp.*
org.bouncycastle.util.*
org.bouncycastle.x509.*
org.slf4j.*
org.slf4j.helpers.*
org.slf4j.spi.*
org.w3c.dom.*
repackage.*
schemaorg_apache_xmlbeans.system.sXMLCONFIG.*
schemaorg_apache_xmlbeans.system.sXMLLANG.*
schemaorg_apache_xmlbeans.system.sXMLSCHEMA.*
schemaorg_apache_xmlbeans.system.sXMLTOOLS.*
Does anyone have an idea for this problem ?
Thanks in advance.

I finally solved the problem :
The real file sent by the serveur is not META-INF/resources/javax.faces/jsf.js but META-INF/resources/javax.faces/jsf-uncompressed.js.
So the weblogic-application.xml file must have the following configuration :
<prefer-application-packages>
<package-name>javax.faces.*</package-name>
<package-name>com.sun.faces.*</package-name>
</prefer-application-packages>
<prefer-application-resources>
<resource-name>javax.faces.*</resource-name>
<resource-name>com.sun.faces.*</resource-name>
<resource-name>META-INF/services/javax.servlet.ServletContainerInitializer</resource-name>
<resource-name>META-INF/services/com.sun.faces.spi.FacesConfigResourceProvider</resource-name>
<resource-name>META-INF/resources/javax.faces/jsf.js</resource-name>
<resource-name>META-INF/resources/javax.faces/jsf-uncompressed.js</resource-name>
</prefer-application-resources>

Related

Ajax event in pagination with Primefaces dataTable not working

I have a "normal" paging with a dataTable. The first "load" brings in 25 items from the database.
In the ajax "page" event I am bringing the following elements in blocks of 25 items. Everything works perfectly with version 5.1 of Primefaces, but in version 5.2 the onPageChange method is not called, in fact paging does nothing.
If in the ajax event "page" I add process="#this" it does call the bean, but not the specified onPageChange method but a start method marked with the #PostConstruct annotation (in this way the same first 25 items and pagination always shows these items).
<p:panel id="..."
header="..."
style="..."
toggleable="true"
toggleSpeed="200" >
<p:dataTable var="some_var"
id="myDataTable"
widgetVar="pag"
first="#{[bean].first}" <-- bean attribute
value="#{[bean].collectionOfObjects}" <-- loading of the first 25 elements
rows="20"
paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
emptyMessage="..."
lazy="true"
rowIndexVar="rowIndex"
rowStyleClass="#{(rowIndex mod 2) eq 0? '...' : '...'}">
<p:ajax event="page"
listener="#{[bean].onPageChange}"/> <-- load the next 25 items (successively)
<p:ajax event="sort"
listener="#{[bean].orderListing}"/>
<p:column width="..."
headerText="..."
style="..."
sortBy="#{some_var.id}"
id="...">
...
</p:column>
[rest of columns]
</p:dataTable>
</p:panel>
Back (just as an outline):
#PostConstruct
protected void init() {
...
this.collectionOfObjects = new GenericLazyModel<CollectionOfObjects>(...);
}
//Method not called by ajax.
public void onPageChange(PageEvent event) {
//Next 25 items
this.collectionOfObjects = new GenericLazyModel<CollectionOfObjects>(...);
}
Versions: primefaces 5.2, jsf-api 2.2.2, jsf-impl 2.2.2 (updating these last two will be very expensive).
In this post there are several possibilities, but I have not managed to solve the error after reading everything carefully.
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
Thank you very much to all!
Finally, after several tests, I have updated the version of PF to 5.3 and it has worked. The error when updating to this version 5.3 was not from the application itself, it was from the primefaces-extensions library that had to be updated to v4.0.0 (at least). If anyone has a problem updating the PF library, check the version of primefaces-extensions as well.

When use ajax inside h:commandLink, FacesMessage is not displaying

In jsf. i'm using h:commandLink for adding objects in list. without selecting mandatory fields objects not added in list and showing warning message.its working fine when not using ajax 'render' inside the h:commandLink.
later i decide, i don't want to load my page. so i added ajax inside h:commandLink. but warning message not showing.Please help to fix this problem.
With ajax working:
<h:commandLink value="ADD" action="#{uomGroupBean.goToAddItem}" class="btn-secondary">
<f:ajax render="ITEM_TABLE"></f:ajax>
</h:commandLink>
Without ajax working:
<h:commandLink value="ADD" action="#{uomGroupBean.goToAddItem}" class="btn-secondary"/>
Method for adding:
public String goToAddItem(){
System.out.println("calling......");
if(uomGroup.getBaseUOM()==null){
Util.addWarn("Please select Base UOM");
return null;
}
if(uomGroup.getUomGroupItems()==null || uomGroup.getUomGroupItems().size()==0){
uomGroup.setUomGroupItems(new ArrayList<UomGroupItem>());
}
uomGroup.getUomGroupItems().add(new UomGroupItem());
return "Called";
}
Thanks in advance.

Primefaces Ajax updated form does not trigger commandButton action

I have a problem with a form not triggering its commandButton action method.
When I submit the form without prior update (not selecting any node in the tree), the method triggers just fine.
As soon as the form is Ajax-updated, the commandButton won't call its action anymore.
Here is the JSF code:
<p:layoutUnit position="center">
<p:tree orientation="horizontal" value="#{flightTypeController.tree}" var="node"
selectionMode="single" selection="#{flightTypeController.selectedNode}">
<p:ajax event="select" listener="#{flightTypeController.onNodeSelect}" update=":typesTree"/>
<p:treeNode>
<h:outputText value="#{node.name}"/>
</p:treeNode>
</p:tree>
<h:form id="typesTree">
<p:inputText disabled="true" id="outputParent" value="#{flightTypeController.selectedOne.name}"/>
<p:inputText id="outputName" value="#{flightTypeController.current.name}"/>
<p:commandButton ajax="false" icon="ui-icon-disk" value="#{bundle.general_create}" action="#{flightTypeController.create()}"/>
</h:form>
</p:layoutUnit>
And the java listener:
public void onNodeSelect(final NodeSelectEvent event) {
final Object res = event.getTreeNode().getData();
if (res instanceof FlightType) {
selectedOne = (FlightType) res;
} else {
selectedOne = null;
}
}
I already check BalusC's bible and JS Fix but without success.
I've seen similar behaviours quite often (and had to find workarounds) so I might have misunderstood something fundamental.
Oh, yes, I checked multiple times : no nested forms in my code.
The JS fix which you found is hooking on jsf.ajax.addOnEvent which is only triggered by <f:ajax>, not by PrimeFaces components which use jQuery under the covers.
To cover PrimeFaces ajax requests as well, grab the current version of the JS fix (I have recently updated that post) and add the following to apply this fix on jQuery ajax requests as well:
$(document).ajaxComplete(function(event, xhr, options) {
if (typeof xhr.responseXML != 'undefined') { // It's undefined when plain $.ajax(), $.get(), etc is used instead of PrimeFaces ajax.
fixViewState(xhr.responseXML);
}
}
Disclaimer: I haven't tried your specific use case. But, theoretically, it should solve your problem.

JSF AJax - How to render the output from an URL

I am trying to render the output of an URL in the same page, using JSF / Ajax (a4j) and so far I am having no luck. BTW, I am using RichFaces 4.0. For example, if the User clicks a row in a Table (or just a button), I like to show a web page right below the Table, that is relevant to the row clicked. Is there a way I can get the relevant URL using a Backing Bean and invoke that URL using A4J Tags? I searched for such tags or sample code and so far I could not find any.
Thanks for your help.
Embedding the result of an external URL in your webpage can only neatly be done with help of a HTML <iframe> element.
So, this should do:
<h:form>
<h:dataTable value="#{bean.websites}" var="website">
<h:column>#{website.name}</h:column>
<h:column>
<h:commandButton value="show" action="#{bean.setWebsite(website)}">
<f:ajax render=":website" />
</h:commandButton>
</h:column>
</h:dataTable>
</h:form>
<h:panelGroup id="website">
<iframe src="#{bean.website.url}"></iframe>
</h:panelGroup>
with
#ManagedBean
#ViewScoped
public class Bean {
private List<Website> websites; // +getter
private Website website; // +getter+setter
// ...
}

Trouble with Primefaces 3.0.M2 SelectOneMenu Ajax behavior

I am having trouble with implementing two SelectOneMenu controls, where data in the second one depends on the selection made in the first. This example on the primeFaces showcase is almost the same as what I want to implement: http://www.primefaces.org/showcase-labs/ui/pprSelect.jsf
except that I have to get the data from a database.
The above example is working correctly in the same project. I am using NetBeans 7.0 with GlassFish 3.1 and PrimeFaces 3.0.M2, the latest drop (20th June 2011).
The source code of the JSF page and the managed bean is attached.
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head><title>Facelet Title</title></h:head>
<h:body>
<p:log />
<center>
<h:form>
<h:outputText value="State: "/>
<p:selectOneMenu id="selectState" value="#{stateCityBean.selectedStateArray}">
<f:selectItem itemLabel="Select Any" itemValue="Empty String"/>
<p:ajax update="selectCity" listener="#{stateCityBean.updateCityMap}"/>
<f:selectItems value="#{stateCityBean.stateMap}" />
</p:selectOneMenu>
<p></p>
<h:outputText value="City: "/>
<p:selectOneMenu id="selectCity" value="#{stateCityBean.selectedCityArray}">
<f:selectItem itemLabel="Select Any" itemValue="Empty String"/>
<f:selectItems value="#{stateCityBean.cityMap}"/>
</p:selectOneMenu>
</h:form>
</center>
</h:body>
StateCityBean.java
package com.xyz.mbeans;
import com.iwizability.priceinfo.dao.*;
import com.iwizability.priceinfo.pojo.*;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.context.Flash;
import javax.faces.event.ValueChangeEvent;
#ManagedBean
#SessionScoped
public class StateCityBean {
private String selectedStateArray;
private Map<String, State> StateMap;
private Map<String, City> CityMap;
private String selectedCityArray;
public StateCityBean() {
System.out.println("Inside.............. ");
StateMap = new LinkedHashMap<String, State>();
CityMap = new LinkedHashMap<String, City>();
}
public String getSelectedStateArray() {return selectedStateArray;}
public void setSelectedStateArray(String selectedStateArray) {this.selectedStateArray = selectedStateArray;}
public Map<String, State> getStateMap() {
StateDaoImpl stateObj = new StateDaoImpl();
StateMap = stateObj.getState();
return StateMap;
}
public void setStateMap(Map<String, State> stateArray) {this.StateMap = stateArray;}
public String getSelectedCityArray() {return selectedCityArray;}
public void setSelectedCityArray(String selectedCityArray) {this.selectedCityArray = selectedCityArray;}
public Map<String, City> getCityMap() {
CityDaoImpl cityObj = new CityDaoImpl();
int stateId = 0;
if (selectedStateArray != null && !selectedStateArray.equals("")) {
stateId = StateMap.get(selectedStateArray).getId();
}
CityMap = cityObj.getCity(stateId);
return CityMap;
}
public void setCityMap(Map<String, City> CityArray) {
this.CityMap = CityArray;
}
public void updateCityMap() {
CityDaoImpl cityObj = new CityDaoImpl();
int stateId = 0;
if (selectedStateArray != null && !selectedStateArray.equals("")) {
stateId = StateMap.get(selectedStateArray).getId();
this.CityMap = cityObj.getCity(stateId);
}
}
}
On debugging, I can see that the updateCityMap method is invoked but the SelectedStateArray variable is null. Even force changing the value of bound CityMap variable does not update the selectCity drop down.
As you would have guessed, I am new to JSF, but the problem is compounded by the fact that I am using a still in development version of the tag library...
I created a demo for the exact same situation you describe in your project. I have a state and city <p:selectOneMenu/> elements on my page. You select a state, and the cities update. If a different state is selected, the city is erased since it may not exist in the state.
The difference is that I use <p:ajax event="change" update="cities, cs"/> to update the elements, and an actionListener to update the city if the state is different.
<p:selectOneMenu id="states" value="#{dataBean.selectedState}"
valueChangeListener="#{dataBean.stateChangeListener(event)}"
style="width: 150px;">
<f:selectItem itemLabel="" itemValue=""/>
<f:selectItems value="#{dataBean.states}"/>
<p:ajax event="change" update="cities, cs"/>
</p:selectOneMenu>
<h:outputLabel value="City:" for="cities"/>
<p:selectOneMenu id="cities"
value="#{dataBean.selectedCity}"
style="width: 150px;">
<f:selectItem itemLabel="" itemValue=""/>
<f:selectItems value="#{dataBean.cities}"/>
<p:ajax event="change" update="cs" />
</p:selectOneMenu>
The whole project and demo code can be found on my blog. I saw this post and decided to post my project. [blog]: http://javaevangelist.blogspot.com/2012/07/primefaces-ajax-enabled.html
Primefaces is trying something diffent. I dont know why. First of all you must know these releases are not stable.
When you analys code with firebug you will shove this.
Lets assume two combo who has ids countries and cities
when you changed the first combo cities update correcty but cities combo' id change to cities_input they add _input prefix. When I analys primefaces source code. Thereare codes something like traverse tree if visited change id by adding _input or _panel. So if you change the combo in second time. Everything work perfect except you said update cities but there is no component who has id cities becouse it has new id cities_input. So your ajax does not work correctly. But they correct this bug in 3.0m4 or after releases.
This is the problem. Another example of this problem it is bug someone open jira for this.
İf you are using login with spring security j_username, j_password change to j_username_input j_password_input. So this breaks the standart and code does not work in second ajax requests.
Hope this helps..
pay attention to lionhearts words. Primefaces namespaces changed in 3.m4 in pages use this.
xmlns:p="http://primefaces.org/ui"
I did a state -> city select in my jsf project the same way you did. The only differences I found are:
my p:ajax has a change event: <p:ajax event="change" update="city" listener="#{contatoMB.filterCities}" />.
my p:ajax comes last after the f:selectItems but this shouldn't be the problem.
my f:selectItems list in the city select is List<javax.faces.model.SelectItem> and not a Map<String, City>, have you tried using SelectItems instead of your map?
my form has an id and prependId false <h:form id="contact-form" prependId="false">, again, this shouldn't be the problem.
my h:selectOneMenu is inside a p:panel, some PrimeFaces components behave in a strange way when inside or outside some other components.
If none of this works maybe the problem is the PrimeFaces version you're using. My PrimeFaces version is 2.2.1.
I use PrimeFaces 3.0.M4 with namespaces:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
It seems to work fine.
Maybe its the primefaces version but your update method in your bean looks pretty complicated.
Why not retrieve the Object of the selection from the ajax event?, this way you don't need to define that variable.
public void update(AjaxBehaviorEvent event)
{
Object selectOneMenuObject = ((UIOutput)event.getSource()).getValue();
//String selectedStateArray = (String)((UIOutput)event...
//update temporary collection of second SelectOneMenu
}
Don't know if that will help you, but thats just the way I do it.
you should just add
event="change"
to p:ajax

Resources