Foren

Prefix on Input Fields in generated code?

thumbnail
Andew Jardine, geändert vor 9 Jahren.

Prefix on Input Fields in generated code?

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
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?
thumbnail
David H Nebinger, geändert vor 9 Jahren.

RE: Prefix on Input Fields in generated code?

Liferay Legend Beiträge: 14916 Beitrittsdatum: 02.09.06 Neueste Beiträge
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.
thumbnail
Neil Griffin, geändert vor 9 Jahren.

RE: Prefix on Input Fields in generated code?

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
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"
thumbnail
Andew Jardine, geändert vor 9 Jahren.

RE: Prefix on Input Fields in generated code?

Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
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.
thumbnail
David H Nebinger, geändert vor 9 Jahren.

RE: Prefix on Input Fields in generated code?

Liferay Legend Beiträge: 14916 Beitrittsdatum: 02.09.06 Neueste Beiträge
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.