You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Mick Knutson <mi...@gmail.com> on 2006/11/13 17:40:41 UTC
Navigation from error question...
I am fairly new to JSF, but thought that I had this right, however I am not
getting the navigation I expect...
When I get an error for a duplicate username, I want to be sent back to my
registration form and have an error message shows.
faces-config:
============
<navigation-rule>
<from-view-id>/views/registration.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/views/secure/index.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>cancel</from-outcome>
<to-view-id>/views/center.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>duplicateUsername</from-outcome>
<to-view-id>/views/registration.xhtml</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
Here is the UserBackingBean method:
============================
public String createUser(){
log.info("createUser()");
FacesContext context = FacesContext.getCurrentInstance();
try{
userManager.createUser(getUser());
} catch(Exception e){
log.error("Duplicate user name. Username already exists");
e.printStackTrace();
String failureMessage = "Duplicate user name. Username already
exists";
FacesContext.getCurrentInstance()
.addMessage(null,
new FacesMessage(
FacesMessage.SEVERITY_ERROR,
failureMessage,
failureMessage));
return "duplicateUsername";
}
return "success";
}
When I get this error, I still get sent to /views/secure/index.xhtml, same
as if I succeeded...
--
Thanks
DJ MICK
http://www.djmick.com
http://www.myspace.com/mickknutson
Re: Navigation from error question...
Posted by Mick Knutson <mi...@gmail.com>.
That did work, but now, I do not get the messages I want printed...
In registration.xhtml:
<TD colspan="2">
<h:messages />
</TD>
<TD>
<h:inputText value="#{UserBackingBean.user.username
}"
required="true"
id="username" >
<f:validateLength minimum="2" />
</h:inputText>
<h:message for="username"
errorClass="error" />
</TD>
Then in my UserBackingBean:
FacesContext.getCurrentInstance()
.addMessage(null,
new FacesMessage(
FacesMessage.SEVERITY_ERROR,
failureMessage,
failureMessage));
//String failureMsg = ErrorMessages.getString("
LoginBean.LOGIN_FAILURE");
FacesMessage message = new FacesMessage(
FacesMessage.SEVERITY_ERROR, failureMessage, failureMessage);
context.addMessage("login_form:loginButton", message);
return (null);
But no messages are printed at all.
The page is displayed though...
On 11/13/06, Gerald Müllan <bi...@gmail.com> wrote:
>
> Hi,
>
> in order to stay on the same page, you can also return null. You don`t
> need any special navigation outcome to achieve this.
>
> cheers,
>
> Gerald
>
> On 11/13/06, Mick Knutson <mi...@gmail.com> wrote:
> > I am fairly new to JSF, but thought that I had this right, however I am
> not
> > getting the navigation I expect...
> >
> > When I get an error for a duplicate username, I want to be sent back to
> my
> > registration form and have an error message shows.
> >
> > faces-config:
> > ============
> >
> > <navigation-rule>
> >
> > <from-view-id>/views/registration.xhtml</from-view-id>
> > <navigation-case>
> > <from-outcome>success</from-outcome>
> >
> > <to-view-id>/views/secure/index.xhtml</to-view-id>
> > <redirect/>
> > </navigation-case>
> > <navigation-case>
> > <from-outcome>cancel</from-outcome>
> > <to-view-id>/views/center.xhtml</to-view-id>
> > <redirect/>
> > </navigation-case>
> > <navigation-case>
> > <from-outcome>duplicateUsername</from-outcome>
> >
> > <to-view-id>/views/registration.xhtml</to-view-id>
> > <redirect/>
> > </navigation-case>
> > </navigation-rule>
> >
> >
> >
> >
> >
> > Here is the UserBackingBean method:
> > ============================
> >
> > public String createUser(){
> > log.info("createUser()");
> >
> > FacesContext context = FacesContext.getCurrentInstance();
> >
> > try{
> > userManager.createUser(getUser());
> > } catch(Exception e){
> > log.error("Duplicate user name. Username already exists");
> > e.printStackTrace();
> > String failureMessage = "Duplicate user name. Username
> already
> > exists";
> > FacesContext.getCurrentInstance()
> > .addMessage(null,
> > new FacesMessage(
> >
> > FacesMessage.SEVERITY_ERROR,
> > failureMessage,
> > failureMessage));
> >
> > return "duplicateUsername";
> > }
> > return "success";
> > }
> >
> >
> > When I get this error, I still get sent to /views/secure/index.xhtml,
> same
> > as if I succeeded...
> >
> >
> > --
> >
> > Thanks
> >
> > DJ MICK
> > http://www.djmick.com
> > http://www.myspace.com/mickknutson
>
>
> --
> http://www.irian.at
>
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache MyFaces
>
--
Thanks
DJ MICK
http://www.djmick.com
http://www.myspace.com/mickknutson
Re: Navigation from error question...
Posted by Gerald Müllan <bi...@gmail.com>.
Hi,
in order to stay on the same page, you can also return null. You don`t
need any special navigation outcome to achieve this.
cheers,
Gerald
On 11/13/06, Mick Knutson <mi...@gmail.com> wrote:
> I am fairly new to JSF, but thought that I had this right, however I am not
> getting the navigation I expect...
>
> When I get an error for a duplicate username, I want to be sent back to my
> registration form and have an error message shows.
>
> faces-config:
> ============
>
> <navigation-rule>
>
> <from-view-id>/views/registration.xhtml</from-view-id>
> <navigation-case>
> <from-outcome>success</from-outcome>
>
> <to-view-id>/views/secure/index.xhtml</to-view-id>
> <redirect/>
> </navigation-case>
> <navigation-case>
> <from-outcome>cancel</from-outcome>
> <to-view-id>/views/center.xhtml</to-view-id>
> <redirect/>
> </navigation-case>
> <navigation-case>
> <from-outcome>duplicateUsername</from-outcome>
>
> <to-view-id>/views/registration.xhtml</to-view-id>
> <redirect/>
> </navigation-case>
> </navigation-rule>
>
>
>
>
>
> Here is the UserBackingBean method:
> ============================
>
> public String createUser(){
> log.info("createUser()");
>
> FacesContext context = FacesContext.getCurrentInstance();
>
> try{
> userManager.createUser(getUser());
> } catch(Exception e){
> log.error("Duplicate user name. Username already exists");
> e.printStackTrace();
> String failureMessage = "Duplicate user name. Username already
> exists";
> FacesContext.getCurrentInstance()
> .addMessage(null,
> new FacesMessage(
>
> FacesMessage.SEVERITY_ERROR,
> failureMessage,
> failureMessage));
>
> return "duplicateUsername";
> }
> return "success";
> }
>
>
> When I get this error, I still get sent to /views/secure/index.xhtml, same
> as if I succeeded...
>
>
> --
>
> Thanks
>
> DJ MICK
> http://www.djmick.com
> http://www.myspace.com/mickknutson
--
http://www.irian.at
Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German
Professional Support for Apache MyFaces