Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Andew Jardine
Prefix on Input Fields in generated code?
July 9, 2014 7:40 AM
Answer

Andew Jardine

Rank: Regular Member

Posts: 193

Join Date: December 22, 2010

Recent Posts

Hey Guys,

I have a question. For some reason when I look at the generated (HTML) code with a tool like firebug or inspector I see that my input fields have names that do not match what I assigned them in the xhtml. The name seems to have three parts -- a random ID (something like A1234) then the name of the form it is a member of and then the name I gave the field so that I end up with something like --

<input type="text" name="A1234:myform:myinputfield" />

... can someone tell me what the A1234 part is, and how I can retrieve it on the server side?
David H Nebinger
RE: Prefix on Input Fields in generated code?
July 9, 2014 7:51 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6738

Join Date: September 1, 2006

Recent Posts

You shouldn't have to worry about them...

When rendered in a unified page, your simple form field name "myinputfield" potentially could conflict with other entity names on the page (i.e. if someone drops 2 of your portlets on the same page, the two forms have the same field name and would be an issue, or if some other developer(s) have forms w/ that name you have the same name conflict but no way to fix or even know about it).

Liferay will 'namespace' the field name so it will be unique on the page, normally this will be something related to the portlet id. In jsf the mechanism is a little different, but the end result is the same. The field is renamed from where it appears on the rendered html.

But this marshalling is the responsibility of jsf, and it is both ways. Your references on the backend code can just use "myinputfield" and the namespace prefix stuff will be stripped off for you.
Neil Griffin
RE: Prefix on Input Fields in generated code?
July 9, 2014 8:03 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2060

Join Date: July 26, 2005

Recent Posts

I agree with David -- you shouldn't have to worry about it unless you are writing client-side JavaScript that needs to reference the "id" of an element in the DOM.

The "A1234" part is a short form of the portlet namespace, optimized by Liferay Faces Bridge. However, versions of Liferay Faces Bridge designed to be used with Liferay Portal 6.2 (like 4.2.0-m1 and 3.2.4-ga5) are no longer able perform the optimization. Instead of something like "A1234" you will see something like "portlet_foo_WAR_fooportlet"
Andew Jardine
RE: Prefix on Input Fields in generated code?
July 9, 2014 8:10 AM
Answer

Andew Jardine

Rank: Regular Member

Posts: 193

Join Date: December 22, 2010

Recent Posts

Hey David,

Thanks for getting back to me. I thought it might have something to do with the name space. I am asking this on behalf of a client who is using the bridge -- personally I tend to stick with MVCPortlets. I did check the liferay-portlet.xml and found that the portlet is not instanceable but to your (and Neil's) point that wouldn't prevent a whole other portlet on the page from causing headaches.

I'll double check with him on how he is retrieving the value server side. He had told me that he was unable to get the value on the server and suspected that the name he was using (eg. myinputname) was not the correct reference. I'll check and report back.
David H Nebinger
RE: Prefix on Input Fields in generated code?
July 9, 2014 8:19 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6738

Join Date: September 1, 2006

Recent Posts

If they're trying to process the form via a simple servlet, then they will have to deal w/ the portlet namespace removal themselves. JSF will handle the stripping for you, but if you're not using JSF then the stripping is up to you. Normally you can find the value by looking for a parameter that ends with DELIMITER + FIELDNAME where DELIMITER is the separator (I think the norm is a colon but it could be a period or something) and FIELDNAME is the field you're looking for.