Home > Archive > Java Help > November 2007 > Using JSF with Servlets or Page Beans
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Using JSF with Servlets or Page Beans
|
|
| csharpdotcom 2007-11-12, 7:17 pm |
| Hi, I'm continuing to plod along with Java Server Faces and have made
quite a
bit of progress in the last few w s thanks to several people here,
such as
Roedy Green, as well as spending a lot of time reading up about the
whole thing,
but I've now run into another snag.
Basically what I want to do is to send the contents of a form to the
server using
Java Server Faces, but because the form has quite a few entries, which
can
vary, it's probably not practical to use beans. Moreover, all the
HTML and
JavaScript was written earlier this year without JSF in mind, and I
want to make
as few changes as possible to the existing HTML and JavaScript code.
My questions are how can I send the contents of a form to a servlet in
Java
by extending the HttpServlet servlet class, or writing a pagebean,
whatever the
latter is, as was mentioned in a brief reply to me on
comp.lang.java.beans
yesterday? Presumably the faces-config.xml file has to be set up in
some way.
More details can be found in my Novermber 11 post on
comp.lang.java.beans,
where I also asked how I can extract a value from the DOM and send it
to a
bean. The home page containing the original code is at
http://csharp.com/simulator, with other links given in my posting to
comp.lang.java.beans.
I would most appreciate some help in getting this sorted out.
Christopher Sharp
| |
| csharpdotcom 2007-11-13, 7:18 pm |
| I still havn't yet figured out how to configure Glassfish to
handle servlets, but this must be something to do with the
xml configuration files.
However, in the mean time as related to one of my
questions above, how do I pass a variable by say
JavaScript to a bean? Suppose I have a JSF form such
as:
<h:form>
<h:inputText value="#{user.text}"/>
<h:commandButton value="Login" action="login"/>
</h:form>
which passes the inputed text to a bean.
Now instead of typing the text in, it is generated
elsewhere on the page, such as a separate form handled
by JavaScript which I want send to the bean. For example
I could have something like:
<head>
<title>Passing a Value to a Bean by JavaScript</title>a
<script type="text/javascript">
var s;
function readform() {
s=myform.forminput.value;
return true;
}
</script>
</head>
<body>
<--Regular non JSF form -->
<form id="myform">
<input type="text" name="forminput"/>
</form>
<--JSF form -->
<h:form>
<h:inputHidden value="what do I put here?"/> <!-- ???? -->
<h:commandButton value="Login" onclick="return readform()"
action="login"/>
</h:form>
</body>
In the JSF form I put in a call to the function readform() which
gets the value from the regular form above, and the idea
is to pass it on to the bean. How do I do this?
I have a lot of code in JavaScript that handles regular forms,
which I don't want to rewrite, so would most appreciate some
advice on this.
Christopher Sharp
|
|
|
|
|