0

I have the following code and whatever I do my web browser does not render any submit button.

I am using eclipse with Glassfish.

The problem is also that somehow when I try my examples fast , the server sometimes hangs around and browser is in the waiting mode for minutes without any error or anything.

Sometimes it does give the page away and it works perfect.

Why is the button not shown and my server is so unstable?

<h:head><title>JSF 2: Using @ManagedBean</title>
<link href="./css/styles.css" 
      rel="stylesheet" type="text/css"/> 
</h:head>
<h:body>
<div align="center">
<table class="title">
  <tr><th>JSF 2: Using @ManagedBean</th></tr>
</table>
<p/>
<fieldset>
<legend>Random Results Page</legend>
<h:form>
  Press button to get one of three possible results pages.
  <br/>
  <h:commandButton value="Go to Random Page" action="#{navigator.choosePage}" />
</h:form>
</fieldset>
</div>




 package coreservlets;
import javax.faces.bean.*;

@ManagedBean
@ApplicationScoped 
public class Navigator {
  private String[] resultPages =
    { "page1", "page2", "page3" };

  public String choosePage() {
    return(RandomUtils.randomElement(resultPages));
  }
}
Artem Moskalev
  • 5,748
  • 11
  • 36
  • 55
  • Im trying. How to do that? It turns my html tags into the picture here – Artem Moskalev Aug 16 '12 at 20:53
  • 1
    @ArtemMoskalev: You highlight the area with the code and press the `{}` button to get code snippets to be displayed correctly. – Keppil Aug 16 '12 at 20:56
  • thanks, Keppil. Ilya, there it is. – Artem Moskalev Aug 16 '12 at 20:59
  • Glassfish does not write any mistakes in the log, by the way – Artem Moskalev Aug 16 '12 at 21:00
  • http://stackoverflow.com/questions/5367918/glassfish-not-display-jsf-components?rq=1 there is a probable answer. I tried it and it works, but then there is another question. I always map my Faces servlet to any .jsf pages, if I map it in web.xml rather to .xhtml files - does it make any difference – Artem Moskalev Aug 16 '12 at 21:07

1 Answers1

2

That can happen if you either forgot to declare the h: XML namespace, causing the <h:xxx> tags being unrecognized. This can be confirmed by just looking at the JSF source code and the generated HTML output (rightclick - View Source in browser).

<html ... xmlns:h="http://java.sun.com/jsf/html">

Or the request URL as you see in browser's address bar didn't match the <url-pattern> of the FacesServlet as mapped in web.xml, causing the <h:xxx> tags being unparsed. This can be confirmed by just looking at the request URL, the web.xml and the generated HTML output.

<url-pattern>*.xhtml</url-pattern>

Or the CSS in styles.css has hidden it in some way. This can be confirmed by checking the CSS file, and/or using the browser's developer toolset and/or checking the generated HTML output.

input[type=submit] {
    display: none; 
}

See also:


Unrelated to the concrete problem, using an application scoped bean for the particular use case is quite strange. It's been shared among all users in all sessions. So if the action is invoked by webapp user X elsewhere in the world, all other webapp users over the world would see it being reflected. Wouldn't you rather use a request or view scoped bean?

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks. The application scope is not my invention - all this code is the example from some tutorial I found online, so I tried to retype it and to launch the application. Which was impossible because of the mistakes in the code there. – Artem Moskalev Aug 17 '12 at 14:55