Problem with Refreshing the data bound text fields
Folks,
First of all, this a GREAT product and I am moving my apps from Eclipse to Studio Creator. I am very impessed with it so far.
I am gone through most tutorials, but can't help resolve the problem that I am having. I have a page, that lists all the users in a table. When you click on any user, it opens up another page that lists the detail of the specific user you have clicked on. This a typical use in most web applications, right?
In the user detail page, I open it in "Read" only mode, by setting the "setReadOnly" to true for all text field components. Then users can edit it by clicking "Edit" button. Edit button just changes the "setReadOnly" to false, to allow editing. After editing, they can hit the "Save" button to save the changes. In the save button, I call this code:
publicvoid prerender(){
try{
userID=getSessionBean1().getUserID();
getSessionBean1().getWeb_userRowSetUserDetail().setObject(1,userID);
getWeb_userDataProviderUserDetail().refresh();
info("prerender: Refresh called");
}catch (Exception ex){
error("Error in userForm.prerender():"+ex.getMessage()+ex.getStackTrace());
log("Error in userForm.prerender():", ex);
}
setReadWrite();
}
public String btnSave_action(){
try{
getWeb_userDataProviderUserDetail().commitChanges();
getWeb_userDataProviderUserDetail().refresh();
info("Data Provider Refreshed in SAVE");
_readOnly=true;
form1.discardSubmittedValues("saveVForm");
info("User Updated New:"+userID);
}catch (Exception ex){
log("Error Description", ex);
}
returnnull;
}
public String btnEdit_action(){
try{
_readOnly=false;
//info("User ID Edt="+getSessionBean1().getUserID());
}catch (Exception ex){
error("Error in userForm.btnEdit_action:"+ex.getMessage()+ex.getStackTrace());
log("Error in userForm.btnEdit_action():", ex);
}
returnnull;
}
privatevoid setReadWrite(){
// Set read-only to true or false for all text fiels
this.btnEdit.setVisible(_readOnly);
this.btnSave.setVisible(!_readOnly);
this.user_id.setReadOnly(_readOnly);
this.user_email_client.setReadOnly(_readOnly);
this.user_email_office.setReadOnly(_readOnly);
this.user_fname.setReadOnly(_readOnly);
this.user_lname.setReadOnly(_readOnly);
this.user_id.setReadOnly(_readOnly);
this.user_password.setReadOnly(_readOnly);
this.user_password_conf.setReadOnly(_readOnly);
this.user_phone_cell.setReadOnly(_readOnly);
this.user_phone_cell_aac.setReadOnly(_readOnly);
this.user_phone_client.setReadOnly(_readOnly);
this.user_phone_home.setReadOnly(_readOnly);
this.user_phone_office.setReadOnly(_readOnly);
}
When the save button is clicked, the database is updated (as I can verify by looking directly into the database), but the data-bound text fields do not display the new value. YES, I am calling refresh() on data provider? I tried to call refresh in both "preRender()" and "Save" button action event, but that did not help either.
Please note that the save button also changes the "setReadOnly" back to TRUE for all text fields. That means, users view the page in Read-Only mode after saving. (They have to click on "Edit" button again to edit it). I discovered that if I do not set the text field components in "ReadOnly" mode, then they display the updated value of the fields. But if I change setReadOnly to TRUE, then they display the old values (before the save).
Any idea what I am doing wrong here?
Thanks
[5118 byte] By [
Sabir] at [2007-11-26 8:38:41]

