フォーラム

ホーム » Liferay Faces » Liferay Faces - English

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
German Tugores
How to call button on JSF page from javascript
2012/04/15 16:05
答え

German Tugores

ランク: Junior Member

投稿: 33

参加年月日: 2012/03/01

最近の投稿

Hi everyone,

I'm developing a portlet using JSF + Icefaces, I'm trying to execute a method in a managed bean calling it from the javascript onclick event of a button.

This is the code in the xhtml page:

<ui:define name="component-example">
<ice:portlet styleClass="formRadioPrincipal">
<h:form id="formRadioP">
<h:panelGrid columns="1" styleClass="panelPrincipal">
<script type="text/javascript">
function exampleScript() {
document.getElementById("btnOculto").click();
}
</script>
<h:outputText value="Programas radiales que nos acompanan"
styleClass="tituloRadio" />
<h:outputText
value="Haga click en un departamento para ver los diferentes programas"
styleClass="tituloRadio2" />
<ice:graphicImage id="giMapa" ismap="true"
url="/css/images/mapaV2.gif" styleClass="imagenMapa"
usemap="#map1" />

<map name="map1">
<area shape="rect" coords="68,100,149,130"
onclick="exampleScript()" title='Salto' />
</map>

<h:commandButton id="btnOculto" value="BotonIr"
actionListener="#{principalMB.pruebaJS}"/>
</h:panelGrid>
</h:form>
</ice:portlet>
</ui:define>

And the code in the managed bean:

public void pruebaJS(ActionEvent e){
System.out.println("Same text in console");
}

Calling the exampleScript() function works... I've put an alert() to test it and the call to the function works well.

I think the problem is in the document.getElementById("btnOculto"), I don't know how I should reference the "btnOculto" button from javascript?
David H Nebinger
RE: How to call button on JSF page from javascript
2012/04/15 18:48
答え

David H Nebinger

Community Moderator

ランク: Liferay Legend

投稿: 11102

参加年月日: 2006/09/01

最近の投稿

All IDs defined in the basic page, when rendered, are fully namespaced to guarantee uniqueness. If you view the source on the generated page you'll see that your ID will end with btnOculto, but that will not be the actual id of the element.

Finding by ID is not going to work well because of this.
Neil Griffin
RE: How to call button on JSF page from javascript
2012/04/16 7:42
答え

Neil Griffin

LIFERAY STAFF

ランク: Liferay Legend

投稿: 2336

参加年月日: 2005/07/26

最近の投稿

You might want to check for JavaScript errors in a console like FireBug.

Here are some links to research for alternatives to getElementById():
http://stackoverflow.com/questions/4275071/javascript-getelementbyid-wildcard
http://stackoverflow.com/questions/1206739/find-all-elements-on-a-page-whose-element-id-contains-a-certain-text-using-jquer
German Tugores
RE: How to call button on JSF page from javascript
2012/04/16 14:29
答え

German Tugores

ランク: Junior Member

投稿: 33

参加年月日: 2012/03/01

最近の投稿

Hi again,

I checked the button's name with firebug, changed the name and it's working fine now! Thank you both for your replies.