I'm looking to create a horizontal menu in a jsp page - the menu items vary by user but stay consistent over every page in the site for that user apart from the appearance of the active tab. Seems a simple enough problem at first (the appearance is modified using css) but I can't decide where to construct the menu.
Menu code:
<ul>
<li>item1</li>
<li id="active">item2</li>
</ul>`
As I see it there are 3 choices of when to retrieve menu items:
Upon receipt of HTTP Request to any controller for the first time store two arrays in the session - [url1, url2] and [item1, item2]. Then make the all the jsp pages form this into the above code. The jsp would have to know it's url to make against the [url1, url2] array in order to insert the active id.
Create the above html separately in each controller. Since a controller knows it's own url, it's simple to add the active id.
Create above html without any active id, store the html in the session and make either the jsp pages/controllers modify the html string.
None of these seem particularly appetising.
Does anyone have any advice on this?
Since a JSP is where all the HTML belongs, I'd go for option 1, but then with a List<MenuItem> instead of two loose arrays. You can find JSP's own URL by ${pageContext.request.requestURI}. The JSTL functions library should be helpful in determining whether the URL matches.
Related
I need to change the values displayed in the timetable based on the room I select from the dropdown list but I don't know how to do it.
The code for dropdown list is:
select option list
And on the same page, the code for the timetable:
timetable JSP page
Right now it shows all values from the database regardless of the selected room.
AJAX(Asynchronous Javascript and XML) can do this for you. AJAX allows for the updating of contents within an HTML object without reloading the page. W3Schools and the JQuery reference both have lots of helpful info on the matter.
I need to create a user interface where the content changes every time the user moves to a new page. However, the header and footer remains the same.
But, within the content, there is sometimes a left pane visible on some of the pages.
I'm not sure how can this be achieved since I'm new to using JSF.
Can someone please suggest a way?
Thanks!
You can achieve this by creating 2 different layouts and using for the correct layout
one with left rail
another without left rail
You need to look at JSF template with Facelets
Here are some links that you can refer
Link 1
Link 2
For the 'puzzly' composition of pages you need to use templating. Great overview can be found in the answer to How to include another XHTML in XHTML using JSF 2.0 Facelets?. The layout itself is HTML/CSS-related, so you need to check that out first.
If you want to produce one part of a template conditionally, there are two possibilities: to do that from a master template, or to do it from a template client. Of course, you could create many templates, as others recommend, but this is counterproductive and hard to maintain in my opinion.
If you want to render a part of template conditionally, you can include rendered="#{view.viewId = '...'}" attribute to JSF components in master template.
Alternatively, if you want to 'overwrite' the default part of a template, that for example has a left panel, just define the target area as an empty one in a template client like <ui:define name="left" />.
Let me explain the problem in very simple manner,
In my app, I've a JSP which contains 2 tiles.
Tile 1 is a jsp containing Search Form. Suppose it has only one search parameter that is set into ActionForm on submit action.
Tile 2 is containing the
DisplayTag showing all results which were stored in session
attribute (After we press submit form of Tile 1).
Now 1st page of display Table is working fine. But when I click on another page links (i.e. 2,3,Last) it loads the blank page. Problem is, Search param is not accessible from here so it can not be appended behind the requestURI. (Definitely, I return the zero records when no conditions appended on sql query.)
So question is, how can I access the property of another JSP (My search form - another tile) ?
My proposed solutions (but I am not satisfied):
I can put my Display Tag code into the same Tile of search form.
Works fine. But I want separation.
I can use hidden params into Tile 2. But it may result in duplicate params same as Tile 1.
Please let me know about some efficient solution as I am new with Struts Tiles concept.
Display tags works with form scope session.
Put the form that you are using to display the data in table in session scope.
i have jsp page with following code snippest...and it will show two radio buttons like car and bike
<bean:message key="label.vehicleType"/> : <html:radio value="Bike" property="vehicleType" idname="vehicleType" name="vehicleType">Bike</html:radio>
<html:radio value="Car" property="vehicleType" idname="vehicleType" name="vehicleType">Car</html:radio><br/>
If I select a radio button named as a car then it should show another two radio button like civic and BMW. or etc.
How can I achieve this with <logic:equal> tag of struts tab library.
I am new with struts tag library and javascript.
Thanks in advance.
<logic:equal> will be of no avail here. You need JavaScript for that. Go like this,
Set grid/div having sub-radios to invisible
Define a function to show the grid/div having sub-radios
Upon selection of radios, invoke the function you defined
Hints:
radio's onchange event can be used here.
In that function you need to validate some values before performing some real action.
You might need to hide the one and show the other one in case the selected radio is different.
If you are using struts 2.x
you can use
<s:if test="some condition">
your required code
</s:if>
You can't.
Everytime you use a JSP tag (Struts Tag extends JSPTag), the tags reads data from the servlet request or session. If you want to use the <logic:equal> tag, you will have to send your radio selection to your Struts Action, retrieve a list of data to populate, and retrn back to your forward and display the data.
If not, use Javascript. You will have to check if the property of your form is checked and enable a div that contains the list of cars that you so wish. This means that you will have to load all your relevant data beforehand and hide your div on onload().
Hope this helps.
Hi firstly i want to mention that i am aware of ajax based application and reuse of same page.
The requirement here is that, i want to have two separate pages one for login and other for the main application. Now, this is not because i just want it, but because i have very different layouts in the two pages which i am comfortable to put together with html elements and css directly in the page and then putting divs to contain dynamic html for gwt to populate.
Even in case of myfaces i have not seen application with same page for login and the main app page.
Anyways, the problem i am facing is, lets say i have two pages
Login.html with a div : div id="login"
Main.html with a div: div id="main"
i have declared both of them in my welcome file list in web.xml
Now i start with Login page fill the "login" div with gwt widgets and on click of a button
i am using following jsni code to redirect to "/Main.html?gwt.codesvr=127.0.0.1:9997"
private native void gotoURL(String url) /-{
$wnd.location.href=url;
}-/;
and then trying to populate the "main" div. But the behaviour as i noticed is that the application call the entry point again and it doesnt find any element as "login" and gives NPE.
Is there a way to do this? also to get rid of the "?gwt.codesvr=127.0.0.1:9997"?
Thanks
First, you don't want to add the ?gwt.codesvr=... stuff - it's related only to hosted (debugging of gwt) mode. You could use a relative url (for example simply "Main.html"). But since you can only have a single entry point, you need to either split the app into two client modules (two separate apps actually) or dispatch in your entry point according to the url (whether you've landed on Login.html or Main.html)
Second, what I would do in this scenario is have an empty html with no layout except a single div for the dynamic content as the only html page of the app. Then I would use 2 UiBinders - one for the main page, and one for login, and use a hash suffix in the url (using GWT's history event and management, and hyperlink widgets) to know where I am. Maybe you should read more in GWT's documentation on history and stateful apps. Try http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsHistory.html#stateful