DWR using get / post url - post

I am using DWR for one of my application. I have setup the environment and clear about how to make call to Java functions using the ClassName.method() approach. But I want to use jsonp style approach mentioned here http://directwebremoting.org/dwr/introduction/remoting_options.html.
I tried creating sample application and run on tomcat. But I was unable to get any result from server. It was saying 404.
This is my call:
$.post("/DWRDemo/dwr/jsonp/Demo/sayHello/" + name, { },
function(data) {
dwr.util.setValue("demoReply", data.reply);
}, "jsonp");
}
where
DWRDemo: Application name
Demo: class name
sayHello : method name
=====================================================================
dwr.xml
<create creator="new" javascript="Demo">
<param name="class" value="org.getahead.dwrdemo.simpletext.Demo"/>
</create>
=====================================================================
web.xml
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<display-name>DWR Servlet</display-name>
<description>Direct Web Remoter Servlet</description>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<init-param>
<param-name>jsonpEnabled</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
=====================================================================
And I have included the required .js files in my html
====================================================================
Is there any other configuration that I am missing.
Appreciate your help.
Regards,
Ronak

I have found the resolution. Actually, I was using DWR.jar (version 2.7). But looks like it does not support servlet call. I tried with DWR.jar (version 3.0) and it worked straight away.

Related

jsf2 don't work ,url pattern

I created application with JSF2 Spring and Hibernate, but when I run it I obtain this error :
Tag Library supports namespace: http://primefaces.org/ui, but no tag was defined for name: clock javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
Take a look inside your web.xml and make sure you have :
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
Also that your view files are ending with .xhtml
Now you can change your default extension :
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
Finally, make sure you changed your welcome file :
<welcome-file-list>
<welcome-file>index.jsf</welcome-file>
</welcome-file-list>
Hope this helps!

Faces Servlet not parsing .xhtml pages in jsf 2. running on tomcat 7

I am trying to create a JSF 2.0 application in eclipse with tomcat7. The project is running successfully but the jsf html and core components are not rendered in browser. I think Faces Servlet I have configured in web.xml.
Following is the web.xml file -
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default)</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
I have my index.xhtml page outside WEB-INF. Its shown in browser but the jsf components are not see in browser. Can anyone please tell what is going wrong.
I have included following jars in WEB-INF/lib -
1. commons-annotations.jar
2. commons-beansutil.jar
3. commons-collection.jar
4. commons-digester.jar
5. commons-logging.jar
6. jsf-api.jar (from mojra 2.0)
7. jsf-impl.jar (from mojra 2.0)
8. jstl.jar
9. standard.jar
Thanks
Try these .. These were specified to me for my own question once..
You don't need and even should not include the JSF jars. Those are already part of Java EE.
Secondly, you definitely don't need and absolutely should not use the separate Facelets jar in combination with JSF 2.x. Facelets is already part of JSF 2.x.
You also should not include the JSTL jar. That one too is provided by Java EE. If u have commons jars by Apache commons, then those are fine but they are NOT needed for JSF. Include them only if you want to use them directly in your application code.
Try to get latest JSF (mojara 2.x).
Also you can modify your web.xml like this and try:
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
When I tried, I removed adding jsf jars separately. And it worked, displaying all the jsf tags. Also make sure you have all the required taglibs in your xhtml page, namely :
<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:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
See if this works.
Please change your servlet mapping shown in your original question to
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
to make it work, i.e. to have your content (which is already happily served by Tomcat) rendered via JSF2.
I had this problem too, and as this question is the first result on google queries about JSF not parsing xhtml files, here is what I have done to solve:
In my case I had a dependency on weld-servlet, version 2.2.1, when I removed it from classpath the JSF started rendering.
Hope this help!

JSF2: Tags not rendered but the usual "fixes" doesn't cut it

