ajax issue in jsf form: malformedXML: During update - ajax

Please I need your support to resolve this ajax issue.
I'm using Jsf 2.1, CDI Bean, Hibernate.
I have a problem when putting <f:ajax render="#form" /> in my form.
I have a select box, I want to Hide/Show form depending on selectOneMenu value change.
after selecting the value, this issue is displayed as mentioned in the image attached.In addition. how could I resolve it please.
attached images

Related

Ajax listener not working with inputFile

First of all, I'm using JSF 2.2.7 and GlassFish 4 in NetBeans 8.0.
Second, sorry if I left any useful info out. This is my first question in here, so I may forget something. Also, english isn't my first language. Sorry for typos/grammar.
So, here's my problem: I'm uploading files with h:inputFile and I need an ajax listener for it.
After noticing that it wasn't working as I expected, I decided to do some testing with a listener that prints "Test", but it's never fired with h:inputFile. I've tried with h:commandButton and h:commandLink and they both work fine.
For further testing, I created a new project using the same test code and everything works, including the listener in h:inputFile.
What I want to know is why it doesn't work in my main project and why it works in the test project. What am I missing here? And how can I make it work in my main project?
Here are some (but not all, since I lost track) things that I've tried/checked so far, after looking for answers:
There are no nested forms. The said xhtml is in a ui:composition, but even taking that into account, there are no nested forms.
Its form has enctype="multipart/form-data"
I've tried changing the method to uploadTest(AjaxBehaviorEvent event) and the listener to listener="#{submitFormBean.uploadTest}" [without the ()]
I've played with the various event="..." and execute="..." (didn't think it would solve my problem, but, well, I had to try)
The code follows below:
xhtml
<h:form>
<h:commandButton id="btnTest">
<f:ajax listener="#{submitFormBean.uploadTest()}"/>` --> works in both projects`
</h:commandButton>
</h:form>
<h:form>
<h:commandLink id="lnkTest" value="Test">
<f:ajax listener="#{submitFormBean.uploadTest()}"/>` --> works in both projects`
</h:commandLink>
</h:form>
<h:form enctype="multipart/form-data">
<h:inputFile id="fileTest">
<f:ajax listener="#{submitFormBean.uploadTest()}"/>` --> works only in test project`
</h:inputFile>
</h:form>
bean
#ViewScoped
#ManagedBean(name = "submitFormBean")
public class SubmitFormBean{
public SubmitFormBean() {
}
public void uploadTest(){
System.out.println("Test");
}
}
Thanks in advance!
I was about to do what I needed in jQuery, but first I decided to try the following and it solved my problem:
right click project/properties/libraries
in the compile tab, I removed and readded the JSF 2.2.7 .jar
It was already there, but for some reason wasn't working. I still don't know what went wrong, but it's working now.
With multipart/form-data in JSF form, you have to do additional configuration to make it works.
You can refer to other questions:
commandButton/commandLink/ajax action/listener method not invoked or input value not updated
JSF 2.0 File upload
And
How to use PrimeFaces p:fileUpload? Listener method is never invoked or UploadedFile is null

How to get state of SelectBooleanCheckbox in Ajax Listener?

