I have this page:
<?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:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:ice="http://www.icesoft.com/icefaces/component"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h1>Hello World PrimeFaces</h1>
<h:form enctype="multipart/form-data">
<p:fileUpload
mode="advanced"
fileUploadListener="#{uploadFileBean.handleFileUpload}"
allowTypes="/(\.|\/)(gif|jpg|jpeg|gif|png|PNG|GIF|JPG|JPEG)$/"
auto="true" />
</h:form>
</h:body>
</html>
and this bean:
package com.gravitant.cloud.common.jsf.core.beans;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import lombok.Getter;
import lombok.Setter;
import org.primefaces.event.FileUploadEvent;
import org.primefaces.model.UploadedFile;
#ManagedBean
#SessionScoped
public class UploadFileBean {
#Getter
#Setter
private UploadedFile file;
public void handleFileUpload(FileUploadEvent event) {
System.out.println("---uploaded file: " + event.getFile().getFileName());
FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
After selecting a specific image to upload, I receive:
Caused by: javax.el.MethodNotFoundException: //C:/dev/gravitant/git-repositories/cloudMatrix-team/cloudmatrix-team/CloudMatrixWeb/CloudMatrix-Web/USERAPP/WebContent/userapp-main.jsf #22,18 fileUploadListener="#{uploadFileBean.handleFileUpload}": Method not found: com.gravitant.cloud.common.jsf.core.beans.UploadFileBean#39d02150.handleFileUpload(org.primefaces.event.FileUploadEvent)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:109) [jsf-impl-2.1.6.jar:2.1.6-SNAPSHOT]
at org.primefaces.component.fileupload.FileUpload.broadcast(FileUpload.java:280) [primefaces-3.5.jar:]
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:759) [jsf-api-2.1.6.jar:2.1.6-SNAPSHOT]
but I am sure that I correctly put the name of the method.
Is there anything I miss?
I'm using jsf 2.1.6, jboss 7, Primefaces (tested both with 3.4 and 3.5)
Related
I have a problem when adding view parameters to a <h:link includeViewParams="true" /> - they are not added to the rendered link. I am using Mojarra 2.3.9.
Template /WEB-INF/templates/main.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://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<!-- Some headers -->
</h:head>
<h:body>
<f:view>
<ui:insert name="metaContent" />
<div class="container-fluid" id="mainContent">
<ui:insert name="mainContent" />
</div>
</f:view>
</h:body>
</html>
Template being used on page test.xhtml
<!DOCTYPE html>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:o="http://omnifaces.org/ui"
template="/WEB-INF/templates/main.xhtml">
<ui:define name="metaContent">
<f:metadata>
<f:viewParam name="id" value="#{myBean.obj}" required="true">
<f:validator validatorId="myIdVvalidator" />
<f:converter converterId="myConverter" />
</f:viewParam>
</f:metadata>
</ui:define>
<ui:define name="mainContent">
<!-- Simply reference current page -->
<h:link outcome="test.xhtml" includeViewParams="true">
My link
</h:link>
</ui:define>
</ui:composition>
Update
If I remove the attribute value of f:viewParam as well as the f:converterand f:validator child elements, the link is rendered as expected. Why can this cause a problem? The Bean myBean is #RequestScoped
Currently, I am using JxBrowser 6.14.2 to print a PDF file which is embedded in tag "". However, I can only get a blank PDF file(save as PDF or print).
The html code is as follows:
<!DOCTYPE html>
<html>
<head>
<title>iframe</title>
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
</head>
<body style="text-align: center" >
<iframe src="iframe.pdf#toolbar=0" id="myFrame" name="myFrame" width="600" height="800"></iframe>
<input type="button" value="print" onclick="testPrint();">
<script type="text/javascript">
function testPrint(){
var iframe = document.getElementById("myFrame");
iframe.contentWindow.print();
}
</script>
</body>
</html>
And the java:
package com.test.print;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;
public class JxBrowserPrintPdf {
public static void main(String[] args) {
Browser browser = new Browser();
BrowserView browserView = new BrowserView(browser);
JFrame frame = new JFrame("JxBrowser - PrintPDF");
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.add(browserView,BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationRelativeTo(null);
browser.loadURL("http://localhost:8888/.../iframe.html");
frame.setVisible(true);
}
}
The webpage displays the contents of the PDF file, but after clicking the print button "print", I get the blank file. And I can get the correct file in the Google browser.
Hope someone can solve my problem. Thanks.
Please I need help on passing arraylist from servlet to the jsp page.I'm trying to populate dropdown values from Database.I have successfully connected to the Database and the values are stored in the list. The list is passed to the servlet.In the servlet, i checked by printing the values retrieved in the console. It's working fine too. Also, i set the attribute to the list and forwarded to my jsp page using request dispatcher. In my jsp page, I'm trying to get the values retrieved using jstl. I have also added the jstl jar and added the jstl tag on the top of the jsp page. I have searched many times for jstl syntax and also implemented that in my jsp. But still values are not retrieved in my dropdown.
Thanks in advance.Please someone help me.
------Success.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%-- <%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> --%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%-- <%# page import = "pack.DtoForm" %>
<jsp:useBean id="dform" scope="page" class="pack.DtoForm" />
<jsp:useBean id="Countries" class="pack.ViewValuesInDB" scope="page"/>
<%# page import="java.util.*" %> --%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Success page</title>
</head>
<body>
<h1>Success page</h1>
<div class="dbstyle">
<h4>Let's start learning connecting to the database!</h4>
<br>
<!-- <form action="DAOServlet" method="get" name="Countries"> -->
<label >Countries*:</label>
<select id="Countries" name="Countries" >
<c:forEach items="${list}" var="listt">
<option value="${listt.Countries}">${listt}</option>
</c:forEach>
</select>
</div>
<!-- </form> -->
</div>
<div>
</div>
</body>
</html></pre>
DtoForm----------------------
package pack;
public class DtoForm {
private String Countries;
public String getCountries() {
return Countries;
}
public void setCountries(String countries) {
this.Countries= countries;
}
}
ViewValuesInDB----------------------------
package pack;
import java.sql.*;
import java.util.ArrayList;
import com.sybase.jdbcx.*;
public class ViewValuesInDB {
Connection con = null;
Statement stmt = null;
SybDriver sybDriver = null;
DtoForm dform=new DtoForm();
//List<DtoForm>dform =new ArrayList<DtoForm>();
ArrayList<String> list=new ArrayList<String>();
public ArrayList<String> makeConnection() throws Exception {
try
{
sybDriver = (SybDriver) Class.forName(
"com.sybase.jdbc2.jdbc.SybDriver").newInstance();
System.out.println("Driver loaded");
con = DriverManager.getConnection(
"jdbc:sybase:Tds:ip:port","username", "password");
System.out.println("Database connected");
Statement stmt = con.createStatement();
String query = "select Countries from Country";
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String a=rs.getString(1);
dform.setCountries(a.toString());
list.add(dform.getCountries());
}
for(int i=0;i<list.size();i++)
{
System.out.println(list.get(i));
}
rs.close();
stmt.close();
con.close();
}
catch(Exception e)
{
System.out.println("Error is "+e.getMessage());
}
return list;
}
public static void main(String args[]) throws Exception {
System.out.println("inside DB main function");
ViewValuesInDB sc = new ViewValuesInDB();
sc.makeConnection();
}
}
---------------genrated html---------
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Success page</title>
<style>
.dbstyle
{
width:100%;
height:540px;
background-color:#FDF5E6;
}
</style>
</head>
<body>
<h1>Success page</h1>
<div class="dbstyle">
<h4>Let's start learning connecting to the database!</h4>
<br>
<!-- <form action="DAOServlet" method="get" name="Countries"> -->
<label >Countries*:</label>
<div>
<select id="Countries" name="Countries" >
</select>
</div>
<!-- </form> -->
</div>
<div>
</div>
</body>
</html>
-------servlet modified--------
package pack;
import java.util.ArrayList;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class DropdownServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request,
HttpServletResponse response) {
System.out.println("action is called inside dropdown");
ViewValuesInDB daoobj = new ViewValuesInDB();
ArrayList<String> list;
try {
list = daoobj.makeConnection();
System.out.println(list);
if(null == list)
{System.out.println("list is null");
}
else{
System.out.println("list has values");
}
request.setAttribute("list", list);
request.getRequestDispatcher("Success.jsp").forward(request,response);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String args[]) throws Exception {
System.out.println("inside servlet function");
DropdownServlet sc = new DropdownServlet();
sc.doGet(null, null);
}
}
I wonder why my JSF 2.2 UI input components are not rendered in my Arquillian Drone Graphene WebDriver's test browser instance. My test page is as follows:
<?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:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Login</title>
</h:head>
<h:body>
<h:form id="loginForm">
<h3>Login Failure</h3>
<h:panelGrid columns="2">
<h:outputLabel for="username">Username:</h:outputLabel>
<h:inputText id="username"/>
<h:outputLabel for="password">Password:</h:outputLabel>
<h:inputSecret id="password" />
<h:commandButton id="login" value="Log in" />
</h:panelGrid>
</h:form>
</h:body>
</html>
And my Arquillian Drone Test Class is as follows:
import java.io.File;
import java.io.Serializable;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.Filters;
import org.jboss.shrinkwrap.api.GenericArchive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.importer.ExplodedImporter;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.primefaces.model.SortOrder;
------------
#RunWith(Arquillian.class)
public class ArquillianDroneTest {
#Drone
WebDriver browser;
#ArquillianResource
URL deploymentUrl;
private static final String WEBAPP_SRC = "src/main/webapp";
#Deployment(testable=false)
public static WebArchive createDeployment()
{
return ShrinkWrap.create(WebArchive.class,"mytestwar.war")
.addClass(TestEjb.class)
.addClass(ServiceFacade.class).addClass(ServiceQueryFacade.class).addClass(AbstractFacade.class)
.addClass(Service.class).addClass(AbstractLongPKEntity.class).addClass(AbstractEntity.class)
.addClass(PersistentEntity.class).addClass(Serializable.class).addClass(PersistentEntity.class)
.addClass(SortOrder.class)
.merge(ShrinkWrap.create(GenericArchive.class).as(ExplodedImporter.class)
.importDirectory(WEBAPP_SRC).as(GenericArchive.class),
"/", Filters.include(".*\\.xhtml$"))
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsWebInfResource(new StringAsset("<faces-config version=\"2.0\"/>"),"faces-config.xml")
.addAsWebResource(new File(WEBAPP_SRC, "dos.xhtml"));
}
#Test
public void testUserLoginSuccess() {
browser.get(deploymentUrl.toExternalForm() + "/login.xhtml");
browser.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
WebElement textUserName=browser.findElement(By.id("username"));
textUserName.sendKeys("TestUSER");
}
}
And all this results (on running maven test) into following WebDriver test browser
Why JSF is not rendered in this test browser?
From comment by #BalusC, I found a clue and solved my problem i.e. inclusion of either production web.xml or testing web.xml file into test WAR. I simply added my production web.xml as follows in my test class and it worked for me:
---------------
#Deployment(testable=false)
public static WebArchive createDeployment()
{
return ShrinkWrap.create(WebArchive.class,"mytestwar.war")
.addClass(TestEjb.class)
.addClass(ServiceFacade.class).addClass(ServiceQueryFacade.class).addClass(AbstractFacade.class)
.addClass(Service.class).addClass(AbstractLongPKEntity.class).addClass(AbstractEntity.class)
.addClass(PersistentEntity.class).addClass(Serializable.class).addClass(PersistentEntity.class)
.addClass(SortOrder.class)
.merge(ShrinkWrap.create(GenericArchive.class).as(ExplodedImporter.class)
.importDirectory(WEBAPP_SRC).as(GenericArchive.class),
"/",Filters.include(".*\\.(jsf|xhtml|html|css|js|png|jpg|xml)$"))
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsWebInfResource(new File(WEBAPP_SRC,"WEB-INF/faces-config.xml"))
.setWebXML(new File(WEBAPP_SRC,"WEB-INF/web.xml"))
.addAsWebResource(new File(WEBAPP_SRC, "dos.xhtml"));
}
----------------------------
I am just trying to use include action class in struts, but i am not able to do....the steps i did are as follows
step 1 : first I created the presentation page, which is
Welcome.jsp
<%# taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<html>
<head>
<title>Include Example</title>
</head>
<body>
<div align="center">
<bean:include id="bid" forward="logins" />
</div>
</body>
</html>
step2: then I created servlet class, from where I passed msg in another client page
ShowServlet.java
package com.ashish.struts.servlet;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ashish.struts.LoginForm;
public class ShowServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
public void service(HttpServletRequest request, HttpServletResponse response)throws IOException,ServletException
{
System.out.println("Now I m in Servlet Class!!!!");
String msg="This is your Login page";
request.setAttribute("MSG", msg);
RequestDispatcher rd= request.getRequestDispatcher("/index1.jsp");
rd.forward(request, response);
}
}
index1.jsp
<%# page isELIgnored="false" %>
<html>
<head>
<title>Include Example</title>
</head>
<body>
<div align="center">
${MSG }
</div>
</body>
</html>
step3: then finally i configured the struts-config.xml file
<?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="log" type="com.ashish.struts.LoginForm" />
</form-beans>
<global-exceptions />
<global-forwards>
<forward name="logins" path="/logs1.do" />
</global-forwards>
<action-mappings >
<action path="/logs1" name="log" type="org.apache.struts.actions.IncludeAction" parameter="/WEB-INF/classes/com/ashish/struts/servlet/ShowServlet" />
</action-mappings>
<message-resources parameter="com.ashish.struts.ApplicationResources" />
</struts-config>
is there any things wrong i did , in the above steps or i left some things to do .....
because whenever i run this application , no error is showing , but desired output is not coming...
Can any one give the answer for that ...
Thanks
Ashish....
You have to add <bean:write name="bid" /> in Welcome.jsp at the location where you want to display it.
Note: all <bean:include id="NAME"... /> should have an accompanying <bean:write name="NAME" /> to print the output message.