JAVA 7 JSF inputFile ERROR javax.servlet.ServletException: UT010016: Not a multi part request - java-7

First of all a greeting and thanks in advance.
The reason for my creating this thread is because of an error that it generates when trying to load a file with
what I want is to capture a file, regardless of its extension, send it to the controller and then convert it to bytearray to store it in a postgre sql database.
<div class="row">
<div class=" text-mini col-lg-12 col-md-6 col-xs-6">
<h:form enctype="multipart/form-data">
<h:panelGrid columns="2">
<h:outputLabel value="Cargar archivo" for="fileUpload" />
<h:inputFile value="#{fileUploadFormBean.fileUpload}" id="fileUpload" />
<h:commandButton value="Cargar"/>
</h:panelGrid>
</h:form>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<h:panelGrid rendered="#{not empty(fileUploadFormBean.fileUpload)}" columns="2" >
<h:outputText value="fileName:" />
<h:outputText value="#{fileUploadFormBean.fileUpload.submittedFileName}" />
<h:outputText value="contentType:" />
<h:outputText value="#{fileUploadFormBean.fileUpload.contentType}" />
<h:outputText value="size:" />
<h:outputText value="#{fileUploadFormBean.fileUpload.size}" />
</h:panelGrid>
</div>
</div>
package com.esmero.cl.mvno.ticketin.controller;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.servlet.http.Part;
#ManagedBean(name = "filecontroller")
#ViewScoped
public class UpLoadFileController implements Serializable{
private static final long serialVersionUID = 1L;
private Part fileUpload;
/**
* Creates a new instance of FileUploadFormBean
*/
public UpLoadFileController() {
}
public Part getFileUpload() {
return fileUpload;
}
public void setFileUpload(Part fileUpload) {
this.fileUpload = fileUpload;
}
}
enter image description here
enter image description here

Related

tabs in a tabView not updated after wildfly migration with primefaces

I'm using primefaces 3.5 JBoss 7.1.1. I'm migrating my app to Wildfly 9.0.2.
The following code used to work with JBoss but no longer with WildFly.
<p:tabView id="tabView" dynamic="true" cache="false" style="width:1120px">
<f:event listener="#{ucoController.loadUcoConfiguration}" type="preRenderView" />
<p:tab id="Activation" title="SOMF Activation">
<h:panelGrid id="ActivationPG" columns="1" cellpadding="10" border="0">
<h:form id="user" class="sgdsForm clear">
<script type="text/javascript">
function startAjaxStatus(){
document.getElementById("tabView:user:image").style.display='block';
document.getElementById("tabView:user:shutDown").style.display='block';
}
</script>
<ol>
<li>
<label for="activate" class="label">SOMF Activation</label>
<p:selectBooleanCheckbox value="#{configurationBean.SOMFActivated}" />
</li>
<li>
<br/>
<h:outputText value="#{configurationBean.SOMFActivationMessage}" style="float:left; text-align:left;margin-leftt:7px;color:#0F5795;font-weight:bold;font-size:0.9em;line-height:23px;"/>
</li>
<li>
<br/>
<p:commandButton ajax="false" global="#{configurationBean.SOMFActivated}" onclick="startAjaxStatus()" value="Update" actionListener="#{ucoController.updateUco}" id="updateActivation" icon="ui-icon-disk" update=":tabView:user,:tabView:ScreeningForm>
</p:commandButton>
</li>
</ol>
<h:panelGrid columns="2" border="0" >
<h:outputText value="Update in progress..." id="shutDown" style="color:#0F5795;font-weight:bold;font-size:0.9em;line-height:23px;display:none;"/>
<p:graphicImage value="resources/img/load.gif" id="image" style="display:none;"/>
</h:panelGrid>
</h:form>
</h:panelGrid>
</p:tab>
<p:tab id="Screening" title="Screening" rendered="#{ucoController.disableConfiguration}">
<h:panelGrid id="ScreeningPG" columns="1" cellpadding="10" border="0">
<h:form id="ScreeningForm" class="sgdsForm clear" >
<ol>
<li>
<label for="analysis" class="label required">Think Time (ms)</label>
<h:inputText id="thinkTime" value="#{configurationBean.screeningThinktime}" maxlength="5" readonly="#{configurationBean.SOMFActivated}">
<f:validator validatorId="screeningTimeValidator" />
<f:attribute name="autoScreening" value="#{configurationBean.automaticScreening}" />
</h:inputText>
</li>
<li>
<label for="activate" class="label">Automatic Screening</label>
<p:selectBooleanCheckbox value="#{configurationBean.automaticScreening}" readonly="#{configurationBean.SOMFActivated}" disabled="#{configurationBean.SOMFActivated}"/>
</li>
<li>
<br/>
<p:commandButton disabled="#{configurationBean.SOMFActivated}" oncomplete="handleComplete(xhr, status, args)" value="Update" actionListener="#{ucoController.updateUco}" id="updateScreening" icon="ui-icon-disk" process="#this,ScreeningForm" update=":tabView:ScreeningPG"/>
</li>
</ol>
</h:form>
</h:panelGrid>
</p:tab>
</p:tabView>
And my backing bean :
#ManagedBean(name = "ucoController", eager = true)
#SessionScoped
public class UcoController implements Serializable {
public final ConfigurationBean loadConfiguration() {
// load configuration
}
public final void updateUco(ActionEvent event) {
// update configuration
}
}
I wonder why the updateUco method is not fired when submiting the form. In consequence my form seems to not be submitted! The model doesn't change.
Is there anything wrong with mojarra version or primefaces?
I went through this exhaustive answer for what to appear the same problem. But none of the point described fit for my case !
Please upgrade primefaces to version 4.0 in order to support JSF version 2.2 which is supported in Wildfly 9.0.2.

