Search code examples
javahtmljspstruts2ognl

Using Struts tag within HTML tag for hiding/displaying table


I want to hide a table on load of a page and hide it on click of a button on that page.I have created a property of type String in Action class named as "displayTablle" and assigned it a value "none" by default.So that when this page is opened by calling action,this property will be none and following code used in table tag should hide the table:

<table border="true" id="dataTable" style="display:"<s:hidden id="disTable"   name = "displayTable" value="%{displayTable}"/>;"> 

<s:submit value="Fetch Data" align="center" action="displayDataAction" />

Then on click of Fetch Data button, I am setting value of this property to blank string i.e " ", so that table will be displayed, But I am stuck with the syntax and <s:hidden> is not getting bound properly, as when I open the page, last part of the table tag's code i.e ;"> is getting printed as is.

Can anybody suggest, what should be the right syntax to bind s:hidden in html table tag? Can we do it like this?


Solution

  • The property tag is used to write text to the JSP page. It has also option for unescaping that text, but it's not required in your case.

    <table border="true" id="dataTable" style="display:<s:property value='%{displayTable}'/>;">