how use primefaces and prettyfaces together? - jsf-2

Primefaces doesn't work when primefaces and pretty face use together.
I add flowing jar:
prettyfaces-jsf2-3.3.3.jar
primefaces-4.0-20130605.174828-3.jar
My web.xml code:
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
My pretty-config.xml code:
<rewrite match="^[^(/primefaces_resource/)|^(javascript)]" trailingSlash="append" toCase="lowercase" redirect="301"/>
<url-mapping id="home">
<pattern value="/" />
<view-id value="/" />
</url-mapping>
This image is whithou prittyface( jar and configure):
when I add pretty face jar .then flowing view:
I want to change the url.
example:
(http://localhost:8084/AntSchoolMS/faces/index.xhtml)
I want it to be changed as
(http://localhost:8084/AntSchoolMS/)
please help me .

I use primefaces 3.5 with pretty faces 3.3.3 and works ok. The configuration in your web.xml seems to be ok. Make sure you place pretty-config.xml also in WEB-INF.
About the pretty-config you posted: it doesn't make any sense to have a url-mapping where the pattern and the view-id are the same, so remove it.
Also I don't have that rewrite rule, I have several mappings like the folowing:
<url-mapping id="login">
<pattern value="/login/">
<view-id value="/login.jsf" />
</url-mapping>
Did you try removing that rewrite rule to see what happens?

I've been using these two for some time and they are working as expected. My project used the 3.5 version of primefaces and PrettyFaces 3.3.3.
In my web.xml I did not need to register any filter like you did.
I would also try to remove the rewrite rule as Damian suggests.

Additionally, I would recommend upgrading to the latest version of PrettyFaces - see http://ocpsoft.org/prettyfaces/

Related

how to have clean url in netbeans for jsp

i would like to remove numerics, symbols and file extensions in the url using netbeans. I tried the following code in web.xml but it aint works
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/index.jsp</url-pattern>
</servlet-mapping>
Answers are welcome
Download the jar http://urlrewritefilter.googlecode.com/files/urlrewritefilter-4.0.3.jar and XML file http://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/4.0/urlrewrite.xml
Add urlrewrite.xml into your web-INF folder then add jar file into your libraries .Then isert this segment into your web.xml which defines the filter mapping
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
Consider if your href is <a href="login.jsp">. In your urlrewrite.xml you can see the following code
<rule>
<from>/Authentication</from>
<to >/login.jsp</to>
</rule>
The <to> represents your native URL you can paste your native url here .
The <from> represents the altered URL that will be shown on the browser URL .
After editing the urlrewrite.xml you should include only your altered URL in the href tag i.e after changing the urlrewrite.xml your href should should call tha altered URL
<a href="/Authentication">
Thats it now URL wil shown with http:abc.com/Authentication/ instead of http:abc.com/login.jsp/

How to remove .action from URL without using a constant in struts.xml

I am using Struts 2 convention plugin. I don't want to use any XML based configurations in my application. So, in this case, how how to remove .action extension from URL without using <constant name="struts.action.extension" value="" /> in struts.xml? I am currently using struts.xml file only to remove .action extension. Is there any annotation to remove .actionextension?
There isn't such annotation. You can use struts.properties or define a constant in web.xml like
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>struts.action.extension</param-name>
<param-value>,</param-value>
</init-param>
</filter>

Tiles Integration with Struts 2 Annotation

I have been trying to integrate Tiles with Struts 2 annotation based action but it's not working correctly.
As I don't have struts-config.xml and in every tutorial available at web they are referencing it with struts-config.xml.
First is it possible to integrate annotation based struts action with tiles. If yes then how?
#Action(value="/login",results={#Result(name="success",location="/home",type=TilesResult.class),
#Result(name="login",location="/jsp/userLogin.jsp")})
public String execute() {
This is what my code is but it always gives me error in MyEclipse at TilesResult.class that
Type mismatch: cannot convert from Class<TilesResult> to String
I have dependency in my pom:
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-tiles-plugin</artifactId>
<version>2.1.8</version>
</dependency>
Can anyone help me how to add tiles in annotation based actions
I used type="tiles" instead of type=TilesResult.class then it has given me below exception
Caused by: The Result type [tiles] which is defined in the Result annotation on the class [class com.actions.LoginAction] or determined by the file extension or is the default result type for the PackageConfig of the action, could not be found as a result-type defined for the Struts/XWork package [com.actions#convention-default#] - [unknown location]
at org.apache.struts2.convention.DefaultResultMapBuilder.createResultConfig(DefaultResultMapBuilder.java:422)
at org.apache.struts2.convention.DefaultResultMapBuilder.createFromAnnotations(DefaultResultMapBuilder.java:394)
at org.apache.struts2.convention.DefaultResultMapBuilder.build(DefaultResultMapBuilder.java:202)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.createActionConfig(PackageBasedActionConfigBuilder.java:800)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildConfiguration(PackageBasedActionConfigBuilder.java:586)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:318)
at org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:53)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:204)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
Try these :
Use type="tiles" instead of type="TilesResult.class"
Use your target tile definition, location="tiles-definition-name", instead of JSP page, location="/jsp/userLogin.jsp", in your result location
Have following in your web.xml:
<context-param>
<param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
<param-value>/WEB-INF/tiles.xml</param-value>
</context-param>
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
Have following in your struts.xml (If you are using annotations alone and no struts.xml, then you have to create a minimal one for this because there's no annotation available to define a custom result type)
<struts>
<constant name="struts.convention.default.parent.package" value="codeoftheday.blogspot.com"/>
<package name="codeoftheday.blogspot.com" extends="struts-default">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
</package>
</struts>
NOTE: I've written a detailed blog post here on this issue - Maven, Struts2 Annotations and Tiles Integration Example via Convention / Codebehind / Zero Config plugin using Eclipse IDE
"org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG" this definition is not available with Strut 2.5.10.1
I have used following jars in my project.
struts2-core-2.5.10.1
struts2-convention-plugin-2.5.10.1
struts2-tiles-plugin-2.5.10.1
javax.servlet-api-3.0.1
Please once you compare your web.xml with following code.
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>actionPackages</param-name>
<param-value>com.demo.action</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<!-- <param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name> -->
<param-name>org.apache.tiles.definition.DefinitionsFactory.DEFINITIONS_CONFIG</param-name>
<param-value>/WEB-INF/config/tiles.xml</param-value>
</context-param>
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>

Calling ActionClass in tiles.xml using Struts 2.0

I reviewed the example of tiles with struts2.0 and found that in tiles.xml jsp pages are called like:
<definition name="welcome" extends="baseLayout">
<put-attribute name="title" value="Welcome"/>
<put-attribute name="body" value="/welcome.jsp"/>
BUT my question is if I want to call the action class instead of .jsp pages than how to call it like
<definition name="friends" extends="baseLayout">
<put-attribute name="title" value="Friends"/>
<put-attribute name="body" value="/checkActionLink.action"/>
when I am trying to write to execute the above code than its showing the error that checkActionLink.action is not found....thanks in advance for the help.....
Following is the web.xml file
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>Struts2Example15</display-name>
<servlet>
<servlet-name>tiles</servlet-name>
<servlet-class>org.apache.tiles.web.startup.TilesServlet</servlet-class>
<init-param>
<param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
<param-value>/WEB-INF/tiles.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
After so much research I found out that adding the following tag:
<dispatcher>FORWARD</dispatcher> in the web.xml the issue gets resolved.
Now the question arises why?
As per my understanding when we add any action as the value of value attribute of the <put-attribute/> tag the request is forwarded to the mentioned action so the action is executed successfully.
Previously <dispatcher>FORWARD</dispatcher> tag was missing so this issue was caused.
I would really appreciate if any correction is there in my understanding.
Thanks. Happy Coding :).
I don't think you can. You'll need to create a jsp and use the struts2 action tag in it. That can call an action and render part of it's page. If you make a jsp only using the action tag, you'll probably get the effect you want. Have never tried this, but you can probably insert the name of the action and namespace from tiles into the action tag before the jsp is invoked.
I would be very interested to hear how this works out for you.

Why is my (Spring Security) servlet filter getting called twice?

Any ideas about why doFilterHttp in my SpringSecurityFilter subclass is getting called twice on each request? I don't really know where to start looking. Feeling a little stumped.
I'm reverse engineering a vacationing co-worker's code. To the best I can figure it, here's the relevant configuration:
in web.xml:
<filter>
<filter-name>userSecurityFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>userSecurityFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>userSecurityFilter</filter-name>
<url-pattern>/json/*</url-pattern>
In spring-security.xml:
<!-- Create the filter chains for developers, users and services -->
<bean id="userSecurityFilter" class="org.springframework.security.util.FilterChainProxy">
<security:filter-chain-map path-type="ant">
<security:filter-chain pattern="/**/json/*" filters="AuthFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor"/>
<security:filter-chain pattern="/**/*.do" filters="AuthFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor"/>
<security:filter-chain pattern="/**" filters="anonymousProcessingFilter,logoutFilter,exceptionTranslationFilter,filterInvocationInterceptor"/>
</security:filter-chain-map>
</bean>
It looks like the /**/json/* urls are getting the filter chain applied twice, while others only get it once. I'm going to go back and check to make sure what I just said is really true.
Ok, fixed it I think.
<filter-mapping>
<filter-name>userSecurityFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>userSecurityFilter</filter-name>
<url-pattern>/json/*</url-pattern>
There are urls under /json/ that end in ".do", so those urls were getting all of the Spring Security stuff applied twice. Thanks for the responses! Even though it was a dumb problem and I answered it myself, working through the reponses led me to the answer. Much appreciated.
Not much to go on here, but it may be that servlet container is processing several dispatchers, look in web.xml for:
<filter-mapping>
<filter-name>securityFilter</filter-name>
<url-pattern>/*</url-pattern>
<!-- the following is optional, but some containers give the wrong default -->
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
Can you post the filter-mapping from your web.xml?
Spring Security filters are not configured in the web.xml like classic Servlet Filters. They are instead configured somewhere in the application-context.xml (or whatever .xml configuration files you import in your web.xml).
Look for beans with a tag like this :
<custom-filter position="LAST" />
adding that tag to a bean will add it to your Spring Security filter chain. My guess is that it's added to the chain properly and also added as a Servlet Filter as shown above. Hence it's actually configured twice.

Resources