You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Dhananjay Prasanna <dp...@emergency.qld.gov.au> on 2006/07/03 03:28:07 UTC

typesafe navigation

Hi



The navigation system in JSF is enforced declaratively. I was curious of
Craig or any of the powers-that-be of myfaces had considered using
typesafe navigation using enums?

We do this in a rudimentary way in our project, as there is a very real
chance of namespace mixups and misspelling:



public class PersonnelBackingBean {



public static enum PersonnelOutcomes implements Outcomes {

      SAVE("personnelSavePage"),

      CANCEL("personnelManagePage"),

;



private String value;

private PersonnelOutcomes(String s) {

      this.value = s;

}



public String toString() {

return value;

}

}



//then in the navigation action-listener

public String doSave() {

      return PersonnelOutcomes.SAVE.toString();

}



}



I was wondering if the JSF or myfaces team had considered using a
typesafe way similar to this so that we can simply return an enum
instance and the framework can sort out if it is legitimate or not. A
more robust example (than the one above) might be:



@FromViewId( "*" )

public enum PersonnelOutcomes implements JSFOutcomes {

      SAVE("savePersonnel", "/faces/personnel/save.jsp");

//etc.

}



Then in faces-config:



<navigation-rule>

      <enum>com.mydomain.personnel.PersonnelOutcomes</enum>

</navigation-rule>



Anyway, thought I would raise it to see if people find this interesting.
I myself have a lot of trouble keeping the navigation outcomes straight.
In our projects (as in all projects) the view layer experiences some
namespace creep and occasionally undergoes navigation refactoring. The
enum system helps us keep our sanity. Of course this would force all
faces users to be JDK5 only, however, seeing as JSF is now part of Java
EE 5, I thought that we were headed down that path anyway and it might
be a sensible approach to take.



Thanks,



Dhanji



This correspondence is for the named persons only.
It may contain confidential or privileged information or both.
No confidentiality or privilege is waived or lost by any mis transmission.
If you receive this correspondence in error please delete it from your system immediately and notify the sender.
You must not disclose, copy or relay on any part of this correspondence, if you are not the intended recipient.
Any opinions expressed in this message are those of the individual sender except where the sender expressly,
and with the authority, states them to be the opinions of the Department of Emergency Services, Queensland.