0
<h:outputLabel value="#{bundle.CreateCustomerLabel_email}" for="email" /> 
<h:inputText id="email" value="#{customerController.selected.email}" title="#{bundle.CreateCustomerTitle_email}" /> 

<h:outputLabel value="Address:" for="addressId.address" /> 
<h:inputText size="30" id="address" value="#{customerController.selected.addressId.address}" title="Address" >
</h:inputText>

In Cutomer Entity bean I've got:

@JoinColumn(name = "address_id", referencedColumnName = "address_id")
@ManyToOne(optional = true, cascade={CascadeType.ALL})
private Address addressId;

In Address Entity bean I've got:

Basic(optional = true)
@NotNull
@Size(min = 1, max = 50)
@Column(name = "address")
private String address;

QUESTION: How can I use nested properties in JSF 2.0 forms? Should I implement nested forms or how?

Thanks in advance! Sami

Sami
  • 2,311
  • 13
  • 46
  • 80
  • 1
    Should work just fine expect that the `for` attribute of your second label is wrong. What's the concrete problem you're facing? – BalusC Feb 25 '12 at 04:00
  • Concrete problem is that it's not working at all :) The first one (simple case) is working but the nested version is not. So what should the for attribute be? – Sami Feb 25 '12 at 10:38
  • I'd start learning [basic HTML](http://htmldog.com/guides/htmlbeginner/). You seem to never really have written any HTML form. Once you get a bit grasp on HTML, then you just need to keep in mind that JSF is basically a HTML code generator. By the way, a broken `for` attribute should absolutely not have resulted in a "not working" form, so your initial problem must have been caused by something else than what Svetoslav is answering. – BalusC Feb 25 '12 at 12:33
  • I used to be in IT business about 7 years ago and I just used Struts and pure Java. But you are right, the reason was not the for attribute, but I really don't know what was it :) I am using JSF-JPA-EJB-MySQl combination and everything seems to work just fine now. – Sami Feb 25 '12 at 14:46
  • Well, Struts is also kind of a HTML generator. In JSF, [the `` component](http://docs.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/h/outputLabel.html) renders a [HTML ` – BalusC Feb 25 '12 at 21:11
  • I have never used for-attribure in label tag. I don't know what is the difference between and . I think that it just an identifier to use in css or something like that. Never used it before. – Sami Feb 26 '12 at 00:48
  • 1
    It's an accessibility aid. E.g. if you click the label, the associated input field will get focus. – BalusC Feb 26 '12 at 01:19

1 Answers1

0

Do you have get methods for addressId and address? The for attribute in the second Label must be for="address".

  • Thanks! That was it. What is the purpose of the for-attribute? I just started to code with JSF so there is plenty of strange things to me. I've got getters and now after that change you said everything is working. BTW. What is the easiest and the best way to implement roles and security to JSF-application? There might be a lot on info about that, but... – Sami Feb 25 '12 at 11:54
  • The `for` attribute identifies the component for which to generate a label element. – Svetoslav Marinov Feb 25 '12 at 21:03