[jboss-user] [JBoss Seam] - a problem with jBpm in Seam
mnrz
do-not-reply at jboss.com
Mon Oct 30 03:39:31 EST 2006
Hi
I am trying to change registration example in order to work with JBpm. but at the first page it is a button with action #"{register.register}"
I define in pageflow if the user already exists tnot change the current page and if not, go to next page, but It calls action register first and it check the database and because user is not exist then that action persist the data into the database and that action is calling again and in the second time, that user already persisted so the current page staty intact and a message will be displayed.
here is pageflow definition file:
| <pageflow-definition name="SeamPracticePageFlow">
|
| <start-page name="start" view-id="/pages/register.jsp">
| <transition name="register" to="checkUser" />
| </start-page>
|
| <decision name="checkUser" expression="#{register.alreadyExists}" >
| <transition name="false" to="registered" >
| <action expression="#{register.register}" />
| </transition>
| <transition name="true" to="start" />
| </decision>
|
| <page name="registered" view-id="/pages/registered.jsp">
| <redirect/>
| <transition name="welcomeMessage" to="listMessage" >
| <action expression="/pages/messages.seam" />
| </transition>
| </page>
|
| <page name="listMessage" view-id="/pages/messages.jsp">
| <redirect/>
| <end-conversation/>
| </page>
|
| </pageflow-definition>
|
and jsp file:
| <f:view>
| <h:form>
| <table border="0">
| <s:validateAll>
| <tr>
| <td>Username</td>
| <td><h:inputText value="#{user.username}" required="true"/></td>
| </tr>
| <tr>
| <td>Full Name</td>
| <td><h:inputText value="#{user.fullName}" required="true"/></td>
| </tr>
| <tr>
| <td>Password</td>
| <td><h:inputSecret value="#{user.password}" required="true"/></td>
| </tr>
| </s:validateAll>
| </table>
| <h:messages/>
| <h:commandButton type="submit" value="Register" action="#{register.register}"/>
| </h:form>
| </f:view>
|
and the action:
| @Create
| @Begin(join=true,pageflow="SeamPracticePageFlow")
| public void register() {
| try {
| if(isAlreadyExists()) {
| userNotExists = false;
| em.persist(user);
| logger.info("user #{user.username} registered.");
| //return "/pages/registered.jsp";
| }else {
| logger.info("user #{user.username} already registered.");
| userNotExists = true;
| }
| } catch (Exception e) {
| e.printStackTrace();
| }
|
| }
|
| public boolean isUserNotExists() {
| return userNotExists;
| }
|
| public boolean isAlreadyExists() {
| try {
| List registered = em.createQuery("select username from User where username = :u")
| .setParameter("u",user.getUsername())
| .getResultList();
| if(registered == null || registered.size() == 0) {
| return true;
| }else {
| FacesMessages.instance().add("user #{user.username} already exists.");
| return false;
| }
| }catch(Exception e) {
| e.printStackTrace();
| }
| FacesMessages.instance().add("something's wrong...");
| return false;
| }
|
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3981675#3981675
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3981675
More information about the jboss-user
mailing list