Java Beans and Ajax - How to return a just a String

I'm working with Ajax, and I'm trying to get a response from a bean method (a String that has a message).
This is the code of my Bean:
//... Some Imports ...//
#ManagedBean(name = "loginBB")
#RequestScoped
public class LoginBean {
private User standard;
#ManagedProperty(value = "#{sessionBB}")
private SessionBean session;
// ... Other stuff ... //
public String logIn() {
return "Yes, you did it";
}
}
And my form look like this:
<h:form id="form" prependId="false" action="#{loginBB.logIn}">
<h:inputHidden id="viaAjax"> </h:inputHidden>
<p:messages id="messages" autoUpdate="true" closable="true" />
<div class="form-group">
<h:outputText value="Mail:" />
<h:inputText value="#{loginBB.user.mail}" required="true"
requiredMessage="Put your email" id="user" styleClass="form-control"/>
</div>
<div class="clear"></div>
<div class="form-group">
<h:outputText value="Pass:" />
<h:inputSecret styleClass="form-control" required="true"
value="#{loginBB.user.password}"
requiredMessage="You must enter a password" />
</div>
<div class="clear"></div>
<h:commandButton styleClass="btn btn-primary" value="logIn"/>
</h:form >
For doing the ajax I didn't use the <f:ajax> tag because is very limitated, so I make my own js code:
$(document.body).on('submit',function(e) {
e.preventDefault();
$.post(url, function(data) {
console.log(data);
})
});
When I check the log, it returns the whole page in the data var!! Even when I'm returning a String in the bean. I looked at the method of the request, and it's a POST, so that's ok.
I just wanted to recieve the string saying "Yes, you did it"
What am I doing wrong?
thanks!

capture selected text from inputTextArea primefaces jsf

