wood burning stoves 2.0*
The moose likes Struts and the fly likes how to hide and show contents with struts2 div tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to hide and show contents with struts2 div tag" Watch "how to hide and show contents with struts2 div tag" New topic
Author

how to hide and show contents with struts2 div tag

Harini Kaushik
Greenhorn

Joined: Aug 08, 2008
Posts: 15
Hi All,

I want to show and hide some tags based on the selection in the drop down list.

The code in jsp

How can i go with the javascript show_details() method for showing the div 'box' on selecting 'W' and 'box1' on selecting 'S'?
How can we use Dojo tags to accomplish the same?
I tried using JQuery for the same.I could use it with html tags and it was working but not with struts 2 tags.

How can I use the javascript in struts2 using Dojo or Jquery?
Any tutorials available???
Please guide me!!!

Appreciate any help!!!

Thanks,
Harini
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

This seems to be a simple problem to me. In the show_detail method, you can call document.getElementById('Register:Workselect').selectedIndex (you can also use document.getElementById('Register:Workselect').options with it) to find out which element is selected. Then depending upon that you can make the divs visible or hidden using document.getElementById('box').style.display = 'none' or 'block'.

(As far as I remember, struts ads the form name to the id of form fields in the form but I don't remember if struts uses : between them or something else)


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Harini Kaushik
Greenhorn

Joined: Aug 08, 2008
Posts: 15
Thanks for your reply Ankit. I 'll try that.
but now the problem is that I'm not able to apply cssStyle for s:div inside s:form itself,,

Like for example,, if i give the div tag without the enclosing form tag its cssStyle gets applied.
Means the whole <s:textfield> tag is not displayed


but if i enclose it inside the form its not working..



Any idea on how to apply cssstyle for the s:div tag inside s:form tag?
Is it possible to hide the whole textfield tag with the div that is enclosed inside the form.?


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I don't think it's valid HTML to have a DIV nested in a FORM (that may depend on which version of HTML you're targeting, though).

It's actually a bit problematic to access the table row of a form element and its label at the moment. That may have been (at least partially) addressed in the "css_xhtml" theme, and I'm planning on adding it to the "xhtml" theme (and "css_xhtml" if it's not already there) but haven't had a chance.

Your quickest solution might be to just take whichever theme you're using and modify it to include suitable "id" attributes on the table rows (or DIV elements if you're using "css_xhtml"), or wait for the next release (I think I missed 2.1.7).
Harini Kaushik
Greenhorn

Joined: Aug 08, 2008
Posts: 15
Thanks for your reply David.

Actually it works if i enclose it just within normal <form> </form> tag.
but not inside <s:form> </s:form> tag.

It will not work with struts tags is it?
Any idea!!?


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What theme are you using?

If you're using the default "xhtml" theme then using S2 form input elements without the <s:form> tag will produce *completely* invalid HTML, whereas embedding the div tags inside the table is invalid but might work.

Without knowing what theme you're using it's impossible to tell you much more than that.
Harini Kaushik
Greenhorn

Joined: Aug 08, 2008
Posts: 15
Yeah actually i was using the default theme till now and i was trying with Dojo and JQuery tags.
It dint work.

I tried giving theme as "ajax" and its working fine with JQuery.
Tat shows my ignorance

Thanks a lot David for your help in this regard
Aruna Ponaka
Greenhorn

Joined: Dec 08, 2009
Posts: 9
I have a struts form, depending on the select option the div should show/hide and the div contains textfields. Am using jquery for show/hide div. The textfields within div are not behaving right. When I keep the theme as "simple", The textfields hide and on option selection they show up but the label to the textfield does not show up and the alignment is bad. If the Theme is "ajax" or "qxhtml" or "xhtml", the textfields hide/show properly but the labels of textfields do not hide. Is there a good compromise between the layout and the hide/show functionality?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please start new threads for new topics--thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to hide and show contents with struts2 div tag