I'm trying to do some action in the ManagedBean based on the state of the checkbox.
Checkbox is here:
<p:selectBooleanCheckbox id="cb">
<p:ajax listener="#{myBB.checkboxChanged}"/>
</p:selectBooleanCheckbox>
The signature of the listener method is this:
public void checkboxChanged(AjaxBehaviorEvent event)
The listener method is called as expected, but I'm not sure how to get the state of the checkbox(if it is selected)
This is false all the time:
((SelectBooleanCheckbox)event.getSource()).isSelected()
Do I need to bind the value of the checkbox? I'd like to avoid that, because the checkboxes are generated from enum in a loop and I don't have any boolean where to bind it(the model is designed in a way that I'm adding/removing the instances of enum to a collection, not setting boolean properties)
I'm running the code on Tomcat 6.0.36 with Primefaces 3.5
JSF implementation is Apache Myfaces 2.1.10
Your code works as expected for me on Mojarra 2.2.1 and PrimeFaces 4.0RC1 as well as Mojarra 2.0.3 and PrimeFaces 3.5. Unfortunately I didn't have 2.1 handy. What version of PrimeFaces are you using? Can you post your complete code?
Lucas was right, everything is fine. The problem is I did not put the button in the form.
After adding <h:form> tag, everything is ok.

Can't populate the right side of RichFaces 4 pickList backed by Spring Webflow managed Beans

I am in the middle of a migration from Richfaces 3.3.3 to Richfaces 4.3.0, which called for a JSF upgrade from 1.2 to 2.1. We are also using Spring Webflow 2.3.2 (upgraded from 2.1.1) for conversation definition. All beans are managed by Spring (no JSF managed beans). Several Richfaces components had to be adjusted for the application to work properly again. The problem I have now concerns the rich:pickList component, which looks like this (I took the showcase example and edited it to depict the problem):
<rich:pickList id="ownPicklist" value="#{listSelectBean.selectedCapitals}"
sourceCaption="Available cities" targetCaption="Selected cities"
listWidth="165px" listHeight="100px">
<a4j:ajax event="change" execute="#this" render="#{mainBean.dynamicRerenderList}" />
<f:selectItems value="#{listSelectBean.capitals}" var="capital"
itemValue="#{capital}" itemLabel="#{capital.name}" />
<f:converter converterId="CapitalsConverter" />
</rich:pickList>
Now unlike the showcase example, our ListSelectBean is a Spring bean and is defined like this:
<bean id="listSelectBean" class="com.xyz.example.bean.ListSelectBean" scope="request" />
The custom converter is registered in the faces-config.xml:
<converter>
<converter-id>CapitalsConverter</converter-id>
<converter-class>com.xyz.converter.CapitalsConverter</converter-class>
</converter>
As you can see we have an ajax event handler attached to the pickList, which dynamically calculates a list of components to be rerendered depending on the selected value(s) from the list. This list also contains the pickList itself, which normally has to be rerendered with much less elements to select from. The ajax response I get contains the full source list, but the target list is empty.
Now to the problem:
When I select an element from the left side it jumps to the right side and immediately back again.
I debugged the issue and learned that all the getters and setters of the listSelectBean are invoked correctly as different JSF phases are run through. The same example with JSF managed, request scoped beans works fine (which is in the Richfaces showcase), also with the ajax rerender on the component itself. I suspect a problem with the bean handling in Spring (Webflow). But I can't pinpoint it. Any help will be highly appreciated.
After long hours of debugging I finally found the solution to the problem. As RichFaces uses a HashSet during the rendering process it is important to have the hashCode() and equals() Methods overridden for complex objects (which is a good idea in general) used in the PickList. Otherwise selected objects won't be marked as selected.

ui:include in richfaces 4 only gets updated on second click

I am new to Richfaces4 and JSF2 and having lots of issues. Same code start to work suddenly and then it breaks. Currently I have a ui:include tag that update the page when the a4j:commandLink is clicked. Using debugging feature of eclipse I can see that the methods are being called and correct value is stored in the bean but page never gets updated until I click on it the second time. It seems the page is updated before the values are set in the backing bean. Following is my code. The same thing was working in MyFaces 2.0.2 before I updated to MyFaces 2.1.3.
<a4j:outputPanel id="pagePanel" layout="block">
<ui:include src="#{panelMenu.currentPage}"></ui:include>
</a4j:outputPanel>
<h:panelGrid>
<p><a4j:commandLink value="View Member" render="pagePanel" execute="pagePanel">
<a4j:param value="/pages/group_member.xhtml" assignTo="#{panelMenu.currentPage}"/>
</a4j:commandLink></p>
<p><a4j:commandLink value="View/Edit Groups" render="pagePanel" execute="pagePanel">
<a4j:param value="/pages/group_detail.xhtml" assignTo="#{panelMenu.currentPage}"/>
</a4j:commandLink></p>
</h:panelGrid>

JSF: Using AJAX push with ICEfaces (ICEpush)

I'm using ICEfaces with ICEpush to push some data to the browser.
However, it does not work like planned: It does no AJAX, it just invokes the action and returns from the action like any other non-AJAX action does.
I'm using the newest ICEfaces and ICEpush versions and Tomahawk 7 and JSF 2.
It works with neither Servlet 2.5 nor Servlet 3.0.
These are the important parts of my bean (view scoped):
public AjaxTest() {
PushRenderer.addCurrentSession(PUSH_GROUP);
}
public void addText() throws InterruptedException {
for(int i = 0; i < 5; i++) {
lines.add("line " + i);
PushRenderer.render(PUSH_GROUP);
Thread.sleep(1000);
}
}
And this is a snippet of my form:
<h:panelGroup>
<h:dataTable id="ajaxTestTable" value="#{ajaxTest.lines}" var="line">
<h:column>
<h:outputText value="#{line}" />
</h:column>
</h:dataTable>
<h:commandButton id="startAjax" value="Start"
action="#{ajaxTest.addText}" />
</h:panelGroup>
Did I miss something? Thanks!
ICEfaces 2.0 is not yet integrated with MyFaces. Have you tried your application with the included Mojarra .jar files?
I'm only familiar with Icefaces 1.8, but it seems to me you're command button isn't ajax enabled. As well you have to use an actionListener instead of an action
You can use either the icefaces command button:
<ice:commandButton id="startAjax" value="Start"
actionListener="#{ajaxTest.addText}"/>
or the JSF 2 ajax tags:
<h:commandButton id="startAjax" value="Start">
<f:ajax listener="#{ajaxTest.addText}"/>
</h:commandButton>
Do you have some development tool that can validate the code? At least on Vaadin version of ICEPush you could not trust to their examples. On their official demo there was deprecated code and on their chat they gave code where imports were from another planet with the correct ones.
My Eclipse told that many imports were wrong and code had deprecated marks on some functions. These guys there develop so fast that their documents are permanently out of date. So, read carefully what your tool says about the code!
I also have the problem with integration of IceFaces (to use push) with the app which already use Richfaces. But it is possible to integrate the IcePush directly with almost any java-web-application (with Servlet Api).
You can see more details on http://achorniy.wordpress.com/2012/02/29/icepush-integration-to-web-application/
The idea is to use javascript-api(or jQuery-api) provided by IcePush. So, your page with javascript-api register itself as a listener to push notifications and in the callback you can call whatever javascript functions to update your page. In Richfaces example you may use ajaxUpdateFunction() which is actually backed by <a4j:jsFunction name="ajaxUpdateFunction" action="#{myBean.update} reRender="updatedComponent(s)" ajaxSingle="true"/> or perform ajax-request with jQuery. In your case (JSF-2.0) I think you can call jsf.ajax.request(this, event, {render:'ajaxTestTable'}) to update what you want (examples http://andyschwartz.wordpress.com/2009/07/31/whats-new-in-jsf-2/)
all you need to do on server-side - is to register IcePush servlet and initialize icePush connection on the client side with javascript api.

Resources