voyent
Failure to Rerender Appropriately: What am I doing wrong?  XML
Forum Index -> General Help
Author Message
StormTAG

Joined: 30/Sep/2008 00:00:00
Messages: 15
Offline


As a preface, I'll note that I've been using IceFaces for about a month now and have found it supremely easy and intuitive, and my co-workers/bosses are all amazed with the quality of our new pages.

That said, I have a very specific and isolated issue. I'm not sure what is so different about this little chunk of code but here goes.

Users can edit and update locations by clicking on an edit button or for new locations, clicking a new location button. This gets sent to an action listener, which updates my backing (session scoped) bean with the appropriate values. The page is then re-rendered and the previously un-rendered section is rendered. When the user is done they either hit submit, to confirm their changes, or cancel, which does nothing. In both cases, the bean is updated and the expression that rendered the edit section is changed back and the edit section disappears.

All this works fine! However, when I try to edit a different location, or create a new one, the values from the previous entry appear in the text input/selectOneMenu fields. The bean is storing the correct value and is seemingly not being updated to these fields. However, some of the properties (a pair of lists which are rendered in data-tables, which I've omitted below) are rendered correctly.

It seems like the HTML is keeping the previous values without updating to the backing bean as I would expect. I'm sure the fields are being re-rendered (or at least, they're not on my screen and then on my screen again later!) I've tried several ways to fix this:

1) Setting the value to a property's properties (value="#{myBean.location.name}")
2) Setting the value to a property and then setting them in the submission function (value="#{myBean.locName}")
3) Binding the elements to the appropriate objects in the bean and directly calling the setValue() method (binding="#{myBean.locNameBind}" ... getLocNameBind().setValue(...) )

None of these seemed to force the system to re-render correctly. They all do exactly what I expect them to do except for not clearing when a new location is prepped for edit.

I'd appreciate any help I can get! Below is the relevant jspx markup and bean code.



The relevant bits of the JSF managed session scope BYOCPMain bean...
Code:
 protected _Location location = null; //With appropriate getter/setter
 
 public void changeLocation(ActionEvent e) {
       _Location newLoc = (_Location) e.getComponent().getAttributes().get("locationToChange");
       if (newLoc == null) {
          newLoc = new _Location();
          newLocation = true;
       } else {
          newLocation = false;
       }
       prepLocationForEdit(newLoc);
    }
 
 public String submitLocation() {
       //Update the location data, persist it and update the view
       if (newLocation) {
          //TODO: Add persistance
          availableLocations.add(new LocationWrapper(location));
          newLocation = false;
       }
 
       location = null;
       return null;
    }
 
 public String cancelLocation() {
       location = null;
       return null;
    }
 


