• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

keep the values of my input text fields

 
Fernando Guerrero
Greenhorn
Posts: 15
Eclipse IDE Java Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18100
51
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your backing bean is Request scope, that's your problem. Use View Scope (JSF2) or session scope (JSF1+).
 
Fernando Guerrero
Greenhorn
Posts: 15
Eclipse IDE Java Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18100
51
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic