This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to hide and show contents with struts2 div tag

 
Harini Kaushik
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9527
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Harini Kaushik
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please start new threads for new topics--thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic