-1

So I have developed a web app using JSF and have names and ids for my buttons/text input fields. But when I open up the web page and do Inspect Element, I do not see the corresponding name/id for each field. Instead, I see this: j_idtx:j_idty, where x and y are some numbers, such as: j_idt2:j_idt5.

I do not see this problem when developing using JSP instead of JSF.

Here is a sample code that sets a button to a certain name:

<ui:composition template="WEB-INF/templates/BasicTemplate.xhtml">
    <ui:define name="content">
        <h:form>
            <h:commandButton action="login_page" value="Login" name="loginButton"></h:commandButton>
            <br></br>
            <br></br>
            <h:commandButton action="registration_page" value="Register" name="registrationButton"></h:commandButton>
        </h:form>
    </ui:define>
</ui:composition>

So how can I make sure my names and ids appear correctly?

Thanks

Viratan
  • 503
  • 3
  • 9
  • 19
  • you have to add attribute on form "prepand=false". If you have form with id="formID", your elements inside your form will have prepand form's ID followed with collon, e.g. child element will have id="formID:childID". some jsf components generate their own code, and they generate ids too. Better stick with classes – Kristijan Iliev Jun 22 '15 at 13:30
  • Ok what about for names? I'm mainly going by names instead of id. Adding prepand="false" does not change the names. – Viratan Jun 22 '15 at 13:51
  • I suggest you to read this post http://stackoverflow.com/questions/15893876/how-to-specify-name-attribute-in-hinputtext – Kristijan Iliev Jun 22 '15 at 13:54
  • @BalusC, it was a poor word choice, never mind that. I thought it was a problem. So how can I explicitly give the buttons a name? – Viratan Jun 22 '15 at 14:05
  • Guess I'll be using the client IDs then. – Viratan Jun 22 '15 at 14:50
  • @Viratan if it helped upvote and accept ;). – Ced Aug 26 '15 at 02:26
  • possible duplicate of [Cannot find component with expression "foo" referenced from "bar" - contains unknown id "foo" cannot locate it in context of component "bar"](http://stackoverflow.com/questions/8634156/cannot-find-component-with-expression-foo-referenced-from-bar-fajax-con) – Ced Aug 26 '15 at 14:09

1 Answers1

0

When you do not specify an id, it will be automatically generated. You did specify an id, however you didn't for the form from with those elements are children off. Thus the form id's auto generated by jsf will be added to your ID in the final version such as j_idt2:myid.

Add an id to the form, and if you want to find the element with its id you have to do: "form:myid"

Like this:

<h:form id="myform">
    <h:inputText id="input"/>
</h:form>

the id of input will be : myform:input

Ced
  • 15,847
  • 14
  • 87
  • 146