Saturday, May 05, 2007

Change default (first) page in APEX

Having seen this question often (yesterday again in the OTN APEX forum) and having had the same problem when I first started with APEX, I thought to blog about it.

When you make your first application in APEX you typically have as default page 1 or the login page (101). If you want to change your default (first) page you need to have a look at three different places. Let's say we want to have page 9 as default page:

1) Application Builder > Your Application > Page 101 > Processes (Page Processing) > Login
Change Process to:

 wwv_flow_custom_auth_std.login(
P_UNAME => :P101_USERNAME,
P_PASSWORD => :P101_PASSWORD,
P_SESSION_ID => v('APP_SESSION'),
P_FLOW_PAGE => :APP_ID||':9'
);
Whenever somebody logs in we want him to go to page 9.

2) Shared Components > Security > Authentication Schemes > Your Authentication
Change the Logout URL: wwv_flow_custom_auth_std.logout?p_this_flow=&APP_ID.&p_next_flow_page_sess=&APP_ID.:9

If somebody logged out, we set the default page to 9 as that's our default page.

3) Shared Components > Security > Edit Security Attributes
Change the Home Link to: f?p=&APP_ID.:9:&SESSION.

If no page is specified this is the page to go to for ex. f?p=100 means we're going to application 100 with as default page, the page specified in the Home Link. You can also reference this url by #HOME_LINK#.

20 comments:

Anonymous said...

Thank you Dimitri for your answer.
But i think that in the future should be much easier to change such properties. Just a parameter at the application level!
Best regards
Adrian

Anonymous said...

Thanks, you're the man.

Anonymous said...

You've saved me from a major headache, a simple thanks won't suffice but that's all i can say.

Thanks again.

Suddenly I realised said...

I was VERY happy to find this - I agree this should either be made MUCH simpler to do by ApEx, or, even better, be a user choice when creating an application.

I have one question, though: I did all three changes, and it works fine. What does NOT work is, if I export the app, and import it with a different ID as run-only (for deployment.) In that case, the logout process STILL uses :app_id:1 (and not :10 like I changed it to.)

Any ideas?

(Thanks still for a clear explanation!)

Castorani said...

Thanks a lot for this post, it was really helpfull

Anonymous said...

thanks, most helpfull

anjali said...

Hi,

Making the changes as you said will take me to a specific page. But if i want to send user to different pages how can I do that.

e.g if user is dummy he should go to page 3 and if user is abc he should go to page 1.

How can I achieve this?
please respond as soon as possible.

Thanks in advance.

Frank Schmidt said...

Thanks for this complete and compact Tip!
Kind Regards, Frank

Anonymous said...

Thank you.

Apex -X said...

Worked perfect. thanks

Jack said...

Hi Dimitri,

I am facing issue on setting up default page even I have checked my all 3 settings which you have described in this post.
My default page should be 7 but sometimes users are redirecting to page 1.

Please suggest.

Regards,
Jack

Anonymous said...

my apex homepage is not working after i run forms builder and forms application. could you please give solution for this.
Thanks in advance.

Anonymous said...

Thanks for this. I'm having a problem though that if someone tries to log in and fail page security, if they press ok and log in with a user who passes page security Apex tries to take them to page 1 (ignoring my settings of page 2). Do you know how to stop this. Thanks

Anonymous said...

Actually as soon as I posted my comment I realised the page direction was been set by the login page (call to wwv_flow_custom_auth_std.login, p_flow_page)

Nick Adams said...

I agree with your with.Thanks you share with me this nice post.Keep it up...

Anonymous said...

My requirement has slight change where different users type should be directed to different pages. So

I wrote like this :
-------------------
DECLARE

l_routeto number;
l_errordesc varchar2(4000);
lc_clob CLOB;
LN_COUNT NUMBER;

BEGIN

IF upper(trim(:P101_USERNAME)) = 'ABC' THEN
l_routeto := 1;
elsif upper(trim(:P101_USERNAME)) = 'DEF' THEN
l_routeto := 201;
elsif upper(trim(:P101_USERNAME)) = 'HIJ' THEN
l_routeto := 301;
else
l_routeto := 1;
END IF;

wwv_flow_custom_auth_std.login
(
P_UNAME => :P101_USERNAME,
P_PASSWORD => :P101_PASSWORD,
P_SESSION_ID => v('APP_SESSION'),
P_FLOW_PAGE => :APP_ID||':'||l_routeto
);

exception
when others then
NULL;

END;

I was able to land into respective pages allocated to Username 'ABC ' and ' DEF ' but got an error when i try to login with username 'HIJ'.

Please help me out.


Thanks & Regards,
Vikram S

Dimitri Gielis said...

What error did you get? Maybe the page didn't exist or has an authorization on?

Beverly Selby said...

Dimitri,

I just started in APEX. I have a requirement to add a change password page so that the user can change his/her password if it is expired or if they just want to. I had added a button to the login page and on the login page process had it go to my new change password page. However, it makes the user login first. I don't want the user to have to login. The only way this currently works is that they select the change password button -> login and it does take them to the change password page. I would like to have them push the change password button and have it go directly to the page without having them login. Any ideas? Thanks. Beverly Selby

Dimitri Gielis said...

Hi Beverly,

You need to set your page as Public (in security section of your Page attributes).

That way for the reset password page they don't need to login.

Hope that helps,
Dimitri

Beverly Selby said...

Bare with me here.... I am using the Authentication Scheme using Application Express Authentication. 101 is my login page ... 36 is my change password page. I edited page 36 set the Security -> Authentication = "Page is Public". I click on the Change Password button and it does go to the change password page however when I put in the username = '', Old password = '', New password and confirm password it comes back with Invalid Old Password. I am typing in the correct password for the Old password. For the Old Password field -> Source, Source Used = Always, replacing any existing value in session state, Source, Source Type = Database Column, Source value or expression = 'PASSWORD'. Once I changed the page to public it put "NOBODY" in the User Name field on the change password field. So when I type in an APEX user and the old password new password, confirm the password...it always indicates that the old password is invalid.