# 1
I haven't found the answer as to why read-only components don't refresh from the bound data on redisplay. However, I did find out that the disabled property gives you the results that you want (if you don't mind the grayed out fields). Try:
this.user_id.setDisabled(_readOnly);
this.user_email_client.setDisabled(_readOnly);
etc.....
# 2
Yes, I confirmed it.
When you do textField.setReadOnly(true) >>> it displays the old value of the field (before editing).
When you do textField.setDisabled(true) >>> it displays the new value (which is what I want).
Sounds like a bug to me... Isn't it? setDisabled looks sort of difficult to read. Jeze, I was about to give up Eclipse, but sounds like Creator will be more stable at 3.0.
Thanks
Message was edited by:
Sabir
Message was edited by:
Sabir
null
null
Message was edited by: Sabir
Sabir at 2007-7-6 22:12:51 >

# 3
Hi. I also discovered that if you use the Standard JSF Text Field component, you get the behavior that you want. (p.s. you call setReadonly instead of setReadOnly). However, with the Std JSF Text Field, a read-only field is grayed out, similar to a disabled Text Field component from the Basic section of the palette.
# 4
Sabir,I found a related Text Field readonly bug (6391493). I added your information to that bug.
# 5
Thanks. Hopefully it will be fixed quickly. I am sort of stuck as I have tons of pages/form in my app that are going to use it. I have already spent a week on going nuts with it, trying all sorts of things, like calling erase(), refreshing dataprovider multiple times in different events, using rowsets instead of data provider, etc.
Message was edited by:
Sabir
Sabir at 2007-7-6 22:12:52 >

# 6
Is there a fix to this yet?Man creator would be great if it wasnt dog ass slow even on good hardware and full of bite you in the ass for hours bugs.
# 7
In regards to the bug mentioned in this thread (6391493).Go to http://developers.sun.com/prodtech/javatools/jscreator/downloads/hotfixes/index .jsp and search for 6391493
# 8
Here is my experience with it. I have three text boxes to be filled out. They are part of a virtual form with an add button as the submit. You can fill out the 3 and add them and a node is added to a tree component. When you click on a node in the tree component (the submit to another virtual form that the 3 buttons participate in) the text fields should be loaded with the values that they where added with. They will not display the values though...having nothing to do with read only. If I disable them before hand...they display the updated values. If I set their value at the top or bottom of prerender, they display the change...if I set the value in an if conditional that is hit (I have checked many times) in prerender, they will not display the values. If I set them in the tree handler anywhere, they will not display the values. This is very frustrating and is wasting tons of my time...I simply want to load the text fields based on the tree node that was clicked...I have messed with this for hours and it certainly does not work.
- Mark
# 9
> Here is my experience with it. I have three text
> boxes to be filled out. They are part of a virtual
> form with an add button as the submit. You can fill
> out the 3 and add them and a node is added to a tree
> component. When you click on a node in the tree
> component (the submit to another virtual form that
> the 3 buttons participate in) the text fields should
> be loaded with the values that they where added with.
Hard to tell from this explanation, but if the text fields do not participate in a virtual form, then they are not going to get updated when an action in the virtual form happens. Not sure this is your problem. Like I say, hard to tell from this explanation.
> They will not display the values though...having
> nothing to do with read only. If I disable them
> before hand...they display the updated values. If I
> set their value at the top or bottom of prerender,
> they display the change...if I set the value in an if
> conditional that is hit (I have checked many times)
> in prerender, they will not display the values. If I
> set them in the tree handler anywhere, they will not
> display the values. This is very frustrating and is
> wasting tons of my time...I simply want to load the
> text fields based on the tree node that was
> clicked...I have messed with this for hours and it
> certainly does not work.
Well, setting them in the tree handler won't work because the tree handler gets called in the page instance that handles the submit and not the page instance that renders the response.
Posting your prerender code might help. Also, your action handler.
>
>
> - Mark
# 10
Thanks for the info on the tree handler jetsons...I appreciate your comments as well sabir.
I have 3 text fields and a tree component. The 3 text fields participate in a virtual form that an add button submits (its the VF submitter). When you click add, a new node is added to the tree component. Now I want it so that when you click that node on the tree, the values you added are reloaded into the 3 text fields. I have tried making the tree a submitter and a submitter and participator for the virtual form that has the 3 text fields and the add button. I have also tried making a new virtform with the 3 text fields as participators and the tree as a submitter. The text fields never show the updated values though (although if I say textfield1().getText() the correct value will print to a message box..just not in the textfield.)
If I just put "getTextField().setText("mytext") in prerender to set the values of the text field, it works. However, if in prerender I say, "if the tree node is not a top level node, then put a the name I stored in sessionbean into text field1" then it will not show up. I can put info(sessionbean1.fieldName) right below where I try to set the textfield and it shows up correctly in the group message box.
Like I said I also tried setting the field directly in the tree handler, but you say that doesnt work so I will give up there.
- Mark
# 11
If I put the following in prerender it does not work. If i put it in the tree handler it does not work. The first IF statement checks whethere or not the selected node is a top lever node of tree. Execution gets in there because I see the INFO's. If I try and set the text before or after the with string literals, it works.
prerender() {
TreeNode selectedNode = getSelectedTreeNode();
if(selectedNode != null && TreeNode.getParentTreeNode(selectedNode) != getTree()) {
ItemDTO item = (ItemDTO)getSessionBean1().getItems().get(selectedNode);
if(item != null) {
itemNameForEdit = item.getName();
info("ItemName:" + getItemName().getText());
info("set :" +item.getName());
} else {
info("null item");
}
}
}
# 12
Let me try that again with correct code:
If I put the following in prerender it does not work. If i put it in the tree handler it does not work. The first IF statement checks whethere or not the selected node is a top lever node of tree. Execution gets in there because I see the INFO's. If I try and set the textfield before or after the IF statement with string literals, it works.
prerender() {
TreeNode selectedNode = getSelectedTreeNode();
if(selectedNode != null && TreeNode.getParentTreeNode(selectedNode) != getTree()) {
ItemDTO item = (ItemDTO)getSessionBean1().getItems().get(selectedNode);
if(item != null) {
itemNameForEdit = item.getName();
getTextField1().setText(itemNameForEdit);
info("ItemName:" + getTextField1().getText());
info("set :" +item.getName());
} else {
info("null item");
}
}
}
textField1 will not show itemNameForEdit but the messagegroup will show:
itemName: name
set: name
lately it started getting doubled:
itemName: name itemName: name
set: name set: name
# 13
CandideEC,
My suggestion is to create a new post with your question. The reason why is because I don't think I can help you and this thread is old. A new post might get new eyes.
What I have observed:
o I cannot recreate your problem. I don't know what gets put into your session properties so that I can recreate a similar scenario. All my scenarios work ok. Nor do I know what component props are bound or how they components participate in virtual forms. A much simpler scenario would be easier to work with. when you create your new post, if you could narrow down the scenario a bit that would be good.
o itemNameforEdit appears to be global (I don't see it declared in the prerender method). What type is it?
o Do you possibly need to call discardSubmittedValues? See http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/ins erts_updates_deletes.html
o Are you running into known bugs with the Tree component? Do you know that in order for getSelected to work you have to have the immediate property set? And that getSelected won't work if the client's cookies are turned off? I don't think these are related but I thought I should mention it.
Sorry I was not able to help
