how to select radio button depends on condition in jsp with struts - java

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.

Related

Using ajax with my JavaScript to store a value while handling events?

I have a jsp, that contains a <button> with an onclick event and a list of <input type="checkbox"/>s that are being handled with my AjaxScript.js (also mentioned in the next paragraph). I ultimately want to use the Java Bean to call a method that'll handle the functionality while processing the event asychronously.
My solution at this point is to store a list var in my js that I refer to, when the buttons onclick is called. The trouble I'm having is in my JSP, where should/can I call the Java method from with a SessionBean variable correctly? Also, if I use the addEventListener to handle the onclick, how do I get it with the load correctly so it is only handling with the checkbox 'on' click and 'off' click with a very interactive page?

How do we navigate from 1 page to another in GWT

I am building a project in GWT and the project requires navigation from one page to another when a button is clicked. How do I do this? Or should I simply write the entire code in the same class file? I know there has to be a way of navigation.
How should I achieve page navigation in GWT?
You should look at GWT Platform
With this library, you can define places. When the user clicks on a button, you just reveal a new place.
In addition, this framework allows you to handle the lifecycle of your GWT components and do some code splitting : page 1 and page 2 can be compiled in 2 different js so that you only load the one you need.
it is also a (and mainly) a MVP framework, like gwt-presenter.
You can do Page navigation through History mechanism of GWT. Here are the steps you should follow:
Add a history string to an iframe of your host page:
Register a ValueChangeHandler that will receive an event of history (page) change. Within this handler you need put a logic that displays the new page.
For example, History.addValueChangeHandler(object of subclass of HistoryHandler);
After doing this whenever you need to navigate to another page do the following: History.newItem("history string of your page to be displayed");

Struts 1.x Java- form data gets lost

My problem is, I have a jsp page(say one.jsp) which contains fields(eg: name, city etc) and after I hit on submit button, a new jsp(two.jsp) is opened in a new tab it contains a radio button 'I accept'. when the user now clicks on this radio button, the business logic should get executed. But the problem is the form values of one.jsp(values of name, city etc) are lost.
opening of the new jsp page using window.open is not a new request to the server. I wonder why the form values are lost.
Since you are using Struts 1 ,Please make sure you declare the fields whose values are to be retained in the ActionForm of the "I Accept" action and do set the values as Form2.setName(Form1.getName());
Or You have to maintain these values as hidden fields in two.jsp.
I guess the above two points would help you !
You are going from from one jsp to another jsp.But form values processed from one jsp to another jsp only>but you are expecting that values to submit form.
So you can do one thing you have get that values using request.getParameter();
and then you have to set that values to which you need.

Wicket, how to lazy-load DropDown choices on click?

I have a lot of DropDownChoice components with many items in a form, and on loading the form, I'd like to display only the saved selected options. When the user clicks on a DropDownChoice, I'd like to ajax-load the full item list on the fly.
Can this be done?
Add a OnChangeAjaxBehavior to your dropdown-component. Override the onUpdate-method and add another component to the target. The chosen value of the dropdown-component is inside its model.
Update: Okey, I think I know what you're trying to achieve. Add an AjaxFormComponentUpdatingBehavior to your dropdown component with "onclick" as constructor parameter.
Override the onUpdate-method and add your dropdown component to the target. Before you do that, update the dropdown model, so that it now contains all values.
If you have a lot of options to show then using <select> is not the best option.
Better check http://ivaynberg.github.com/select2/ or http://livedocs.dojotoolkit.org/dijit/form/FilteringSelect or any other JS based component which can load options on demand via Ajax.
Maybe you could go with the AjaxEditableLabels... Using the AjaxEditableChoiceLabel from Wicket Extensions, you'll get a compponent that displays the current value as a Label until clicked and the changes to a DropDownChoice via Ajax. That should be pretty much like the solution you're looking for.

JSP menu design advice

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.

Categories

Resources