Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

Disabling form field based on value in form in Struts

Hi all,

          Based on a value in an Action Form, i want to disable fields.

          Heres the requirement, when from a page (say   a.jsp) i submit a form with hidden varibale "event". Now, if event = "new" i use the setEvent() method in the Action form to set it correspondingly. Then on the next page, based on this form value, i want to disable / enable a form field . Can i do that ??

          preferably using c-tag ? or any struts tag

  • 5
  • 3
1 Solution
Yes, you can do it.
You can use the struts logic tags http://struts.apache.org/userGuide/dev_logic.html
to wrap the jsp part that generate the html for that form field.
The easiest way to pass that info is to make the Action take that field value from the form
and put t in the http request attributes then to use the empty tag or the equal tag.
in your Action

request.setAttribute("shoud_display", shouldDisplay?"yes":"no");

then in your jsp

<jsp:useBean id="testString" scope="request" type="java.lang.String" />
<logic:someComparisonTag name="sould_display" value="yes">
<!-- display your elemet here e.g --> <input type=....
More info on bean and logic tags see: http://javaboutique.internet.com/tutorials/StrutsTags/
Also see http://j2ee.masslight.com/Chapter4.html (code/Chapter4/SimpleStruts/index.jsp)
letsbedecentAuthor Commented:
what is the id="testString"  here ??
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Oops, sorry:
<jsp:useBean id="sould_display" scope="request" type="java.lang.String" />
<logic:someComparisonTag name="sould_display" value="yes">

Is that more clear?
letsbedecentAuthor Commented:
id should be the form-name isnt it ?? can it be a field in that form too !! should display is only a field right
>> should display is only a field right
In the example above, yes.

>> id should be the form-name isnt it ??
in this case is the request attribute the action set -> request.setAttribute("shoud_display", shouldDisplay?"yes":"no");

>> can it be a field in that form too !
Yes, I think you can do something like that:
<jsp:useBean id="the_name_of_your_form" scope="request" type="the_class_name_of_your_form" />
<logic:someComparisonTag name="the_name_of_your_form.the_property_that_indicate_yes_to_display" value="the_value_that_indicate_yes_to_display">
The value of the name can be the bean name or nested property or index
letsbedecentAuthor Commented:
i have a hidden field in a form , on a.jsp
when submitted this form i go to a action handler and come to b.jsp

now on b.jsp also i have the same hidden field.

can i on b.jsp do the following

<logic:equal name="hidden_field" value="true">
  //Block that should get processed only when value is true
Yes, though when this value is a request paramter (and not a request attribute set by the struts action) then attribute "name" should be replaced with "parameter"

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now