I cannot make the fileUpload option working. I keep having the message file is null.
Could you tell me how to fix this ?
here is my xhtml:
<h:form enctype="multipart/form-data">
<p:fileUpload mode="simple" id="recupereFile" value="#{FileUploadView.uploadedFile}" />
<p:commandButton value="Upload" action="#{FileUploadView.upload}" ajax="false" />
</h:form>
here is my java:
#ManagedBean(name="FileUploadView")
public class FileUploadView {
private UploadedFile file;
public UploadedFile getFile() {
System.out.println(file);
return file;
}
public void setFile(UploadedFile file) {
this.file = file;
}
public void upload() {
UploadedFile file = getFile();
System.out.println("hello");
System.out.println(file);
if(file != null) {
FacesMessage message = new FacesMessage("Succesful", file.getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, message);
System.out.println(message);
}
}
}
file is always null !
my web.xml
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>
org.primefaces.webapp.filter.FileUploadFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
I have these jars:
commons-fileupload-1.3.1.jar
commons-io_2.5.jar
Thansk for your help.
We had a similar issue a few month ago here. The colleague who did this left our company, so I can't ask him. Anyway this is how the relevant parts of my web.xml look like.
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<url-pattern>*.jsf</url-pattern>
</filter-mapping>
Also we have this context-param:
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>auto</param-value>
</context-param>
The value attribute of p:fileUpload should correspond to the name of the UploadedFile in the bean.
It should work if you replace FileUploadView.uploadedFile with FileUploadView.file in the p:fileUpload:
<p:fileUpload mode="simple" id="recupereFile" value="#{FileUploadView.file}" />
Related
I have an issue after uploading an image. the image is not refreshed upon upload. The bean is session scoped, and after upload I need to refresh manually the page to see the new image. How can I refresh the graphical Image automatically after image/file upload? thank you
The following code could successfully upload the image but the previous image still visible and the new image could be visible only after refresh:
Platforms:
jsf 2.2
,tomcat 7.37
, primefaces 5.0
<h:form id="form" enctype="multipart/form-data">
<p:growl id="growl_1" showDetail="true"/>
<p:panelGrid id="pg_photo"
style="margin-bottom:10px;
width: 50em"
styleClass="panelGridCenter">
<f:facet name="header">
<p:row>
<p:column>
<p:graphicImage
id="gi_etud"
width="150"
height="120"
value="#{etudiantProfilView.imageEtudAsStream}"/>
</p:column>
<p:column>
<p:fileUpload id="fu_photo"
value="#{etudiantProfilView.imageEtudUF}"
mode="advanced"
dragDropSupport="true"
fileLimit="10"
sizeLimit="100000"
allowTypes="/(\.|\/)(gif|jpg|jpeg|gif|png|PNG|GIF|JPG|JPEG)$/"
auto="true"
update="growl_1 gi_etud"
fileUploadListener="#{etudiantProfilView.imageUploadListener}"
>
</p:fileUpload>
</p:column>
</p:row>
</f:facet>
</p:panelGrid>
</h:form>
The session bean:
#ManagedBean
#SessionScoped
public class EtudiantProfilView implements Serializable {
//some stuff
public void imageUploadListener(FileUploadEvent event) throws IOException {
//save the image to the hard disk
}
//some stuff
}
I have resolved the refresh issue by adding "reload" action to "oncomplete" attribute for uploadFile component:
<p:fileUpload id="fu_photo" value="#{etudiantProfilView.imageEtudUF}"
mode="advanced"
dragDropSupport="true"
fileLimit="10"
sizeLimit="200000"
allowTypes="/(\.|\/)(gif|jpg|jpeg|gif|png|PNG|GIF|JPG|JPEG)$/"
auto="true"
update="#form"
oncomplete="window.location.reload();"
fileUploadListener="#{etudiantProfilView.imageUploadListener}"
>
</p:fileUpload>
I'm developing a web application with PrimeFaces 4.0.RC1 and i have problem with file upload,
exactly with the fileUploadListener; this listener doesn't invoke the method "handleFileUpload".
When i try to invoke this method with commandButton: the action in the commandButton work fine;
this is a pert of my web.xml:
<!-- Filter for the JSF uploder -->
<context-param>
<param-name>primefaces.UPLOADER</param-name>
<param-value>commons</param-value>
</context-param>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>facesServlet</servlet-name>
</filter-mapping>
this my xhtml page:
<h:form enctype="multipart/form-data">
<p:growl id="kpiUploadNote" showDetail="true" sticky="true" />
<!-- Test with advanced fileUpload -->
<p:fileUpload
fileUploadListener="#{fileUploadController.handleFileUpload}"
mode="advanced" dragDropSupport="false" sizeLimit="100000"
update="kpiUploadNote" fileLimit="3" allowTypes="/(\.|\/)(csv|xlsx)$/" />
<!-- Test with commandButton to test the bean -->
<p:commandButton action="#{fileUploadController.handleFileUpload}"
update="kpiUploadNote" ajax="false" />
</h:form>
this my ManagedBean:
#Scope
#ManagedBean(name = "fileUploadController")
public class FileUploadController {
public void handleFileUpload(FileUploadEvent event) {
System.out.println("calling file upload...");
FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void handleFileUpload() {
FacesMessage msg = new FacesMessage("Succesful", " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
This my first Question in stack overflow and i hope you help me :),
I am making simple login page and trying to validate it using struts ValidatorForm but its not working. But same code worked for DynaValidatorForm. Not able to understand what's problem.
It is not showing any error when I click login button.
Here is my code.
login.jsp
<body>
<div style="color:red">
<html:errors />
</div>
<html:form action="/Login" >
User Name : <html:text name="LoginForm" property="username" /> <br>
Password : <html:password name="LoginForm" property="password" /> <br>
<html:submit value="Login" />
</html:form>
</body>
LoginAction.java
public class LoginAction extends Action
{ public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
LoginForm loginForm=(LoginForm) form;
String userName = loginForm.getUsername();
String password = loginForm.getPassword();
if(userName.equals("sumeet") )
{
return mapping.findForward("success");
}
else
{
return mapping.findForward("failure");
}
struts.config
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans>
<form-bean name="LoginForm" type="com.ibm.Forms.LoginForm" >
</form-bean>
</form-beans>
<global-exceptions>
</global-exceptions>
<global-forwards>
</global-forwards>
<action-mappings>
<action name="LoginForm" path="/Login" scope="session" input="/login.jsp" type="com.ibm.Action.LoginAction" cancellable="true" validate="true">
<forward name="success" path="/success.jsp"/>
</action>
</action-mappings>
<message-resources parameter="test2.resources.ApplicationResources"/>
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
</struts-config>
valdiation.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN" "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd" >
<form-validation>
<formset>
<form name="LoginForm">
<field property="username" depends="required">
</field>
<field property="password" depends="required,minlength">
<arg1 key="${var:minlength}" name="minlength" resource="false"/>
<var>
<var-name>minlength</var-name>
<var-value>6</var-value>
</var>
</field>
</form>
</formset>
</form-validation>
Thank you.
You are missing the .do in the action attribute of the html form. You don't need the name attribute in both inputs.
<html:form action="/Login.do" >
User Name : <html:text property="username" /> <br>
Password : <html:password property="password" /> <br>
<html:submit value="Login" />
</html:form>
I'm trying to implement a page with primefaces fileUpload but my handleUpload function isn't triggered.
My xhtml:
<h:form enctype="multipart/form-data">
<p:panel id="uploadFormPanel" header="File upload">
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
<h:outputText value="#{criteriaTranslation.questionaireFile}:" />
<p:fileUpload update="uploadMessages"
fileUploadListener="#{critereCSVImporter.handleFileUpload}"
mode="advanced"
allowTypes="/(\.|\/)(csv)$/"/>
</h:panelGrid>
<p:growl id="uploadMessages" showDetail="true"/>
</p:panel>
</h:form>
My backing bean:
#ManagedBean
#ViewScoped
public class CritereCSVImporter {
#Inject
private CriteriaBL criteriaBL;
private String OCRMODE;
public void handleFileUpload(FileUploadEvent event) {
System.out.println("handle");
InputStream inputStream = event.getFile().getInputstream();
}
My web.xml:
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>
org.primefaces.webapp.filter.FileUploadFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
Am I missing something?
Place commons-fileupload and commons-io jars in your lib folder
Apache Commons FileUpload
Apache Commons IO
We are developing an out-of-browser Silverlight 4 application and want to change the title after the application loads.
Example:
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
public string UserName { get; set; }
public string VersionNumber { get; set; }
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
string title = string.Format("MyApplication {0} {1} ", this.VersionNumber, this.UserName);
HtmlPage.Window.Eval(string.Format("document.title='{0}'", title));
}
}
Three things I have tried:
The above example does not work and throws an InvalidOperationException "The DOM/scripting bridge is disabled." All the references I found, example, said the HTML bridge is disabled in OOB mode.
Create a custom OOB Window, example, but I would prefer a more elegant solution.
Adjust the OutOfBrowserSettings.xml file, but it doesn't appear that I can get access to it after Load.
Any ideas on how to adjust the title after the application has loaded?
Unfortunately, the only way to do this is to create a custom OOB Window:
Look here and here for examples.
Try setting:
<param name="windowless" value="true"/>
<object id="SilverlightControlApp" data="data:application/x-silverlight-2," type="application/x-silverlight-2"
width="100%" height="100%">
<param name="source" value="ClientBin/MyTestApp.Client.xap" />
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="4.0.50826.0" />
<param name="windowless" value="true"/>
<%-- <param name="minRuntimeVersion" value="3.0.40818.0" />--%>
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration: none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight"
style="border-style: none" />
<%-- <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0" style="text-decoration: none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight"
style="border-style: none" />--%>
</a>
</object>