• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question on how to fix error on inputHidden field

 
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In trying to process an <h:inputHidden...> field I got an error:

/index.jsp(200,6) '' Illegal Syntax for Set Operation


Here is my HTML inputHidden field:



I passed in the value successfully from my jQuery code that I wanted to pass into my backing bean which was the value "D". The generated HTML does show that the value property of this inputHidden field was populated successfully.

However, I just learned from the IBM JSF list server the following:

"When you submit the page, all JSF input components, including h:inputText, would process their submitted values and will try to update their 'value' object with the submitted value. Your inputHidden fails to do so, because it does not have a valid value object."

My question is, how do I assign a value object to the value of what I'm passing currently to the value field in the inputHidden field from my jQuery javascript code?

Here is the code in my jQuery where I populated the value "D" that I mentioned above:



Any help/direction would be appreciated. Thank you.

 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure if I understand your problem correctly but I do see a couple of problems with your input field. First of all the input field has no visible value so there is no need to have separated start and end tags. And second of all the input fields value attribute is used to to tell JSF from what property in what bean are you planning to take the initial value from and eventually update when you send the form.

Like this
So after you send the form the value you mentioned 'D' will go to backingBean property.
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The value EL is the location property reference in the backing bean that the inputHidden will update, Because this is an input control, it's required to treat it as such, even if you actually have no intention of ever referencing the value in the backing bean.

There are 2 solutions:

1. Define a property in your backing bean and supply set/get methods. Ignore the property value if it amuses you.

2. Don't use the JSF inputText tag, use the raw HTML input type="hidden" tag instead. That way JSF won't try to update the backing bean.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IIari,

Thanks for your time and your reply. Basically, in my javascript I was grabbing the value that the function created which is a string value "D" and puttting it into the value="" property in my <h:inputHidden id="selectedFacilityCodeValue" value=""></h:inputHidden>

Since this is a hidden field and not an <h:inputText...> field then how do I get the value from my javascript and populate the property in my backing bean?

That is primarily what my problem is. How do I do that in my javascript and if so, how do I associate the backingbean.property with the value from my javascript?

Hope that makes more sense. Thank you, again.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim - thanks for the reply. I will try that.

Does the hidden value ID then go on the request and then I can pull it from the request ParameterMap to get at the value through the FacesContext?

I have to get the value to the backing bean in some way. Therefore the reason for my question.

Thanks again.
 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That would be the long way around. If you define a property, just use the property's value. No need for long complicated, non-portable JSF code.

There's no special magic here. When you map a JSF input control to a property, the page is displayed with its current value (as retrieved by the "get" method), and on the submit, the value pushed to the property via its "set" method will be whatever the current control value is. If you want to set that value via JavaScript (jQuery or otherwise) instead of manually typing data, JSF won't care. And hidden text controls were never considered to hold immutable values, even in straight HTML. Only hidden ones.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So in my backing bean I have:

String selectedFacilityCodeValue

getSelectedFacilityCodeValue
setSelectedFacilityCodeValue

The id for the hidden field is: selectedFacilityCodeValue

And you're saying that the backing bean will pickup the value in the hidden field based ID of the hidden value? Sorry I just need to see code and wanted to confirm that I'm understanding you correctly.

I just need to know how I'm connecting the value in the hidden field with the property in the backing bean.

Thanks.
 
Ilari Moilanen
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The id of the input tag is not sent to server and it does not define what property is defined in the backing bean.

It may be confusing but you define the property in the value attribute like I showed you in my first reply. So if the value attribute I have is value="backingBean.property" that would mean that I have a backing bean with a property named property.

Like this
 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, to be pedantic about it, "selectedFacilityCodeValue" is the property name. The "id=" attribute on the XML is a different critter entirely. But yes, if you set a 'value=#{mybean.selectedFacilityCodeValue}" on the jsf inputHidden control, that property will be posted with whatever value its corresponding HTML control on the webpage contains. Subject, of course to the usual backing bean property validation and conversion constraints.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apparently/obviously I'm confused.

I'm populating, via javascript, the value attribute of the hidden field with a value of "D":



Now, per Tim, I'm not going to use the JSF inputHidden component but the straight HTML code for the input type="hidden"... and I am giving an example of what js code is doing in populating the value attribute:



Question - how do I get the value="D" to my backing bean property "selectedFacilityCodeValue"?

Sorry if I've confused the entire issue. Tim states that I do not have to use the request parameters because that is the long way around but does not show how to get the value from javascript to the property. That is what I need to know.

Thanks.

 
Ilari Moilanen
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, now I see what you meant

Tim said that you can do it with normal html input if you like but IF you do it with normal html input THEN you have to catch the value by yourself from the request parameters!

If on the other hand you do it the JSF way (as Tim and I described in our last posts) then the value goes to the backing bean automatically.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. I just tested and it went in. I was getting a NULL value initially. Thank you and Tim for your patience and help.

Regards.
 
And then the entire population worshiped me like unto a god. Well, me and this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic