Fórum

How do I change/define tag identifiers?

Mpumelelo Mthethwa, modificado 7 Anos atrás.

How do I change/define tag identifiers?

New Member Postagens: 2 Data de Entrada: 24/12/16 Postagens Recentes
Hello, everyone.

I just started portlet development using Liferay.

While working on my "Hello World" AJAX project, I noticed that in the markup there auto-generated id's for every element...

This is my source code
<!--?xml version="1.0"?-->

<f:view xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets">
	<h:head />
	<h:body>
		<h3>JSF 2.2 Hello World Example</h3>
		<h:form id="simpleForm">
			<h:inputtext id="input" value="#{simpleFormBean.inputText}" />
			<h:commandbutton value="Submit" action="view">
					<f:ajax execute="input" render="output"></f:ajax>
			</h:commandbutton>
			<br>
			<h:outputtext id="output" value="#{simpleFormBean.inputText}" />
		</h:form>
	</h:body>
</f:view>


and this is what's generated

<div id="_helloWorldExamplePortlet_WAR_jsfhelloworldportlet_" class="liferay-faces-bridge-body">
	<h3>JSF 2.2 Hello World Example</h3>
	<form id="_helloWorldExamplePortlet_WAR_jsfhelloworldportlet_:simpleForm" name="_helloWorldExamplePortlet_WAR_jsfhelloworldportlet_:simpleForm" method="post" action="http://localhost:8080/web/guest/home?p_auth=ItNb9NpN&amp;p_p_id=helloWorldExamplePortlet_WAR_jsfhelloworldportlet&amp;p_p_lifecycle=1&amp;p_p_state=normal&amp;p_p_mode=view&amp;p_p_col_id=column-1&amp;p_p_col_count=1&amp;_helloWorldExamplePortlet_WAR_jsfhelloworldportlet__facesViewIdRender=%2FWEB-INF%2Fviews%2Fhelloworldexampleportlet%2Fview.xhtml" enctype="application/x-www-form-urlencoded">
		<input name="_helloWorldExamplePortlet_WAR_jsfhelloworldportlet_:simpleForm" value="_helloWorldExamplePortlet_WAR_jsfhelloworldportlet_:simpleForm" type="hidden">
		<input name="javax.faces.encodedURL" value="http://localhost:8080/web/guest/home?p_p_id=helloWorldExamplePortlet_WAR_jsfhelloworldportlet&amp;p_p_lifecycle=2&amp;p_p_state=normal&amp;p_p_mode=view&amp;p_p_cacheability=cacheLevelPage&amp;p_p_col_id=column-1&amp;p_p_col_count=1&amp;_helloWorldExamplePortlet_WAR_jsfhelloworldportlet__jsfBridgeAjax=true&amp;_helloWorldExamplePortlet_WAR_jsfhelloworldportlet__facesViewIdResource=%2FWEB-INF%2Fviews%2Fhelloworldexampleportlet%2Fview.xhtml" type="hidden">
		<input id="_helloWorldExamplePortlet_WAR_jsfhelloworldportlet_:simpleForm:input" name="_helloWorldExamplePortlet_WAR_jsfhelloworldportlet_:simpleForm:input" value="" type="text"><input id="_helloWorldExamplePortlet_WAR_jsfhelloworldportlet_:simpleForm:j_idt5" name="_helloWorldExamplePortlet_WAR_jsfhelloworldportlet_:simpleForm:j_idt5" value="Submit" onclick="mojarra.ab(this,event,'action','_helloWorldExamplePortlet_WAR_jsfhelloworldportlet_:simpleForm:input','_helloWorldExamplePortlet_WAR_jsfhelloworldportlet_:simpleForm:output');return false" type="submit">
		<br>
		<span id="_helloWorldExamplePortlet_WAR_jsfhelloworldportlet_:simpleForm:output"></span>
		<input name="javax.faces.ViewState" id="javax.faces.ViewState" value="8697976959127719408:7894598210925314581" autocomplete="off" type="hidden">
	</form>
</div>


As you can see "_helloWorldExamplePortlet_WAR_jsfhelloworldportlet_:" is prefixed to every id that I defined in the source code.
I would like to know if there is a way to change this prefix into something cleaner like "helloWorld:" instead of this long auto-generated one.

Mpumelelo
thumbnail
Romeo Sheshi, modificado 7 Anos atrás.

RE: How do I change/define tag identifiers? (Resposta)

Junior Member Postagens: 35 Data de Entrada: 09/05/12 Postagens Recentes
this is the portlet namespace is like an unique id that ensures that the given name is uniquely associated with this portlet to avoids conflicts with other portlets. You can't change it its combination of war name and porltetname and if is istanceble the instanceId.

In your javascript just use this way


document.getElementById(<portlet:namespace>myId);
</portlet:namespace>


see the link Portlet Namespace
Mpumelelo Mthethwa, modificado 7 Anos atrás.

RE: How do I change/define tag identifiers?

New Member Postagens: 2 Data de Entrada: 24/12/16 Postagens Recentes
Hi, Romeo
I actually forgot to mention that I wanted to reference the id's later in my code.
This helps a lot.
Thank you for the reply!

Mpumelelo
thumbnail
Neil Griffin, modificado 7 Anos atrás.

RE: How do I change/define tag identifiers?

Liferay Legend Postagens: 2655 Data de Entrada: 27/07/05 Postagens Recentes
If you are using JSF, then you will want to use the Facelets version of portlet:namespace.