• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Current JSP(JSF) doesn't match the URL

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to learn JSF in WSAD 5.1.2. I have four faces JSPs: Login.jsp, AdminMainMenu.jsp, UserMainMenu.jsp and UserSearch.jsp. After starting WTE, I ran my Login.jsp which displayed the Login.jsp and gave me the URL of "http://localhost:9080/medsup/faces/Login.jsp". After typing the userid and clicking the submit button, it then went to "UserMainMenu.jsp" with the URL of "http://localhost:9080/medsup/faces/Login.jsp;jsessionid=0000YXtEAWkUp2LuBHHUdCfwX4Z:-1".
The following are the codes that I have in the Login.jsp"
[code]
public String doButton1Action()
{
//actionBegin: goto.page
if (getUserId().getValue().equals("admin"))
gotoPage("/AdminMainMenu.jsp");
else
gotoPage("/UserMainMenu.jsp");
//actionEnd: goto.page
// Type Java code to handle command event here
// Note, this code must return an object of type String (or
null)
return "";
}
[code]
When I pressed the submit button of the UserMainMenu.jsp, it did not go to UserSearch.jsp. Instead, it didn't go anywhere. It Just stayed there displaying UserMainMenu.jsp. When I traced it, I found out that when I pressed the submit button of the UserMainMenu.jsp, I executed the Login.jsp and not the UserMainMenu.jsp because the URL still has the Login.jsp.
Can somebody help me please? I need to know how I can alter the content of the URL in such a way that when I press the submit button of the Login.jsp and when it went to display the UserMainMenu.jsp, the URL also should have the UserMainMenu.jsp and not the Login.jsp. I already checked the option in WTE to enable the URL rewriting.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of defining your goto pages in the action, why don't you use a <navigation-rule> in the faces-config file instead? Then your action could look like this:

if (getUserId().getValue().equals("admin"))
return "admin";
else
return "user";

Then, define your <navigation-rule> like this:

<navigation-rule>
<from-view-id>/login.jsp</from-view-id>
<navigation-case>
<from-outcome>admin</from-outcome>
<to-view-id>/adminMainMenu.jsp</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>user</from-outcome>
<to-view-id>/userMainMenu.jsp</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>

Note the use of <redirect/>. That should help with your URL troubles.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as the URL not matching the current page, The URL is always a page behind with JSF. You can pretty much ignore what is happening in the address line in your browser. It is meaningless to the page you are on.
 
Mike Minner
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

As far as the URL not matching the current page, The URL is always a page behind with JSF. You can pretty much ignore what is happening in the address line in your browser. It is meaningless to the page you are on.



While it being 'meaningless to the page you are on' might be true, the URL does not always have to be 'a page behind with JSF'. If you use the <redirect/> tag as I listed above, the URL will reflect the current page.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mike Minner:


While it being 'meaningless to the page you are on' might be true, the URL does not always have to be 'a page behind with JSF'. If you use the <redirect/> tag as I listed above, the URL will reflect the current page.



Thanks for clarifying Mike. I overlooked your last comment.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interestingly, looking at information about the <redirect/> tag in the navigation case the only reason I can see to NOT use it is if you want your logic to bypass any container specific operations, like ServletFilters. So it might have made more sense for JSF to use <redirect/> be default and for the developor to choose a tag like <forward/> instead when the need arises to bypass those container operations. Oh well. I guess that's neither here nor there.
 
Percy Navarro
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sir Gregg and Sir Mike,

I have followed your suggestions and the only difference is that it changed the URL from "Login.jsp" to "UserMainMenu.jsp". But when I pressed the "Submit" button in my "UserMainMenu.jsp", it still did not go anywhere. It's still displaying the "UserMainMenu.jsp" rather than displaying the next jsp which should be the "UserSearch.jsp."
The following are the codes I have in "UserMainMenu.jsp" and the navigation rule in my faces-config.xml:

[code- UserMainMenu.jsp]
//actionBegin: goto.page
//actionEnd: goto.page
// Type Java code to handle command event here
// Note, this code must return an object of type String (or null)
System.out.println("I am in UserSearch submit button");
return "usersearch";
[code - faces-config.xml]
<navigation-rule>
<from-view-id>/UserMainMenu.jsp</from-view-id>
<navigation-case>
<from-outcome>usersearch</from-outcome>
<to-view-id>/UserSearch.jsp</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>

