aspose file tools*
The moose likes Struts and the fly likes Disable a text field after it's first use.. JSP + Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Disable a text field after it Watch "Disable a text field after it New topic
Author

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

John Brown
Greenhorn

Joined: Sep 03, 2008
Posts: 6
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..
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61599
    
  67

"inactive", your display name was ok when I moved the post to this forum. Why did you change it?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
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

Joined: Sep 03, 2008
Posts: 6
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

Joined: Aug 29, 2008
Posts: 349
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

Joined: Sep 03, 2008
Posts: 6
Thanks, tom, that has worked a treat..
John Brown
Greenhorn

Joined: Sep 03, 2008
Posts: 6
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

Joined: Aug 29, 2008
Posts: 349
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Disable a text field after it's first use.. JSP + Struts