UPD: this error is caused by installing PrimeFaces 4.0.
I have a problem with multipart/form-data and AJAX in JSF 2.2.4 (Glassfish 4.0.0). When I type something, a strange iframe is shown with id JSFFrameId that contains AJAX's responce. Something like this:
<iframe src="about:blank" id="JSFFrameId" name="JSFFrameId">
<partial-response id="j_id1"><changes><update id="j_id1:javax.faces.ViewState:0"><![CDATA[1204950170773864689:-3204770436768457110]]></update></changes></partial-response>
</iframe>
But the value is set. What's wrong? Is it a bug?
JSF form:
<h:form enctype="multipart/form-data">
<h:outputText value="#{foo.string}" id="asd" />
<h:inputText value="#{foo.string}">
<f:ajax event="change" render="asd" />
</h:inputText>
</h:form>
Bean:
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
#ManagedBean(name = "foo")
#RequestScoped
public class SomeBean {
private String string;
public String getString() {
return string;
}
public void setString(String string) {
this.string = string;
}
}
I think it could be this bug: JSF jira
Related
I use JSF with PrimeFaces framework
I have a <ui-repeat> containing <p:fieldset>, when I filter <p:fieldset> with an AJAX query, the <ui-repeat> disappears from the page.
Here is my code :
<h:form id="myForm1">
<p:panelGrid id="pnlg">
<ui:repeat var="state" value="#{myBean.listState}" varStatus="status">
<p:fieldset id="fieldsetState">
<p:dataGrid id="dataGridState" value="#{myBean.state}">
<p:panel id="pnl">
// some code...
</p:panel>
</p:dataGrid>
</p:fieldset>
</ui:repeat>
</p:panelGrid>
</h:form>
<h:form id="myForm2">
<p:commandButton value="Filter">
// When I run this AJAX query, it is supposed to update 'myForm'. Instead, 'pnlg' disappears
<p:ajax listener="#{ManageState.filterState}" update="myForm1" />
</p:commandButton>
</h:form>
When I run this AJAX query, it is supposed to update 'myForm'. Instead, 'pnlg' disappears. I think it is because of <ui:repeat>.
Here is my backing Bean :
#ManagedBean
#ViewScoped
public class ManageState extends AbstractManagedBean implements Serializable {
public void filterState() {
// Filter the list...
}
}
#ManagedBean
#SessionScoped
public class myBean implements Serializable {
private List<sortedBean> listState;
// getter, setter...
}
I solved the problem, merged the two forms and it works. But I do not know exactly why he behaves this way.
I have a CDI ViewScoped bean and a JSF page. After a couple of AJAX requests the bean somehow recreated.
Here is the full code of the application:
index.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
Hello from Facelets
<h:form>
<h:inputText value="#{questionBean.newTag}"></h:inputText>
<h:commandButton value="Add Tag">
<f:ajax listener="#{questionBean.addTag()}" execute="#form" render="#form"></f:ajax>
</h:commandButton>
<ui:repeat value="#{questionBean.tagsOfQuestion}" var="tag">
<h:outputLabel value="#{tag}"></h:outputLabel>
<h:commandButton value="X">
<f:ajax event="click" listener="#{questionBean.removeTag(tag)}" render="#form" execute="#form"/>
</h:commandButton>
</ui:repeat>
</h:form>
</h:body>
</html>
Here is the backing CDI bean
QuestionBean.java
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
#Named
#ViewScoped
public class QuestionBean {
private String newTag;
private List<String> tagsOfQuestion = new ArrayList<String>();
private Date dateCreated = new Date();
public QuestionBean(){
System.out.println("Date Created : "+dateCreated);
}
public void addTag(){
if(!newTag.isEmpty()){
getTagsOfQuestion().add(newTag);
}
newTag = "";
}
public void removeTag(String tagToRemove){
getTagsOfQuestion().remove(tagToRemove);
}
public String getNewTag() {
return newTag;
}
public void setNewTag(String newTag) {
this.newTag = newTag;
}
public List<String> getTagsOfQuestion() {
return tagsOfQuestion;
}
public void setTagsOfQuestion(List<String> tagsOfQuestion) {
this.tagsOfQuestion = tagsOfQuestion;
}
}
Well I had the same problem when I tried it - Netbeans 8 and JSF 2.2.0 too.
Works for me after I updated Glassfish - grab javax.faces.jar from here - I took the very newest, 2.2.8-02, and replaced the one in glassfish/glassfish/modules.
Don't know what the error was or exactly when it was fixed though.
Hope it works for you too.
i have a not resolveable problem, or at least with my limited knowledge about jsf.
I know there are some good solutions to find on stackoverflow, but i can't figure out my error.
i just want to have some commandlinks like a navigationbar and they should change the content of a pre defined div tag which got an include clause. So i guess my Index could be reinterpreted as a kind of template.
my Index:
<h:panelGroup id="navigation" layout="block">
<h:form>
<h:panelGrid columns="4" columnClasses="colDefault,colDefault,colDefault,colDefault">
<f:ajax render=":include">
<h:commandLink value="entry1" action="#{menuController.setPage('login')}" />
<h:commandLink value="entry2" action="#{menuController.setPage('register')}" />
<h:commandLink value="entry3" action="#{menuController.setPage('welcome')}" />
</f:ajax>
</h:panelGrid>
</h:form>
</h:panelGroup>
<h:panelGroup id="center_content" layout="block" class="center_content" >
<h:panelGroup id="include">
<ui:include src="#{menuController.page}.xhtml" />
</h:panelGroup>
</h:panelGroup>
its just like in this post of BalusC
with a small and pretty simple bean:
#ManagedBean
public class MenuController implements Serializable{
private String page;
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
}
but i got a TagAttributeException #
/index.xhtml #17,92 action="#{menuController.setPage('login')}" Could not Resolve Variable [Overflow]: menuController
i've tryed, but i have no clue what to do.
You need to put the bean in a fixed scope:
#ManagedBean
#ViewScoped
public class MenuController implements Serializable {}
And you need to preinitialize page with a default value:
private String page;
#PostConstruct
public void init() {
page = "login"; // Default value.
}
I am very new to ajax and trying to copy the value of one box to another. Here is my code:
<h:form>
<h:inputText value="#{ajaxBean.name}">
<f:ajax render="otherbox" execute="#this" event="keyup"></f:ajax>
</h:inputText>
<h:inputText id="otherbox" value="#{ajaxBean.name}"></h:inputText>
</h:form>
And the bean
#Named(value = "ajaxBean")
#Dependent
public class AjaxBean {
public AjaxBean() {
}
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
That code does not work. Can anyone help me?
Thanks
Your question is not about Ajax or JSF. It is a JavaScript question.
You can access and modify items with JavaScript.
Add this JavaScript codes between <h:head></h:head>
<script>
function copyField()
{
document.getElementById("field2").value = document.getElementById("field1").value;
}
</script>
And your page:
<h:form id="myform" prependId="false">
<h:inputText id="field1" value="#{myBean.name}" onkeyup="copyField();" />
<h:inputText id="field2" value="#{myBean.name}"></h:inputText>
</h:form>
Take attention to prependId="false" to avoid mixing ids.
See also:
JSF: Why prependId = false in a form?
I think you are mixing up JSF and CDI. #Dependent says that the bean is in the dependent pseudo-scope (which is anyways the default-scope for CDI-beans), so every time you make a request the bean will be reinstanciated and the bean can not hold any state. Look here for an explanation of the scopes and especially for what the dependent scope is used for.
So first of all you have to use some different scope, #RequestScoped should be enough for your task. And as I do not see any use of CDI here, use #ManagedBean instead of #Named - so the default scope for the bean will be the request scope.
Try this:
#ManagedBean
public class AjaxBean {
...
}
1.1, IceFaces 3.0.1 and JSF 2.1 and was trying to work with ace:fileentry. I can't understand why the listener is never called! Even the IDE sends me a warning "pruebaBean.sampleListener is an unknown property".
Here is a short example of what i'm doing. When click the submit button nothing happen.
Can someone help me ?? Could be some kind of bug?
prueba.xhtml:
<?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:ice="http://www.icesoft.com/icefaces/component"
xmlns:ace="http://www.icefaces.org/icefaces/components">
<h:head>
</h:head>
<h:body>
<ice:form id="usuarioForm">
<ice:panelGrid columns="2">
<ace:fileEntry id="fileEntryImage" absolutePath="c:\iTablero\imagenes"
useSessionSubdir="false" useOriginalFilename="false"
fileEntryListener="#{pruebaBean.sampleListener}"/>
<ice:commandButton type="submit" value="Subir archivo"/>
</ice:panelGrid>
<ice:messages/>
</ice:form>
</h:body>
PruebaBean.java:
package com.itablero.backingbeans;
import java.io.Serializable;
import javax.annotation.ManagedBean;
import javax.faces.bean.RequestScoped;
import org.icefaces.ace.component.fileentry.FileEntry;
import org.icefaces.ace.component.fileentry.FileEntryEvent;
import org.springframework.stereotype.Controller;
#ManagedBean
#Controller
#RequestScoped
public class PruebaBean implements Serializable {
public void sampleListener (FileEntryEvent e) {
System.out.println("it work!");
FileEntry fe = (FileEntry) e.getComponent();
//some others operations
}
}
Update 1
Thanks to #fischermatte I found the problem was replace ice:commandButton for h:commandButton. But when I applied this to the original complete form and didn't work. The fileEntryListener method is never called. Can someone see the error here?
Logically the previous example and the code below have the same web.xml, faces-config.xml, etc. Note the button to submit the file is h:commandButton, and there is a ice:commandButton for complete form. I already tried to change this por en h:cb.
Here is the original form (that is display in a popup/modal window) and bean:
usuariosList.xhtml
<ice:panelPopup rendered="#{usuariosBean.showPopup}"
visible="#{usuariosBean.showPopup}"
modal="true"
autoCentre="true">
<f:facet name="header">
<h:panelGroup>
<h:panelGroup style="float: left;">
Usuario
</h:panelGroup>
<h:panelGroup style="float: right;">
<ice:form>
<h:commandButton image="/resources/images/popup-close.png"
alt="Cerrar" title="Cerrar"
style="height: 11px; width: 11px; border: 0;"
action="#{usuariosBean.closePopup}"/>
</ice:form>
</h:panelGroup>
</h:panelGroup>
</f:facet>
<f:facet name="body">
<ice:form id="usuarioForm">
<ice:panelGrid columns="2">
<p>Nombre:</p>
<ice:inputText id="nombre" label="nombre" value="#{usuariosBean.usuario.nombre}" size="40" />
<p>Imagen:</p>
<ice:graphicImage value="#{usuariosBean.usuario.imagen}"/>
<ace:fileEntry id="fileEntryImage" absolutePath="c:\iTablero\imagenes"
useSessionSubdir="false" useOriginalFilename="false"
fileEntryListener="#{usuariosBean.formListener}"/>
<h:commandButton type="submit" value="Subir archivo"/>
</ice:panelGrid>
<ice:messages for="usuarioForm"/>
<ice:commandButton value="Guardar" action="#{usuariosBean.save()}" />
</ice:form>
</f:facet>
</ice:panelPopup>
UsuariosBean.java
package com.itablero.backingbeans;
import com.itablero.excepciones.DAOException;
import com.itablero.modelo.Usuario;
import com.itablero.servicios.AdminService;
import java.io.Serializable;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.icefaces.ace.component.fileentry.FileEntry;
import org.icefaces.ace.component.fileentry.FileEntryEvent;
import org.icefaces.ace.component.fileentry.FileEntryResults;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
#ManagedBean
#Controller
#ViewScoped
public class UsuariosBean implements Serializable {
#Autowired
private AdminBean adminBean;
#Autowired
private AdminService adminService;
private Usuario usuario = new Usuario();
private boolean showPopup;
//getter and setters
public boolean isShowPopup() {
return showPopup;
}
public void setShowPopup(boolean showPopup) {
this.showPopup = showPopup;
}
public void openPopup() {
this.showPopup = true;
}
public void closePopup() {
this.showPopup = false;
this.usuario = new Usuario();
}
public String edit(Usuario usuario) {
this.usuario = usuario;
this.showPopup = true;
return "usuariosList";
}
public String delete(Usuario usuario) {
adminService.delete(usuario);
return "usuariosList";
}
public String save() {
try {
usuario.setTutor(adminBean.getLoggedTutor());
adminService.save(usuario);
} catch (DAOException ex) {
Logger.getLogger(TutoresBean.class.getName()).log(Level.SEVERE, null, ex);
}
usuario = new Usuario();
this.showPopup = false;
return "usuariosList";
}
public void formListener(FileEntryEvent e) {
System.out.println("Entro");
FileEntry fe = (FileEntry)e.getComponent();
FileEntryResults results = fe.getResults();
//other stuff
}
}
Update 2
I think I figured out why is not working, but need some help with the fix. I made the corrections as #fischermatte advice me, but didn't work.
To reach this page with the form, first have to navigate throw a the main page /admin/admin.html, if a look the URL in the browser appears http://localhost:8084/iTablero/admin/admin.html. This page has a menu, one of this menu options bring me to the page with the problematic form. But, because is an AJAX call (if i'm not wrong) the URL in the browser does not change, it keeps the http://localhost:8084/iTablero/admin/admin.html. And the fileEntry never calls the listener.
Now, if I enter the URL by myself http://localhost:8084/iTablero/admin/usuariosList.html, the page is displayed correctly as before, but now THE FILEENTRY WORKS PERFECTLY!!!
I have no idea how to fix this, will have to use redirects? I think is something around AJAX.......help pls! :-D
Update 3
That is the menu, without redirect is not working.
<h:form>
<ice:menuBar orientation="horizontal">
<ice:menuItem value="Tutores" action="tutoresList"/>
<ice:menuItem value="Usuarios" action="usuariosList"/>
<ice:menuItem value="Tableros" action="tablerosList"/>
<ice:menuItem value="Simbolos" action="simbolosList"/>
<ice:menuItem value="Estadisticas" action="estadisticas"/>
<ice:menuItem value="Salir" action="#{adminBean.logout()}"/>
</ice:menuBar>
</h:form>
With action="usuariosList?faces-redirect=true" works fine.
Already test with forward navigation to a basic page form with only a FileEntry and doesn't work too. Again, if I use redirect, works fine. I think is some kind of issue with this component and forward navigation.
You have to use JSF's commandbutton instead of icefaces's: <h:commandButton type="submit" value="Subir archivo"/>. It is a known issue in ICEFaces, see ace:fileEntry wiki.
Update 1
Plus you either remove the rendered attribute in the popup or update the popup when opening it like here:
<h:form>
<h:commandButton value="Show Popup" action="#{usuariosBean.showPopupAction}">
<f:ajax render=":popupPanelGroup"/>
</h:commandButton>
</h:form>
<h:panelGroup id="popupPanelGroup">
<ice:panelPopup visible="#{usuariosBean.showPopup}" rendered="#{usuariosBean.showPopup}" modal="true" autoCentre="true">
...
</ice:panelPopup>
</h:panelGroup>