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.
Related
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 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)
I'm learning Spring and webflow and I'm having trouble with something which seems like it should be simple. My flow is capturing a query string parameter and stashing it in a flow-scoped variable when the flow begins. I'm trying to echo it on the first view-state. Errors ensue.
Here's the flow definition:
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
<on-start>
<set name="flowScope.foo" value="requestParameters.fubar" />
</on-start>
<view-state id="step1" view="../jsp/step1.jsp">
<transition on="next" to="step2" />
</view-state>
<view-state id="step2" view="../jsp/step2.jsp">
<transition on="next" to="step3" />
<transition on="prev" to="step1" />
</view-state>
<view-state id="step3" view="../jsp/step3.jsp">
<transition on="prev" to="step2" />
<transition on="next" to="done" />
</view-state>
<end-state id="done" view="endView" />
<end-state id="cancelled" view="../jsp/cancelledView.jsp" />
<global-transitions>
<transition on="cancel" to="cancelled" />
</global-transitions>
</flow>
step1.jsp:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%# taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%# taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Step 1</title>
</head>
<body>
This is step 1
<h1>flowRequestContext.flowScope: ${flowRequestContext.flowScope}</h1>
<h1>flowRequestContext.flowScope["foo"]: ${flowRequestContext.flowScope["foo"]}</h1>
<h2>${flowScope}</h2>
<c:if test="${empty flowScope}">
<h1>FLOW SCOPE IS EMPTY!</h1>
</c:if>
<c:if test="${!empty flowScope}">
<h1>FLOW SCOPE IS *NOT* EMPTY!</h1>
</c:if>
<c:if test="${empty flowRequestContext.flowScope}">
<h1>flowRequestContext.FLOW SCOPE IS EMPTY!</h1>
</c:if>
<c:if test="${!empty flowRequestContext.flowScope}">
<h1>flowRequestContext.FLOW SCOPE IS *NOT* EMPTY!</h1>
</c:if>
<form:form id="myForm">
<input type="submit" id="next" name="_eventId_next" value="Next" />
<input type="submit" name="_eventId_cancel" value="Cancel" />
</form:form>
</body>
</html>
Resulting error:
javax.el.PropertyNotFoundException: Property 'foo' not found on type org.springframework.webflow.core.collection.LocalAttributeMap
javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:223)
javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:200)
javax.el.BeanELResolver.property(BeanELResolver.java:311)
javax.el.BeanELResolver.getValue(BeanELResolver.java:85)
javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)
org.apache.el.parser.AstValue.getValue(AstValue.java:169)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
...
If I omit the attempt to access the key "foo" the page renders with the following output (where the query string is ?fubar=baz):
This is step 1
flowRequestContext.flowScope: map['foo' -> 'baz', 'viewScope' -> map[[empty]]]
FLOW SCOPE IS EMPTY!
flowRequestContext.FLOW SCOPE IS *NOT* EMPTY!
It looks like the identifier flowRequestContext.flowScope does refer to a map, and it looks like it does contain the key and value I would expect... but if I try to access it like a map in EL it doesn't cooperate.
just use ${foo} everything in your flowscope should be accessible with $
My application (MVC4/C#) uses the SimpleMembershipProvider and generally works fine. However, I have a problem that I cannot resolve after spending many hours researching and testing.
If I leave my application for a period of time (say 30 minutes) then select a menu item, the page renders (sidebar/header/footer), but the #RenderBody section redirects to the ~/Account/Login action.
If I then ignore the login and click on any controller action link (from the menu) then it loads as expected. It appears that the razor layout view correctly thinks I am authenticated, but the controller doesn't think I am authorized. I have a base class for most of my controllers that I inherit from that has the [Authorize] attribute.
If I logout, only the RenderBody section renders as expected, for ~/Account/Login action.
From web.config
<system.web>
<roleManager enabled="true" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
Base controller
[Authorize]
public abstract class AuthorizeBaseController : Controller
{
}
Controllers
public class SiteController : AuthorizeBaseController
{
private SiteContext db = new SiteContext();
public ActionResult Index()
{
return View(db.Sites.ToList());
}
:
_Layout.cshtml
:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>#ViewBag.Title</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
#Styles.Render("~/Content/css")
#Scripts.Render("~/bundles/modernizr")
#Styles.Render("~/Content/menubar.css")
</head>
<body>
#if (Request.IsAuthenticated)
{
<div id="header">
:
</div>
<div id="sidebar">
:
</div> <!-- sidebar -->
}
<div id="body">
#RenderBody()
</div>
#if (Request.IsAuthenticated)
{
<footer>
:
</footer>
}
#Scripts.Render("~/bundles/jquery")
#RenderSection("scripts", required: false)
</body>
</html>
It is because
[Authorize]
AuthorizeAttribute is MVC in built Attribute . make your own customize Attribute . You can have result as expect you .
Right now you can remove this Authorize Attribute from your every Controller and Action then your problem will solved .
The problem was caused by the SimpleMembershipProvider. In short, sometimes my Authorise filter was being called before InitializeSimpleMembershipAttribute().
I got my solution from this post which refers to a more detailed explanation on Scott Allen's blog
I'm currently creating a web application using the jquery+struts plugin. It also uses hibernate. I have two web pages already, the other one works perfectly fine but when I created another one, it threw an error saying that the action cannot be found. The error is:
ERROR (org.apache.struts2.dispatcher.Dispatcher:38) - Could not find action or result
/mims_agchem/index.action
No result defined for action com.agchem.mims.actions.Index and result success
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:375)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:277)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
These are my codes:
struts.xml
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<package name="admin" namespace="/admin" extends="hibernate-default,json-default,struts-default">
<interceptors>
<interceptor-stack name="showcaseStack">
<interceptor-ref name="defaultStackHibernate"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="showcaseStack"/>
<action name="*" class="com.agchem.mims.actions.admin.{1}">
<result>/jsp/admin/{1}.jsp</result>
<result name="redirect" type="redirect">${redirectUrl}</result>
</action>
</package>
<package name="general" namespace="/" extends="hibernate-default,json-default,struts-default">
<interceptors>
<interceptor-stack name="showcaseStack">
<interceptor-ref name="defaultStackHibernate"/>
</interceptor-stack>
</interceptors>
<action name="index" class="com.agchem.mims.actions.Index">
<result name="success">/jsp/index.jsp</result>
<result name="redirect" type="redirect">${redirectUrl}</result>
</action>
</package>
Index.java
package com.agchem.mims.actions;
import com.opensymphony.xwork2.ActionSupport;
public class Index extends ActionSupport {
private static final long serialVersionUID = 1475579903320095412L;
#Override
public String execute() throws Exception {
return SUCCESS;
}
}
index.jsp
<?xml version="1.0" encoding="utf-8"?>
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>AGCHEM MIMS</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="keywords" content="struts2,jquery, hibernate, plugin,showcase, grid" />
<meta http-equiv="description" content="Project Maintenance" />
<link href="../styles/main.css" rel="stylesheet" type="text/css" />
<link href="../styles/menu.css" rel="stylesheet" type="text/css" />
<sj:head
loadAtOnce="true"
compressed="false"
jquerytheme="mims"
customBasepath="../themes"
loadFromGoogle="false"
debug="true"
/>
<script type="text/javascript" src="../js/menu.js"></script>
</head>
<body>
<s:url id="adm201" action="ADM201"/>
<s:url id="adm210" action="ADM210"/>
<s:url id="adm301" action="ADM301"/>
<s:url id="adm310" action="ADM310"/>
<div id="menu">
<ul class="menu" style="width: 765px">
<li>
<sj:a href="../general/main_admin.html" targets="main">Home</sj:a>
</li>
<li class="current">
<sj:a href="#" class="parent">Project</sj:a>
<div>
<ul>
<li><sj:a href="%{adm201}" class="current" targets="main">Create New Project</sj:a></li>
<li><sj:a href="%{adm210}" targets="main">Search Projects</sj:a></li>
</ul>
</div>
</li>
<li>
<sj:a href="#" class="parent">User</sj:a>
<div>
<ul>
<li><sj:a href="%{adm301}" targets="main">Create New User</sj:a></li>
<li><sj:a href="%{adm310}" targets="main">Search Users</sj:a></li>
</ul>
</div>
</li>
</ul>
</div>
<sj:div id="main" href="%{adm201}">
<img id="indicator" src="../images/indicator.gif" alt="Loading..."/>
</sj:div>
</body>
</html>
Hope someone could explain and help me on my problem. Thanks a lot!
Regards,
Honey =)
The other page already worked. With just some refresh and restarts on the server, the page just worked fine. :) Weird though.. :)