The relevant bits of the JSPX.
Code:
 <ice:form>
 ...
 <ice:commandLink partialSubmit="true"
                                                actionListener="#{BYOCPMain.changeLocation}"
                                                disabled="#{BYOCPMain.editing}">
                                  <f:attribute name="locationToChange" value="#{loc.loc}"/>
                                  <ice:outputText value="Edit"/>
                               </ice:commandLink>
 ...
 <ice:commandButton value="New Location" immediate="true"
                                               disabled="#{BYOCPMain.editing}" 
                                               actionListener="#{BYOCPMain.changeLocation}"/>
 ...
 </ice:form>
 
 <ice:form>
                   <ice:panelGroup styleClass="contentBox" rendered="#{BYOCPMain.location != null}">
                         <ice:outputText value="Location: " styleClass="required"/>
                         <ice:inputText id="locationName" required="true" partialSubmit="true"
                                        value="#{BYOCPMain.location.name}" 
                                        styleClass="wide"/><br/>
                         <ice:message for="locationName" styleClass="warnStyle"/>
                      </ice:panelGroup>
                      <ice:panelGroup styleClass="optionItem">
                         <ice:panelGrid columns="3">
                            <ice:outputText value="Address: " styleClass="required"/>
                            <ice:inputText id="locationAddress" value="#{BYOCPMain.location.address}" required="true" partialSubmit="true" size="15">
                               <f:validator validatorId="AddressValidator" />
                            </ice:inputText>
                            <ice:message for="locationAddress" styleClass="warnStyle"/>
                            <ice:outputText value="City: " styleClass="required"/>
                            <ice:inputText id="locationCity" value="#{BYOCPMain.location.city}" required="true" partialSubmit="true" size="15"/>
                            <ice:message for="locationCity" styleClass="warnStyle"/>
                            <ice:outputText value="State/Province: " styleClass="required"/>
                            <ice:selectOneMenu id="locationState" value="#{BYOCPMain.location.state}" partialSubmit="true"  required="true">
                               <f:selectItems value="#{StateList.selectItems}"/>
                            </ice:selectOneMenu>
                            <ice:message for="locationState" styleClass="warnStyle"/>
                            <ice:outputText value="Postal Code: " styleClass="required"/>
                            <ice:inputText id="locationPostal" value="#{BYOCPMain.location.postal}" required="true" partialSubmit="true" size="10">
                               <f:validator validatorId="ZipCodeValidator"/>
                            </ice:inputText>
                            <ice:message for="locationPostal" styleClass="warnStyle"/>
                            <ice:outputText value="Phone Number: " styleClass="required"/>
                            <ice:inputText id="locationPhone" value="#{BYOCPMain.location.phone}" required="true" partialSubmit="true" size="15">
                               <f:validator validatorId="PhoneNumValidator"/>
                            </ice:inputText>
                            <ice:message for="locationPhone" styleClass="warnStyle"/>
                            <ice:outputText value="Fax Number: " styleClass="required"/>
                            <ice:inputText id="locationFax" value="#{BYOCPMain.location.fax}" required="true" partialSubmit="true" size="15">
                               <f:validator validatorId="PhoneNumValidator"/>
                            </ice:inputText>
                            <ice:message for="locationFax" styleClass="warnStyle"/>
                         </ice:panelGrid>
                      </ice:panelGroup>
                      <ice:panelGroup styleClass="optionItem centered">
                         <ice:panelGrid style="margin:auto;" columnClasses="r,l" columns="2">
                            <ice:commandButton value="Submit" action="#{BYOCPMain.submitLocation}"/>
                            <ice:commandButton value="Cancel" action="#{BYOCPMain.cancelLocation}" immediate="true"/>
                         </ice:panelGrid>
                      </ice:panelGroup>
                   </ice:panelGroup>
                </ice:form>
 
oleczek

Joined: 24/Jan/2007 00:00:00
Messages: 92
Offline


Not sure if this will help but check


http://www.icefaces.org/JForum/posts/list/7071.page

Olek
Galilei

Joined: 27/Aug/2007 00:00:00
Messages: 14
Offline


Try using one form first. A Action updates only the form containing it.
StormTAG

Joined: 30/Sep/2008 00:00:00
Messages: 15
Offline


oleczek wrote:
Not sure if this will help but check


http://www.icefaces.org/JForum/posts/list/7071.page

Olek
 


This led me to the right answer. Thanks!

My problem apparently was with the cancel button, which had immediate="true". The UIInput components were maintaining their values after I cancelled, despite me updating the backing bean data, so when they were rerendered, they showed the old values.

Binding to the form and using the recursive UIInput clear method detailed in that post seems to have fixed it.

Thanks again! I feel silly now that I couldn't find that post on my own.
stpro

Joined: 13/Sep/2007 00:00:00
Messages: 3
Offline


Hi guys and gals,
I don't know if this is related but there was a problem I was having that is at least similar. I am using icefaces and tomcat.

I had a form that was basically a bunch of input text boxes, and an "add" button. Lets say it was a form to add contacts to a database.
Below was a table of contacts. If you wanted to edit an existing contact, you would click on it in the table and that contact's details would populate the input text boxes above where you edit them and click add (or save).

The problem I was having was that the input box was displaying the backing beans value but instead was displaying the last value that was displayed in the input box.
For example, lets say you had three input boxes, one each for first name, surname and age. Lets say you had selected a contact Joe Bloggs age 18.
Lets say you then select a different contact, Jane Doe age 47.
Although the backing bean would have values for Jane, the web form would display values for Joe.

I found that the solution lay in the method for selecting a contact from the table.
If I used a RowSelector to select the contact from the ice:dataTable, it would do as above, whereas, if I used an actionListener (with a commandLink), it would update the values as required.

Anyway, I hope this helps someone
[Email]
 
Forum Index -> General Help
Go to:   
Powered by JForum 2.1.7ice © JForum Team