Changes in .xhtml file not reflected in browser, restart and build needed - eclipse

If I make changes in my .xhtml file, the changes are not getting reflected on the screen in my browser. To get it to work, I have to restart the server everytime. This seems unwieldy to me.
I have added the following context parameters in my web.xml:
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>1</param-value>
</context-param>
However, they did not have any effect.
My technology stack is listed below:
SWF 2.3.0
Primefaces 2.2.1
JSF 2
Spring Security 3
Spring 3.1.0M1I
EhCache
Apache Tomcat 6.0
STS 2.5.1.

If you're using an IDE, then you have to configure your IDE as well to publish changes to the server immediately. Otherwise the webapp which is running on the server won't get any notion of those changes.
As you're using STS which in turn is basically Eclipse for Java EE which is preloaded with a bunch of Spring specific plugins, I think that giving a generic Eclipse-targeted answer is more than sufficient.
In Eclipse, you just have to doubleclick the server entry in Servers view and then edit the Publishing section to set Automatically publish when resources changes and set the publishing interval as low as possible. It can even be 0 seconds.
That javax.faces.FACELETS_REFRESH_PERIOD only applies on the files in the webapp context. You just have to make sure that the IDE is publishing changes to the webapp context as soon as possible.

I have just spent a couple of hours before finding out that adding antiResourceLocking="true" as an attribute to the <Context> element in the applications context.xml causes the same problem in Tomcat 7: changes in facelet files are not picked up; redeployment is needed.
Removing antiResourceLocking="true" or changing it to antiResourceLocking="false" makes Tomcat work as expected for development project stage.

You should add those lines in your web.xml so that it will refresh whenever a change occurs in your .xhtml code.
<!-- JSF 2 (Facelets 2.x) -->
<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>0</param-value>
</context-param>
<!-- Set the project stage to "Development", "UnitTest", "SystemTest", or "Production". -->
<!-- An optional parameter that makes troubleshooting errors much easier. -->
<!-- You should remove this context parameter before deploying to production! -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!--For JSF 1.2 (Facelets 1.x) parameters are -->
<context-param>
<param-name>facelets.REFRESH_PERIOD</param-name>
<param-value>0</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>

Related

Disable the logo, refresh and export icon in CrystalReports BI 4.1

I am trying to disable the logo, refresh and export icon in CrystalReports.
To achieve this, I tried with the following options
In BOE.ear/BOE.war/WEB-INF/eclipse/plugins/webpath.CrystalReports/web/WEB-INF/web.xml
added below entries
<context-param>
<param-name>viewrpt.export</param-name>
<param-value>false</param-value>
<description>Set whether a export button will be shown</description>
</context-param>
<context-param>
<param-name>viewrpt.logo</param-name>
<param-value>false</param-value>
<description>Set whether a logo will be shown</description>
</context-param>
<context-param>
<param-name>viewrpt.refresh</param-name>
<param-value>false</param-value>
<description>Set whether a refresh button will be shown</description>
</context-param>
But this is not working. Any expert advice would be helpful. Thanks.
By default, BI4 will use precompiled JSP files and will ignore any changes you make to the code.
If you want to make these unsupported changes, first locate the file global.properties in the folder WEB-INF/internal in the BOE.war archive. Look for the property precompiled.jsp.files.use and change it from true to false.
Next, redeploy the BOE webapp on your application server. Your changes should now be applied.

Eclipse Help of RAP 2.0 application does not work with WebSphere 8.5.5.0

Problem
As far as I understand in RAP every single servlet request should go through the Equinox Servlet Bridge. This includes the Help pages, which are JSP files inside the org.eclipse.help.webapp plugin.
I have the following Servlet Mapping in the Web.xml:
<servlet-mapping>
<servlet-name>equinoxbridgeservlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
If I deploy my application into websphere, then I cannot open the help, and I get this error:
It seems, that WebSphere simply ignores my will, that I want to handle even the "/index.jsp" url with the equinox servlet.
Already Tried
I tried the com.ibm.ws.webcontainer.enableJspMappingOverride custom property of the web container, but it did not help.
In the documentation it is stated:
When a url-pattern is defined in the jsp-property-group of the
web.xml, file, it is typically mapped to, and handled by the
JavaServer Page (JSP) engine. If you have applications that must
override this mapping so that they can handle and serve the JSP
content themselves, set the
com.ibm.ws.webcontainer.enableJspMappingOverride property to true.
I also added the following snippet to the web xml, but it also did not help:
<jsp-config>
<jsp-property-group>
<description>Enables using help webapp JSP pages with Websphere</description>
<url-pattern>*.jsp</url-pattern>
</jsp-property-group>
</jsp-config>
Do you have any idea how to make WebSphere to leave my requests with *.jsp URLs alone, and let equinox bridge to make its work?
It seems, that the custom property is neccessary, but not enough. I need an extra servlet mapping as described here.
So the mapping should look like this:
<servlet-mapping>
<servlet-name>equinoxbridgeservlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>equinoxbridgeservlet</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>

How to continuously deploy changes in JSF project without restarting Tomcat?

