• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Disable a text field after it's first use.. JSP + Struts

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In my code I have a jsp page, with text fields, buttons and a list box, myDetails.jsp, the information entered here is all
read/verified in ProcessMyDetailsAction.java. (I am also using Struts)

If the list box is populated, I want one of the text fields to be grayed out.(disabled or readonly)
(ie, after the first batch on info is entered, the details are displayed in the list box and the fields are empty, so more information can be entered, but I want the date textfield to be disabled, as I don't want to allow the user to change the date.)

I have a boolean variable set up in my java code, which is set to true if the list box is not empty,
and I am trying to read it on the jsp page to set the text field disabled property to true or false

here is the code i am using:
myDetails.jsp

<html:text name="myDetailsActionForm" maxlength="3" size="3" property="myDetails.textBox" styleId="TxBox" dsabled="#{ProcessMyDetailsAction.listBoxPopulated}" />

ProcessMyDetailsAction. is my Java class and
listBoxPopulated is my boolean variable, which gets set to true.

If anyone has any suggestions, I would be greatful..
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Inactive,

Welcome to JavaRanch. We're glad you're here!

I do need to remind you, though that the name you are currently displaying with your posts does not meet the requirements of the JavaRanch naming policy. Specifically, it requires that you use a first and last name that is not obviously fictitious.

Please Click on the My Profile link on the top of this page to change your publicly displayed name to one that meets these requirements.

This may seem trivial to you, but it's an important part of the JavaRanch culture and we appreciate your compliance with it.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"inactive", your display name was ok when I moved the post to this forum. Why did you change it?
 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm pretty familiar with struts 1.1, 1.2, and somewhat with 2.0. However I'm not familiar with the #{...} syntax you are using for you disabled attribute. It looks kind of like you're trying to use OGNL with a struts1 tag. What version of struts are you running? What is this #{} syntax?
 
John Brown
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tom,

Im using version 1.1, the syntax that I used was given to me by a mate who used it in another application. Im new to struts and JSP, so I thought this was normal code...

my program runs with this code, but it never picks up the true or false value from the class.

basically what I need is the correct code/syntax to access the variable that i have set up in my java class.
 
Tom Rispoli
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe in struts 1.1 that actions in struts 1.1 are single threaded, there for any variables you store in your action class will be shared by any one executing that class since only one instance of it exists. I think you'll want to move listBoxPopulated into your form class.

From your jsp section I'm assuming that myDetails isn't a collection of any sort, just an object. I'd put listBoxPopulated in meDetails, set it and then do this:

 
John Brown
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, tom, that has worked a treat..
 
John Brown
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have another question:

<logic:equal name="myDetailsActionForm" property="myDetails.listBoxPopulated" scope="request" value="true"> <html:text name="myDetailsActionForm" maxlength="3" size="3" property="myDetails.textBox" styleId="TxBox" disabled="true" /></logic:equal><logic:notEqual name="myDetailsActionForm" property="myDetails.listBoxPopulated" scope="request" value="true"> <html:text name="myDetailsActionForm" maxlength="3" size="3" property="myDetails.textBox" styleId="TxBox" disabled="false" /></logic:notEqual>


Using the same code, if I had another text box, is there a way that I can populate this text box, using the value of the fist one...

ie, when I do this:

<html:text name="myDetailsActionForm" maxlength="3" size="3" property="myDetails.textBox2" styleId="TxBox2" disabled="false" value="myDetails.textBox2.value"/>

It seems that any combination I've tried with the value="myDetails.TxBox.value" will always put the string "myDetails.TxBox.value" in the text box, what I want is the value in the textbox, (the string that the user entered in)

I have tried all sorts of combiniation, but I always get the string of what ever is inside the " " value="whatEverIsHere"

Am I going complete the wrong way about this...?
 
Tom Rispoli
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The second text field, I'm assuming that it has a corresponding property in your form class, you can just set the value of that property equal to the value that you have in the property for your first text field. If you'd prefere to do it in your jsp for some reason you can use the bean efine tag to put the value from the first text field into a scripting variable and then use a scriptlet to put this into the value attribute of the second text field. It would look something like this:



Usually you want to try to avoid scriptlets though, I use them, but I usually feel worse about my self in the morning when I do.
 
Listen. That's my theme music. That's how I know I'm a super hero. That, and this tiny ad told me:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic