aspose file tools*
The moose likes JSF and the fly likes keep the values of my input text fields Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "keep the values of my input text fields" Watch "keep the values of my input text fields" New topic
Author

keep the values of my input text fields

Fernando Guerrero
Greenhorn

Joined: Apr 26, 2011
Posts: 14

Hello

I have a input text that I want to activate only when I check a checkbox, the problem is that every time that I check or uncheck the checkbox, all the data that I have in my other input text disappears.

This is the secction of my code that generate the textfield and the checkbox and some buttons. What I am doing wrong?? Is there anyway to keep the data that is in my input text, (maybe using javascript or any option)?

Note: the code that defines my page, is inside in only one <form>

<BR />
<hutputLabel for="jobname" value="Would you like to assign a specific job name?" />

<h:selectBooleanCheckbox
id="jobname"
title="Job Name"
immediate="true"
valueChangeListener="#{reportRunner.checkNameChange}"
style="position:relative;left:10px;"
disabled="displayJobName()"
value="#{reportRunner.wantsName}"
onchange="this.form.submit()"
onclick="displayJobName()" >
</h:selectBooleanCheckbox>

<BR />
<h:inputText
id="userjobname"
value="#{reportRunner.userJobName}"
rendered="#{reportRunner.needName}"
style="display:none"
required="#{reportRunner.needName}"
valueChangeListener="#{reportRunner.userJobNameChanged}"/>
<h:message for="userjobname" styleClass="errorMessage"/>

<BR />
<BR />
<h:message for="run_report" styleClass="errorMessage"/>
<BR />
<h:commandButton type="button" class="button" disabled="true"
value="Previous"
action="#{reportRunner.previous()}"
/>
<h:commandButton type="submit" class="button"
value="Next Page"

action="#{reportRunner.nextPage()}"
/>

<h:commandButton class="button"
immediate="true"
value="#{messages['command.cancel']}"
action="#{reportRunner.goBack()}"
/>
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16139
    
  21

If your backing bean is Request scope, that's your problem. Use View Scope (JSF2) or session scope (JSF1+).


Customer surveys are for companies who didn't pay proper attention to begin with.
Fernando Guerrero
Greenhorn

Joined: Apr 26, 2011
Posts: 14

My scope was "session", I already changed it to "view" but I have the same problem. Is there any way to save the values of the inputText fields with javaScript and after I check the checkbox and all the fields are blank, write back those values into the fields? Do you require that I post the full page code?

Thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16139
    
  21

If reportRunner is in View scope or higher, the input fields should retain their value without requiring you to do anything at all. When a JSF page is displayed, the current values of the properties will be displayed automatically. That's Request Scope doesn't work - a whole new bean would have been created with whatever values the bean had initialized to.

You seem to be overcomplicating this operation. If you want an AJAX-style auto-submit of a value on enter, you don't need valuechangelisteners, since the normal JSF lifecycle is going to set the property for you. However, I have doubts about using raw JavaScript to submit the JSF form. You're better off using an AJAX-aware tagset such as RichFaces or IceFaces or use the JSF2 AJAX features.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: keep the values of my input text fields