Please help....
 
Mike Minner
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So both your usermainmenu.jsp and your login.jsp contain a Submit button? Are they using the same backing bean? Are they both bound to the same value? Are you calling the same action method from both buttons?

Can you show more of your code, or describe what you're trying to do?
 
Percy Navarro
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sir Mike,

What I'm trying to accomplish is to navigate from one jsp to another jsp to another jsp (i.e. from Login.jsp to UserMainMenu.jsp to UserSearch.jsp).

[code - faces-config.xml]

<navigation-rule>
<from-view-id>/Login.jsp</from-view-id>
<navigation-case>
<from-outcome>adminmainmenu</from-outcome>
<to-view-id>/AdminMainMenu.jsp</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>usermainmenu</from-outcome>
<to-view-id>/UserMainMenu.jsp</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>

<navigation-rule>
<from-view-id>/UserMainMenu.jsp</from-view-id>
<navigation-case>
<from-outcome>usersearch</from-outcome>
<to-view-id>/UserSearch.jsp</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>

[code- Login.jsp: This works]
public String doButton1Action()
{
System.out.println("userid: " + getUserId().getValue()+ " ");
if (getUserId().getValue().equals("admin"))
return "adminmainmenu";
else
return "usermainmenu";
}

[code- UserMainMenu: This does not work. It stays in this jsp when I pressed the Submit button. It does not even go to this method "doButton1Action()".]

public String doButton1Action()
{
System.out.println("*** UserMainMenu.doButton1Action() ***");
return "usersearch";
}

Thank you Sir Mike for helping me....
 
Mike Minner
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Was it Sargeant Hulka that said something like, "Don't call me 'sir', I work for a living"? Something like that...





Are these the same method? I suppose they cannot be since they are obviously different.

Are they in the same backing bean? I suppose they cannot be since they have the same signature.

So are there two different backing beans which each contain a method with the signature ?

If so, are the <h:commandButtons>'s wired to the right bean? Can you post the relevant parts of the actual JSPs?

Your navigation rules look good. I do not see any problems there.

[Edit] grrrr....
[ August 09, 2005: Message edited by: Mike Minner ]
 
Percy Navarro
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Mike for your time....

Those methods came from two different JSPs (one from the Login.jsp and the other from the UserMainMenu.jsp).

[code- start of Login.jsp]
<TR>
<TD height="40"></TD>
<TD></TD>
<!-- flm:cell -->
<TD valign="top"><hx:commandExButton type="submit"
value="Submit" styleClass="commandExButton" id="button1" action="#{pc_Login.doButton1Action}" ></hx:commandExButton></TD>
<TD></TD>
<TD></TD>
<TD></TD>
</TR>
 
Percy Navarro
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Mike for your time....

The two methods came from two different JSPs (Login.jsp & UserMainMenu.jsp).





[code: end of UserMainMenu.java]

[Edited by Gregg Bolinger to include propor use of UBB CODE tags]
[ August 10, 2005: Message edited by: Gregg Bolinger ]
 
Mike Minner
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aaaahhhhh.....

I am trying to learn JSF in WSAD 5.1.2


Missed that part of your first post. There are folks here familiar with this. I am not one. Can somebody help Percy out?

[ August 10, 2005: Message edited by: Mike Minner ]

[ August 10, 2005: Message edited by: Mike Minner ]

[ August 10, 2005: Mike Minner is getting tired of trying to get formatting correct ]
[ August 10, 2005: Message edited by: Mike Minner ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more item that has been left out; what about the managed-bean declarations in the faces-config? Can we see that?

On a side note, I'd HIGHLY recommend not using an IDE that generates code for you when learning JSF. All it will do is confuse and cause problems, hence the length of this discussion. In fact, I still don't use an IDE that generates code for me. But once you get familiar with JSF and know how all the pieces are put together manually, there is nothing wrong with using a tool that aids in this. Right now I believe WSAD is hendering you.
 
Percy Navarro
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Mike and Gregg. I'll try to code everything myself. This is the first time I've used the Wizards in IDE.
 
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic