[jboss-user] [JBoss Seam] - The value of seam cannot be acquired with JSF.
kumachan
do-not-reply at jboss.com
Sun Nov 5 22:07:58 EST 2006
Hello.
I have my first simple program of ejb3 by using Seam and JSF.
Though I tried ajax by this program
The value acquired from the entity bean cannot be displayed as an element of JSF.
The parameter passed by ajax in the session bean can be acquired, and DB can be accessed.
The value of the text box doesn't change when the result is displayed after it communicates with ajax asynchronously.
Could anyone advise,please?
## Environment ##
JBOSS4.0.5GA
jdk1.5.0_06
jboss-seam-1.0.1.GA
## Register.java ##
@Local
| public interface Register {
| public String start();
| public String confirm();
| public String register();
|
| @WebRemote
| public boolean checkExists(String username);
|
| public void destroy();
| }
## RegisterAction.java ##
@Stateful
| @Name("register")
| @Scope(CONVERSATION)
| public class RegisterAction implements Register {
|
| @In(required = false)
| @Out(required=false)
| private User user;
|
| @PersistenceContext
| private EntityManager em;
|
| @Begin
| public String start(){
| user = new User();
| return "/register.jsp";
| }
|
| @Conversational(ifNotBegunOutcome = "/register.jsp")
| public String confirm(){
| return "/confirm.jsp";
| }
|
| @End
| @Conversational(ifNotBegunOutcome = "/register.jsp")
| public String register(){
| em.persist(user);
| return "/registered.jsp";
| }
|
| public boolean checkExists(String username){
| user = (User)em.createQuery("select OBJECT(o) from User o where o.username=:username").setParameter("username", username).getSingleResult();
| if(user == null) return true;
| else return false;
| }
|
| @Destroy
| @Remove
| public void destroy(){}
| }
## register.jsp ##
<%@ page language="java" contentType="text/html; charset=Shift_JIS" pageEncoding="MS932"%>
| <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
| <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
| <html><head><title>register</title></head>
| <script type="text/javascript" src="seam/remoting/resource/remote.js">
| </script>
| <script type="text/javascript" src="seam/remoting/interface.js?register">
| </script>
| <script type="text/javascript">
| <!--
| function checkExists(i) {
| s = i.value;
| Seam.Component.getInstance("register").checkExists(s, checkExistsCallback);
| }
| function checkExistsCallback(result) {
| if (result) {
| // alert("It is not registered.");
| } else {
| document.getElementById("error").innerHTML="It has already been registered.";
| // alert("It has already been registered. ");
| }
| }
| //-->
| </script>
| <body>
| <f:view>
| <h:form>
| <table border="0">
| <tr>
| <td>User ID</td>
| <td><h:inputText value="#{user.username}" required="true" onblur="javascript:checkExists(this);"/><span id="error"></span></td>
| </tr>
| <tr>
| <td>Name</td>
| <td><h:inputText value="#{user.name}" required="true" /></td>
| </tr>
| <tr>
| <td>Password</td>
| <td><h:inputSecret value="#{user.password}" required="true" /></td>
| </tr>
| </table>
| <h:messages />
| <h:commandButton type="submit" value="confirm" action="#{register.confirm}" />
| </h:form>
| </f:view>
| </body></html>
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3983344#3983344
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3983344
More information about the jboss-user
mailing list