I want to capture selected text from inputTextArea on ajax dblclick or select event.How can I do this ?
The code below selects everything in the text area (which I don't want). Thank you very much.
<h:form id="form">
<p:panel header="Select Text">
<h:panelGrid columns="3" cellpadding="5">
<h:outputText value="Text: " />
<p:inputTextarea id="textarea"
value="#{selectedTextBean.selectedText}">
<p:ajax event="select" update="selectedText" />
</p:inputTextarea>
<h:outputText id="selectedText"
value="#{selectedTextBean.selectedText}" />
</h:panelGrid>
</p:panel>
</h:form>
Here is SelectedTextBean
#ManagedBean
#ViewScoped
public class SelectedTextBean {
public SelectedTextBean() {
}
private String selectedText;
public String getSelectedText() {
return selectedText;
}
public void setSelectedText(String selectedText) {
this.selectedText = selectedText;
}
}
You can use this plugin jquery-textrange.
xhtml
<p:inputTextarea onselect="setSelectedText()" />
<p:remoteCommand name="setSelectedTextCommand"
actionListener="#{mainBean.setSelectedText()}"
update="currentSelectedText" />
Selected Text is:
<h:outputText value="#{mainBean.selectedTextInArea}"
id="currentSelectedText" />
<h:outputScript library="js" name="jquery-textrange.js" />
<script>
function setSelectedText() {
var range = $('.ui-inputtextarea').textrange();// general selector
setSelectedTextCommand([{name: 'selectedText', value: range.text}]);
}
</script>
Bean
private String selectedTextInArea;
public void setSelectedText() {
FacesContext context = FacesContext.getCurrentInstance();
Map map = context.getExternalContext().getRequestParameterMap();
selectedTextInArea = (String) map.get("selectedText");
}
public String getSelectedTextInArea() {
return selectedTextInArea;
}
public void setSelectedTextInArea(String selectedTextInArea) {
this.selectedTextInArea = selectedTextInArea;
}
And Here's a live demo on Primefaces TextArea Selection, and on github.
You can do that sending a parameter to a remote command as follows:
The View
<h:form id="form">
<p:panel header="Select Text">
<h:panelGrid columns="3" cellpadding="5">
<h:outputText value="Text: " />
<h:panelGroup>
<p:inputTextarea id="textarea"
value="#{selectedTextBean.selectedText}" onselect="processSelection();" />
<p:remoteCommand name="sendSelection" actionListener="#{selectedTextBean.onSelect}" update="selectedText" process="#this" />
</h:panelGroup>
<h:outputText id="selectedText"
value="#{selectedTextBean.selectedText}" />
</h:panelGrid>
</p:panel>
</h:form>
<script>
function processSelection() {
var selectedText = (!!document.getSelection) ? document.getSelection() :
(!!window.getSelection) ? window.getSelection() :
document.selection.createRange().text;
sendSelection([{name: 'selectedText', value: selectedText}]);
}
</script>
Note that the text selection changes depending on the browser.
The Bean
import java.io.Serializable;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
#ManagedBean
#ViewScoped
public class SelectedTextBean implements Serializable {
public SelectedTextBean() {
}
private String selectedText;
public void onSelect() {
FacesContext context = FacesContext.getCurrentInstance();
Map map = context.getExternalContext().getRequestParameterMap();
selectedText = (String) map.get("selectedText");
}
public String getSelectedText() {
return selectedText;
}
public void setSelectedText(String selectedText) {
this.selectedText = selectedText;
}
}

primefaces dialog disappears when commandButton is submitted

I have a proble with dialog, here is my add.xhtml :
when I click "Envoyer demande" I'm displaying a message of confirmation "Demande d'inscription envoyée" in the dialog but dialog disappears after clicking button "Envoyer demande" .
here is add.xhtm :
<h:form>
<h:commandLink value="Créer un compte" onclick="dlg3.show();return false;"/>
</h:form>
<p:dialog id="modalDialoog" widgetVar="dlg3" draggable="false" resizable="false"
dynamic="true" header="Inscription">
<center>
<p:panel id="xyzBody">
<h:form id="inscri-f">
<h:panelGrid id="loginPan" columns="2" bgcolor="White">
<h:outputText value="Nom d'utilisateur :" />
<p:inputText id="username" value="#{demandeBean.login}"></p:inputText>
<h:outputText value="Mot de passe :" />
<p:password id="pwd" value="#{demandeBean.pwd}"/>
<h:commandButton value="Envoyer demande" update=":inscri-f:cr"
actionListener="#{demandeBean.envoi_dde}"></h:commandButton>
<h:commandButton value="Retour" action="page1?faces-redirect=true"></h:commandButton>
<p:outputPanel id="cr">
<h:outputText rendered="#{demandeBean.saved}" value="#{demandeBean.message}"/>
</p:outputPanel>
</h:panelGrid>
</h:form>
</p:panel>
</center>
</p:dialog>
my addBean.java :
#ViewScoped
public class DemandeBean implements Serializable{
private static final long serialVersionUID = 1L;
DdeDAO ndao = new DdeDaoImpl();
private String login;
private String pwd;
private String message = "";
private boolean saved = false;
//getters and setters of all attributes
public void envoi_dde(){
Demande d = new Demande();
d.setNom_ut(this.login);
d.setPwd(this.pwd);
ndao.nouvelle_dde(d);
saved = true;
this.setMessage("Demande d'inscription envoyée");
}
I want dialog not to disappear after clicking button "Envoyer demande" .
1) change the h:commandButton to p:commandButton
2) set the ajax attribute of p:commandButton to true
this must work perfectly

f:ajax does not update ui:repeat

My JSF page is like this, The <f:ajax> part does now work.
<h:selectOneListbox value="#{category.categoryId}">
<f:selectItems value="#{category.allSubCategories}" var="c" itemLabel="#{c.title}" itemValue="#{c.categoryId}" />
<f:ajax execute="#form" render="projects" />
</h:selectOneListbox>
<h:panelGroup id="projects">
<ul>
<ui:repeat items="#{category.allItems}" var="o" id="itemTable">
<li><h:graphicImage value="#{o.imageUrl}" id="itemImage" /></li>
<li><h:outputText value="#{o.title}" /></li>
<li><label>Price: $ </label><h:outputText value="#{o.price}" /></li>
</ui:repeat>
</ul>
</h:panelGroup>
My bean is:
#ManagedBean(name = "category")
#SessionScoped
public class CategoryServiceBean extends BaseService implements Serializable {
private static final long serialVersionUID = -12082902292711980L;
private Integer categoryId;
private Integer parentCategoryId;
private Integer locationId;
#ManagedProperty(value="#{categorySupport}")
private CategorySupport categorySupport;
public List<RestCategory> getAllSubCategories() {
return getCategorySupport().getCategoriesByParent(locationId, parentCategoryId);
}
public List<RestItem> getAllItems() {
return response = getCategorySupport().getCategoryItems( locationId, categoryId);
}
// ...
}
My problem is that the <f:ajax execute="#form" render="projects" /> does not populate values to <h:panelGroup id="projects">. How is this caused and how can I solve it? If I use <h:dataTable> instead of <ui:repeat>, then it works fine.
<ui:repeat items="#{category.allItems}" var="o" id="itemTable">
The items attribute doesn't exist in <ui:repeat>. You're apparently confusing it with <c:forEach>. Use the value attribute.
<ui:repeat value="#{category.allItems}" var="o" id="itemTable">

Resources