File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Question on how to fix error on inputHidden field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Question on how to fix error on inputHidden field" Watch "Question on how to fix error on inputHidden field" New topic
Author

Question on how to fix error on inputHidden field

Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 386

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.

Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
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.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15957
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 386

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

Joined: Jun 21, 2005
Posts: 386

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

Joined: Jun 25, 2001
Posts: 15957
    
  19

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

Joined: Jun 21, 2005
Posts: 386

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

Joined: Apr 15, 2008
Posts: 198
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

Joined: Jun 25, 2001
Posts: 15957
    
  19

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

Joined: Jun 21, 2005
Posts: 386

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

Joined: Apr 15, 2008
Posts: 198
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

Joined: Jun 21, 2005
Posts: 386

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on how to fix error on inputHidden field
 
Similar Threads
How to access JSF hidden field value?
creating a table component dynamically
trying to populate hidden field on my JSF form using jQuery
Javascript/JSF problem after save
Please help - More specific question on JSF + jQuery