I have a JSF project in Eclipse. Now every time I make changes to the .xhtml files, I have to stop Tomcat server, and then start Tomcat server again.
Is there any other way where I can continuously build and test my application without restarting the server every time I make changes?
There are at least two changes you need to make when you need to develop a JSF project:
Tell Eclipse to automatically publish changes by changing the Tomcat settings as follows (doubleclick Tomcat server entry in Servers view to get this screen):
It namely defaults to "Never publish automatically".
Tell JSF that the webapp is currently in development mode by adding the following to web.xml:
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
This will change some internal workings to make the developers easier such as disabling the Facelet cache and reloading resources. Don't forget to remove this when building a production release because this affects performance. This setting can alternatively also be set by JNDI.
The alternative is to migrate from the barebones Tomcat server to a normal JEE server such as WildFly, Payara, Liberty, etc. For them, the above described Eclipse setting is not necessary anymore and you can even live edit bean methods (on Tomcat, you'd still need to restart the whole server for them).
facelets.REFRESH_PERIOD: –
interval compiler checks for page changes – lower values useful during development
<context-param>
<param-name>facelets.REFRESH_PERIOD</param-name>
<param-value>2</param-value>
</context-param>
(or)
<context-param>
<param-name>facelets.REFRESH_PERIOD</param-name>
<param-value>1</param-value>
</context-param>
you can set any one of the above. change in web.xml
set to -1 if you don't want to effect changes made.(default value)
check this link.
Edit: as #BalusC told, above will work for jsf 1.x, For jsf 2.X change publishing settings and javax.faces.PROJECT_STAGE in web.xml.

HTTP Status 404 - on Eclipse with Tomcat

I am trying just to run a servlet on my local Tomcat with Eclipse.
But I keep getting this error and do not have any idea what to do differently.
I actually recorded it here : http://www.screenr.com/ZyD8
Many thanks!
Also I changed the web.xml to this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID"
version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" >
<display-name>
TEST3
</display-name>
<welcome-file-list>
<welcome-file>
TEST3
</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>
helloServlet
</servlet-name>
<servlet-class>
HelloServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
helloServlet
</servlet-name>
<url-pattern>
/hello
</url-pattern>
</servlet-mapping>
</web-app>
I have seen your link.
When ever you run any dynamic web project. By default Servlet container (which is Tomcat in this case) searches for files specified in wel-come list. Check your web.xml, it should contains entry like
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
You haven't created file from any of the above list. So, running
http://localhost:8080/TEST2 will give you 404 error.
Rather run : http://localhost:8080/TEST2/HelloSerlvet will invoke the servlet which you have created.
Edit: Check Project Menu of eclipse and verify "Build Automatically" is checked and Servlet container is running (http://localhost:8080).
Edit 2: Right Click Project --> Properties, Select Java Build Path --> source Tab --> Change Default output folder. Create /WEB-INF/classes
under /WebContent (default in eclipse)
This is based on the answer from Hardik Mishra with some highlights:
1. From the file explorer (not from Eclipse), Manually create the "/WEB-INF/classes" under /WebContent
2. Right Click Project --> Properties, Select Java Build Path --> source Tab --> Change Default output folder to the folder you just created above.
3. go to the file explorer, not from Eclipse, since the Eclipse "project Explorer" may have some filters that doesnot show the classes folder. You should see the .class files compiled under this directory
Try to test it again. If it does not work, restart Eclipse for one time and then it should work.
I have been seeing these types of issue for quite sometime and have seen multiple solutions which work for some and rest still face the same issue.
One of the simple solution is traverse to the .java/.jsp/etc., right click and select run from server option.
I found this solution to be simple yet effective way of running.
path Java Resource->src->->example.java-->right click-->run as-->run on server.
Even after this also you can face few issues like port 8005 not available, please follow the below link to clean out your current Apache setting and re-setting the same.
TOMCAT - HTTP Status 404
Deployment error:Starting of Tomcat failed, the server port 8080 is already in use
Hope this finding was helpful.
Normally, when you modify the web.xml file, you should "clean" Tomcat. Just right-click on Tomcat in Eclipse and clean. Do same for project. You may also stop Tomcat, remove the app from Tomcat (right-click on app under Tomcat and remove) and then add it back. Restart Tomcat.
I am gonna divide this problem in two scenarios:
scenario 1: you are trying to run/execute html/jsp file but getting this error.
scenario 2: you have successfully executed jsp/html file but it is not executing next servlet file. example: there is jsp submit form in webcontent/webapp, it is getting executed but after filling and submitting form you are getting this error.
Scenario 1:
Make sure that your jsp/html file are in webcontent/webapp folder that you created at the time of project creation.
check web.xml file where content should be like this:
try changing tomcat server version.
Scenario 2:
at this level your main culprit is web.xml file where you have to check Servlet mapping thoroughly or add webservlet annotation at file level.

Hot republishing/deploying of static xhtml files issues

I'm noticing a lot of issues operating the "hot deploying" of JSF pages in the following environment:
Eclipse Indigo(latest version)
Tomcat 5.5
JSF 1.2
Facelets View Handler
I noticed that, if I modify an already rendered xhtml page (for example the CSS style of an element) and then re-publish(through Eclipse or manually copying the xhtml file inside Tomcat) this page (maintaining the servlet container up), it doesn't show me the current changes.
I also, in vain, setup the following configuration on my web application:
<Context
docBase="mywebapp"
path="/mywebapp"
reloadable="true"
cachingAllowed="false">
My last tought is that the Restore-View Phase of a typical JSF page processing, does not check if the client-view (the xhtml page of course) has changed from the last time it has been loaded in the FacesContext.
If so, how can i force the building of a new UIViewRoot object for each submitted request??
I'm a lot frustrating in restarting the tomcat server for each change in jsf pages.
Thanks a lot for your support.
Try adding the following to your web.xml config file:
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>facelets.REFRESH_PERIOD</param-name>
<param-value>1</param-value>
</context-param>
It tells JSF to re-render the Facelet. See how I put "1". In a Prod environment you would always put "-1" to disable this feature, since the facelets shouldn't be changing in a Prod environment.
You also need to make sure you can Hot Deploy class and JSP resources. You can find how to do that here:
http://ducquoc.wordpress.com/2010/11/06/eclipse-wtp-tomcat-hot-deploy/