0

JSF code

<h:dataTable value="#{requestScope.allProfile}" var="allProfile">
<h:column>                  
<f:facet name="header">StudentID</f:facet>          
<h:inputText value="#{allProfile.studentId}"
size="10" rendered="#{allProfile.canEdit}" />
<h:outputText value="#{allProfile.studentId}"
rendered="#{not allProfile.canEdit}" />
</h:column>`

Servlet

private void doProcess(HttpServletRequest request,
    HttpServletResponse response) throws ServletException, IOException, Exception {
    StudentManager stuManager = new StudentManager(); 
    List<studto>allProfile = stuManager.getAllstudentProfile();
    request.setAttribute("studentProfile", allProfile);
    RequestDispatcher rd = request.getRequestDispatcher("/ViewPage.xhtml");
    rd.forward(request, response);
}

I have been able to bring my data from database until servlet. But I can not get data in xhtml page. Do I need to create faces-config to write managed bean?

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
user2905306
  • 1
  • 2
  • 4
  • The key idea behind JSP is that it has a BackingBean http://docs.oracle.com/javaee/5/tutorial/doc/bnaqm.html – Scary Wombat Oct 22 '13 at 02:54
  • Please learn JSF, this is covered in the basics. There are good resources at [StackOverflow JSF wiki](http://stackoverflow.com/tags/jsf/info). – Luiggi Mendoza Oct 22 '13 at 03:22
  • @user2310289 those resources are for old JSF 1.2. Note that JSF has changed **a lot** between JSF 1.2 and JSF 2.0 and is currently in JSF 2.2.4 since [October 3rd, 2013](https://javaserverfaces.java.net/). – Luiggi Mendoza Oct 22 '13 at 03:24
  • That's interesting. As per https://javaserverfaces.java.net/users.html _One of the best places to start is with the official documetation. The user documentation is available as part of the Java EE 5 tutorial_ – Scary Wombat Oct 22 '13 at 04:22
  • @user2310289 you know that it is not-to-date but still recommend it? Really? – Luiggi Mendoza Oct 22 '13 at 04:23
  • please refer this [Link][1] There clear idea given [1]: http://stackoverflow.com/questions/550448/get-request-and-session-parameters-and-attributes-from-jsf-pages/550718#550718 – Pushkar Oct 22 '13 at 04:31
  • No I am quoting what is written on the link you posted. Please post what **you** think it the best step-by-step beginners JSF tutorial site. – Scary Wombat Oct 22 '13 at 04:31
  • @user2310289 if you **read** the text in the link you will notice that gives recommendations about how to ask and even post a simple Hello world tutorial using JSF 2. It points to lot of resources explaining JSF 2 and **only 1** that points to JSF 1.2 in Java EE 5 tutorial. The link you posted **is not** part of the links in StackOverflow JSF wiki (but yes, I think you can get to it by naively navigating through javaserverfaces.net but it is not the only resource). – Luiggi Mendoza Oct 22 '13 at 04:51
  • Sorry Luiggi, I am not trying to have a pissing competition with you, I am trying to get a link for the OP which shows a good step-by-step tutorial. I think this is really what the OP needs. – Scary Wombat Oct 22 '13 at 05:04
  • Hi Pushkar, I tried calling 'request' but it is not working for me. Any more advise? Thank you everyone for helping me. – user2905306 Oct 22 '13 at 07:56

1 Answers1

0

A servlet is completely the wrong tool for the job of preparing form data for a JSF form. You should just be doing the job in the (post)constructor of the JSF backing bean associated with the JSF form like as demonstrated in every sane JSF tutorial.

E.g.

<h:dataTable value="#{bean.allProfile}" var="allProfile">
    <h:column>
        <f:facet name="header">StudentID</f:facet>          
        <h:inputText value="#{allProfile.studentId}"
            size="10" rendered="#{allProfile.canEdit}" />
        <h:outputText value="#{allProfile.studentId}"
            rendered="#{not allProfile.canEdit}" />
    </h:column>

with this backing bean:

@ManagedBean
@RequestScoped
public class Bean {

    private List<studto> allProfile;

    @PostConstruct
    public void init() {
        allProfile = new StudentManager().getAllstudentProfile();
    }

    public List<studto> getAllProfile() {
        return allProfile;
    }

}

Now just open the page by /ViewPage.xhtml in browser's address bar (assuming that you've the FacesServlet already mapped on an <url-pattern> value of *.xhtml).

By the way, I'd work on your Java naming conventions. Classnames must start with uppercase.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555