Iam using p:commandlink for my menulinks..
the problem is that url in the browser is not getting refreshed with the page provided in th action..
Here goes my code...
any help
<li>Masters
<ul>
<li><p:commandLink action="ParcelMaster1.xhtml" value="ParcelMaster" /></li>
<li><p:commandLink action="ZoneMaster1.xhtml" value="ZoneMaster" ajax="false"/></li>
<li><p:commandLink action="PropertyFlatMaster1.xhtml" value="PropertyFlatMaster" ajax="false"/></li>
<li><p:commandLink action="WardMaster1.xhtml" value="WardMaster" ajax="false"/></li>
<li><p:commandLink action="MaMaster1.xhtml" value="MAMaster" ajax="false"/></li>
<li><p:commandLink action="PropertyParentMaster.xhtml" value="PropertyParentMaster" ajax="false"/></li>
<li>Usage Types</li>
<li>Custom Types</li>
</ul></li>
You have to add ajax = "false" to your commandLink. It is by default ajax call and it cannot redirect. Also try adding ?faces-redirect=true to url to which you are redirecting.
Related
I'm developing a simple crud app without frontend, but I want to have a very simple visual for myself and the viewers.
Now I have created a simple jsp-file with a set of tags 'a'.
It was not difficult to complete all GET requests. However, POST requests give an error "HTTP Status 415 – Unsupported Media Type".
This is my .jsp
<%# page contentType="text/html;charset=UTF-8" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>Title</title>
<style>
</style>
</head>
<body>
<div class="admin div">
<h2>Options for Admin</h2>
<li>Create User</li>
<li>Update User</li>
<li>Delete User</li>
<li>Get User by ID(for example 100003</li>
<li>Get User by Email(for example - david_D#gmail.com)</li>
<li>All users</li>
<br>
<li>Create restaurant</li>
<li>Update restaurant</li>
<li>Delete restaurant</li>
<br>
<li>
<form method="post" action="/rest/admin/restaurants/100005/meals">
<div class="add">
<dt>Description</dt>
<input type="text" name="description" value="Some Meal"><br> </input>
</div>
<div class="add">
<dt>Price</dt>
<input type="number" name="price" value="50"><br> </input>
</div>
<button type="submit">SAVE</button>
</form>
</li>
<br>
<li>Update meal</li>
<li>Delete meal</li>
<li>Get actual meals (for example - by restaurant with ID = 100005)</li>
<li>Get meal by ID (for example - by restaurant with ID = 100005, meal ID = 100010)</li>
</div>
</body>
</html>
When i try to send POST-request I get 'HTTP Status 415 – Unsupported Media Type'.
In network:
The response must have a 'json/application' content type, but the request has 'text/html'.
It doesn't work just to add another contentType in jsp-file.
Please, share your experiance.
Try to make your #PostMapping controller method mapping looks like this:
#PostMapping(value = "/yourUrl", consumes =
{MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_HTML_VALUE}, produces =
{MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_HTML_VALUE})
I'm creating an application in jsp & servlet. So I have created a home.jsp page it is a main page of an application and it contains a menu bar . When user clicks on menu item the following page should appear in my iframe and if user clicks on another menu item the selected page should appear in the same iframe.
I need a help.... The following code is creating a menu bar and menu item
<li>Master
<ul>
<li>Customer</li>
<li>Suplier</li>
<li>Item</li>
</ul>
</li>
<li>Transaction
<ul>
<li>Purchase</li>
<li>Sales</li>
</ul>
</li>
<li>Contact</li>
After menu bar I have a iframe in which I want to show a menu item.
I don't know how do i do this. please help me out
You will need to bind a function onclick of your <a> tag. Then using jQuery find the href of the <a> which is clicked, finally assign that href as src of your iframe
HTML
<li>Master
<ul>
<li>Customer</li>
<li>Suplier</li>
<li>Item</li>
</ul>
</li>
<li>Transaction
<ul>
<li>Purchase</li>
<li>Sales</li>
</ul>
</li>
<li>Contact</li>
<br />
<iframe src="" height="300" width="500"></iframe>
jQuery
$(document).ready(function () {
$('a').click(function () {
var target = $(this).attr('href');
$('iframe').attr('src', target);
return false;
});
});
Here's a working DEMO. I just changed the href of first two items as example.
How to set a class attribute if some condition is true in a tag in JSP?
In my JSP page I have some tabs. In the first tab I have a form field and after submission, it will call servlet, process it and then it will forward to the same JSP page and will set a session attribute value (say the id of next Tab) And in my JSP page in the LI tag I am setting the class attribute to active if the string got from session attribute is some value.
But I am not able to get it.
Here is part of servlet code
String dataloadType=request.getParameter("dataloadType");
if(dataloadType.equals("fromDB"))
{
request.setAttribute("activeTab", "fromDatabase");
RequestDispatcher rd=request.getRequestDispatcher("index.jsp");
rd.forward(request, response);
}
Part of index.jsp is
<div class="navbar btn-navbar">
<div id="tabs" class="tabbable">
<ul id="myTab" class="nav nav-tabs">
<li><a href="#datacollector" target="main"
data-toggle="tab">Data Collector</a></li>
<li id="fromDB" class="selectDataloadType <c:if test="${activeTab == 'fromDatabase'}">active</c:if>" style="display: none;"><a
href="#fromDatabase" target="main" data-toggle="tab">Data Load
Database</a></li>
<li id="fromFile" class="selectDataloadType" style="display: none;"><a
href="#fromFiles" target="main" data-toggle="tab">Data Load
File</a></li>
<li id="email" class="selectDataloadType" style="display: none;"><a
href="#fromEmail" target="main" data-toggle="tab">Data Load
Email</a></li>
<li id="webServices" class="selectDataloadType"
style="display: none;"><a href="#fromWebServices"
target="main" data-toggle="tab">Data Load Web</a></li>
<li><a href="#datamap" target="main" data-toggle="tab">Data
Map</a></li>
<li>Schedule</li>
</ul>
LI with id fromDB is setting the class attribute to active if the session attribute is 'fromDatabase' But its not working as it is not taking that part as code.
Here is the index.jsp
It is showing the code in page, so its not taking it. How can I solve it?
I think you're not setting the class attribute correctly... The class attribute of the LI tag is selectDataloadType [space] active, so eventually it is just selectDataloadType I think...
Why not something like:
<li id="fromDB" <c:if test="${activeTab == 'fromDatabase'}">class="active"</c:if>...
You can use choose instead of if if you need to have a class attruibute in any case...
I have expandable menu, you can see the code in this link..
my question is how can I keep toggle state after page refresh.
Thanks for your helps.
How about save it in a session variable?
Session("TopMenuState") = XYZ
where XYZ is your state info
Update
Mmmmm I will try and explain best I can with my limited amount of Javascript skills.
To check if local storage/session storage is available as follows
if(typeof(Storage)!=="undefined")
{
// localStorage and sessionStorage supported
}
else
{
// localStorage and sessionStorage NOT supported
}
Once your satisfied that local storage will be available then you can continue with coding the actual scripts, otherwise, one would assume that maybe the code will not work?
Further more when the user clicks on a link in your sliding menu, the idea is to persist the NAME of the menu he/she clicked on, and when the page loads, or when you render your menu's you can check the session/local storage to see what menu item (if any) was clicked on
So in the links in sliding menu you may end up with something along the lines of :
<div class="menuContent">
<a class="slider"><img alt="" id="bot" src="images/arrow_bottom.png"></a>
<ul id="nav">
<li><img src="images/t1.png" /> Home</li>
<li>
<ul id="1">
<li><img src="images/empty.gif" />Link 1</li>
<li><img src="images/empty.gif" />Link 2</li>
<li><img src="images/empty.gif" />Link 2</li>
<li><img src="images/empty.gif" />Link 3</li>
<li><img src="images/empty.gif" />Link 4</li>
</ul>
// THIS LINE MODIFIED
<span onclick="ProcessMenuLink('MenuItem1')" class="sub" tabindex="1"><img src="images/t2.png" />HTML/CSS</span>
</li>
<li>
<ul id="2">
<li><img src="images/empty.gif" />Link 6</li>
<li><img src="images/empty.gif" />Link 7</li>
<li><img src="images/empty.gif" />Link 8</li>
<li><img src="images/empty.gif" />Link 9</li>
<li><img src="images/empty.gif" />Link 10</li>
</ul>
// THIS LINE MODIFIED
<span onclick="ProcessMenuLink('MenuItem2')" class="sub" tabindex="1"><img src="images/t3.png" />jQuery/JS</span>
</li>
<li><img src="images/t2.png" />PHP</li>
</ul>
</div>
PLEASE NOTE: My javascript skills arelimited so you may need to check this code!
It is most likely missing a semicolon here and there.
And then in the subroutine or function you may have something along the lines of:
Void ProcessMenuLink(MenuItemId){
if(typeof(Storage)!=="undefined")
{
// localStorage and sessionStorage supported
//If the menuitem selected is valid
if (MenuItemId == 1) Then
{
//Save the selected menu ID/Name
localStorage.MySelectedMenuItem=MenuItemId;
// OPTIONAL - Call the toggle subroutine to toggle the selected menuitems
// Code to call sliding routine if its not executed via the CLASS parameter
}
}
else
{
// localStorage and sessionStorage NOT supported
}
}
Now at this point you have saved the SELECTED MENU ITEM in the local storage and I assume the page reloads.
So when your page loads you will want to call the subroutine which performs the menu animation or SLIDING and pass it relevant value based upon the locally-stored selected menuitem value.
Sub Window.OnLoad
//load locally stored data
if (localStorage.MySelectedMenuItem == 'MenuItem1')
{
// menu item with id 'MenuItem1' was selected so call the sliding routine
// using whatever value you used to identify your first sliding menu
}
else
{
if (localStorage.MySelectedMenuItem == 'MenuItem2')
{
// menu item with id 'MenuItem2' was selected so call the sliding routine
// using whatever value you used to identify your first sliding menu
}
else
{
// nothing was selected or an invalid selection was specified
// show the menu items in their DEFAULT state
}
}
End Sub
I'm not completely sure how to call/execute the function as its all in Javascript
Well I can only apologise for my weak Java skills coming from a VB background,
but i hope you got the gist of my meaning and that it helps you address your issue.
I have a div like this:
<div class="widget-archive-monthly widget-archive widget">
<h3 class="widget-header">Monthly Archives</h3>
<div class="widget-content">
<ul>
<li>October 2010</li>
<li>September 2010</li>
<li>August 2010</li>
<li>July 2010</li>
<li>June 2010</li>
<li>May 2010</li>
<li>April 2010</li>
<li>March 2010</li>
<li>February 2010</li>
<li>January 2010</li>
<li>December 2009</li>
<li>November 2009</li>
<li>October 2009</li>
<li>September 2009</li>
<li>August 2009</li>
<li>July 2009</li>
<li>June 2009</li>
<li>May 2009</li>
<li>April 2009</li>
<li>March 2009</li>
<li>February 2009</li>
</ul>
</div>
</div>
I'm trying to get the href values inside the widget-content div.
How would I target these links using xpath and ignore any other link on the page such as the one for "Archives" so that I end up just with these values:
http://myblog.com/blogs/my_name/2010/10/
http://myblog.com/blogs/my_name/2010/09/
http://myblog.com/blogs/my_name/2010/08/
http://myblog.com/blogs/my_name/2010/07/
... etc ...
//div[#class="widget-content"]//a/#href
That should give you the href values of links that are ONLY inside the widget-content DIV.
relative answer = XPath: find link URL by link text
"//a/#href"