My problem is similar to:
JSF tags not rendered, JSf tags not being rendered and also JSF tags not being rendered as HTML no suggestion there helped me.
Basically the problem is that regardless of going through a welcome page or not the page is not rendered. IE tries to download the file and chrome basically just skips all the jsf tags. It's obvious that it wasn't translated by the framework but I don't understand why.
The back story is that I did a pilot for a conversion of a system from jsf 1.2 into jsf2. The pilot was successful I managed to get it to work in the pilot branch. However when I'm trying to achieve the same thing for real this time I can't get it to work.
The usual problem seems to be (accordingly to veteran answerer BalusC):
The page URL did not match the url-pattern of the FacesServlet, thus it had not any chance to parse the tags.
OR: The xmlns declarations for JSF components are missing in tag, thus it was treated as plaintext.
The usual fixes seems to be:
Include xmlns in html declaration (I have this in both web.xml and the .xhtml files)
Include or modify Faces Servlet Mapping in web.xml. I can however find no fault in mine. I also tried switching out /faces/* to *.xhtml. Parts that I see as relevant in web.xml included below (Whole file is big, this is a big system):
Part of web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_5.xsd"
version="2.5">
<context-param>
<description>
Tell the runtime where we are in the project development
lifecycle.
</description>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
<url-pattern>*.xhtml</url-pattern>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<welcome-file-list id="default">
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
</welcome-file-list>
I'm aware that the welcome file is a html file but this worked in the pilot. That file uses
<body bgcolor="#FFFFFF" onload="window.location='portal/login/login.jsf'">
</body>
To get things going. if I manually type the adress in to some random test page containing little and simple code the problem still occurs so the problem feels unrelated to welcome page.
Will gladly assist with any additional information and I'm really stuck here in a bad spot. Thanks for reading.
Resolved by editing faces-config to include xmlns:xsi.

How to extend an XML File using ant xmltask by copying tags from a source-file to the dest-file in specific positions

Im trying to create a special web.xml for local development.
I have some tags stored in a separate xml-file which need to be selected and pasted to specific positions inside the final web.xml.
To achieve this I am using the copy and the paste action in the following manner:
<xmltask source="templates.xml">
<copy path="//data/init-param" buffer="initParamBuffer"/>
</xmltask>
<xmltask source="web.xml" dest="web.xml">
<paste path="//web-app/filter[contains(./filter-name,'MyFilter')]
/init-param[contains(./param-name,
'MyInitParameter')]"
position="after" buffer="initParamBuffer"/>
</xmltask>
My intention is to gather ALL init-param Tags from the source File and paste them after the Tag selected in the paste operation.
Also the Part where Im selecting a Tag which contains a tag with a specified content using the contains() function is not working smoothly either.
Maybe there is a better way to form this xpath expression...
update:
As I have written before, I do not know the best approach to this problem. I have read about the possibility to transform using stylesheets, but since the ant-xmltask promised to be a more sleak sollution I have tried this first.
As far as I have come with this approach, it is possible to insert/write tags into the web.xml using this approach. I have succeeded in inserting single init-param tags at locations that where sligtly off, with a less complex expression:
<paste path="//web-app/filter[1]/init-param"
position="after" buffer="initParamBuffer"/>
So my Problem was:
A: I want to select more than one tag into the buffer
B: I want to insert the content of that buffer after a tag specified by a name (not index).
Here is an example for the sources (templates.xml) to insert into the web.xml:
<data>
<init-param>
<param-name>newparam1</param-name>
<param-value>1</param-value>
</init-param>
<init-param>
<param-name>newparam2</param-name>
<param-value>2</param-value>
</init-param>
</data>
Here is part of an web.xml where the above section is to be pasted:
<web-app>
<filter-mapping>
<filter-name>SomeFilter</filter-name>
<url-pattern>/somePath/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>MyFilter</filter-name>
<url-pattern>/myPath/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>SomeFilter</filter-name>
<filter-class>foo.bar.SomeFilter</filter-class>
<init-param>
<param-name>SomeInitParameter</param-name>
<param-value>4711</param-value>
</init-param>
</filter>
<filter>
<filter-name>MyFilter</filter-name>
<filter-class>foo.bar.MyFilter</filter-class>
<init-param>
<param-name>MyInitParameter</param-name>
<param-value>0815</param-value>
</init-param>
</filter>
</web-app>
And here is the result I would hope to achieve:
<web-app>
<filter-mapping>
<filter-name>SomeFilter</filter-name>
<url-pattern>/somePath/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>MyFilter</filter-name>
<url-pattern>/myPath/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>SomeFilter</filter-name>
<filter-class>foo.bar.SomeFilter</filter-class>
<init-param>
<param-name>SomeInitParameter</param-name>
<param-value>4711</param-value>
</init-param>
</filter>
<filter>
<filter-name>MyFilter</filter-name>
<filter-class>foo.bar.MyFilter</filter-class>
<init-param>
<param-name>MyInitParameter</param-name>
<param-value>0815</param-value>
</init-param>
<init-param>
<param-name>newparam1</param-name>
<param-value>1</param-value>
</init-param>
<init-param>
<param-name>newparam2</param-name>
<param-value>2</param-value>
</init-param>
</filter>
</web-app>
Use XPath Or:
Path|Path
From:
<paste path="//web-app/filter[1]/init-param" position="after" buffer="initParamBuffer"/>
To:
<paste path="//web-app/filter[1]/init-param|//web-app/filter[2]/init-param" position="after" buffer="initParamBuffer"/>
XPath is a Query language operating on the XML Infoset of XML documents. It can only return results or select nodes, but it cannot change the structure of the source XML document or modify it in any way.
A suitable language, designed especially for processing XML documentsand producing new XML documents, is XSLT.
The task specified in your question can be done in a very easy way using XSLT.
Please, provide a complete (but minimal) source XML document, the complete wanted result and specify any rules that the transformation should follow. Then many people will be able to give you correct and useful solutions.

Stripes: all URLs resolved through StripesDispatcher and forwarded to pre-compiled JSPs

Is it possible to have the StripesDispatcher be the sole determiner of webserver urls by looking at the #UrlBinding annotations on action beans AND also having those action beans forward to pre-compiled JSPs / servlets WITHOUT needing to define and maintain <servlet> <servlet-mapping> pairs in web.xml? Basically, I just want to have to only maintain the #UrlBinding annotations as the sole determiners of available webapp paths.
Perhaps there is a way to point Jasper to where my servlets are and load them all up automatically without having to explicitly define each and every one?
The particular way in which this is achieved is not important, only that I leave the land of explicit servlet web.xml dependencies.
Maybe I don't understand your question, but I'll give it a go. AFAIK the only mapping you need in a Stripes app's web.xml to use #URLBinding as the 'source of truth' for URLs in your web-app:
<filter>
<filter-name>StripesFilter</filter-name>
<filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class>
<init-param>
<param-name>ActionResolver.Packages</param-name>
<param-value>com.your.action.beans.package</param-value>
</init-param>
<init-param>
<param-name>Extension.Packages</param-name>
<param-value>com.your.extension.packages</param-value>
</param-value>
</init-param>
</filter>
...
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>net.sourceforge.stripes.controller.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
...
<filter-mapping>
<filter-name>StripesFilter</filter-name>
<servlet-name>DispatcherServlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
With this, there is no need to change anything in web.xml when you add/remove action beans and/or JSPs.

Resources